using System;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.App.Products.Dto;
using TakeoutSaaS.Application.App.Products.Queries;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Web.Api;

namespace TakeoutSaaS.MiniApi.Controllers;

/// <summary>
/// 小程序端菜单查询。
/// </summary>
[ApiVersion("1.0")]
[Authorize]
[Route("api/mini/v{version:apiVersion}/stores/{storeId:long}/menu")]
public sealed class MenusController(IMediator mediator) : BaseApiController
{
    /// <summary>
    /// 获取门店菜单（含分类与商品详情）。
    /// </summary>
    [HttpGet]
    [ProducesResponseType(typeof(ApiResponse<StoreMenuDto>), StatusCodes.Status200OK)]
    public async Task<ApiResponse<StoreMenuDto>> GetMenu(long storeId, [FromQuery] DateTime? updatedAfter, CancellationToken cancellationToken)
    {
        // 1. 组装查询
        var query = new GetStoreMenuQuery
        {
            StoreId = storeId,
            UpdatedAfter = updatedAfter
        };
        // 2. 拉取菜单
        var result = await mediator.Send(query, cancellationToken);
        return ApiResponse<StoreMenuDto>.Ok(result);
    }
}
