using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Application.App.Stores.Queries;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Web.Api;

namespace TakeoutSaaS.AdminApi.Controllers;

/// <summary>
/// 门店资质预警（平台）。
/// </summary>
[ApiVersion("1.0")]
[Authorize]
[Route("api/admin/v{version:apiVersion}/platform/store-qualifications")]
public sealed class StoreQualificationsController(
    IMediator mediator)
    : BaseApiController
{
    /// <summary>
    /// 查询资质即将过期/已过期列表。
    /// </summary>
    /// <param name="query">查询参数。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>资质预警分页结果。</returns>
    [HttpGet("expiring")]
    [PermissionAuthorize("store-qualification:read")]
    [ProducesResponseType(typeof(ApiResponse<StoreQualificationAlertResultDto>), StatusCodes.Status200OK)]
    public async Task<ApiResponse<StoreQualificationAlertResultDto>> ListExpiring(
        [FromQuery] ListExpiringStoreQualificationsQuery query,
        CancellationToken cancellationToken)
    {
        // 1. 查询资质预警
        var result = await mediator.Send(query, cancellationToken);

        // 2. (空行后) 返回结果
        return ApiResponse<StoreQualificationAlertResultDto>.Ok(result);
    }
}
