using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Tiku.Api.Contracts;
using Tiku.Api.Security;
using Tiku.Application.Commerce;
using Tiku.Application.Jobs;
using Tiku.Application.Points;
using Tiku.Application.Security;
using Tiku.Domain.Commerce;

namespace Tiku.Api.Controllers;

[ApiController]
[Tags("租户端-交易运营")]
[Authorize(Policy = BackendPermissions.TenantCommerceOperate)]
[RequireSaasFeature(SaasFeatureCatalog.StudentStore)]
[Produces("application/json")]
[Route("api/tenant/commerce")]
public sealed class CommerceOrderAdministrationController(
    ICommerceOrderAdministrationService service,
    CommerceAdminActorResolver actorResolver) : ControllerBase
{
    [HttpGet("orders")]
    [EndpointSummary("查询租户订单")]
    [ProducesResponseType<AdminOrderList>(StatusCodes.Status200OK)]
    public async Task<ActionResult<AdminOrderList>> Orders(
        [FromQuery] TenantCommerceQueryDto query,
        CancellationToken cancellationToken)
    {
        return Ok(await service.GetOrdersAsync(
            actorResolver.Resolve(),
            actorResolver.ToQuery(query),
            cancellationToken));
    }

    [HttpGet("payments")]
    [EndpointSummary("查询租户支付记录")]
    [ProducesResponseType<AdminPaymentList>(StatusCodes.Status200OK)]
    public async Task<ActionResult<AdminPaymentList>> Payments(
        [FromQuery] TenantCommerceQueryDto query,
        CancellationToken cancellationToken)
    {
        return Ok(await service.GetPaymentsAsync(
            actorResolver.Resolve(),
            actorResolver.ToQuery(query),
            cancellationToken));
    }
}
