using Hotline.Application.OrderApp.OrderDelayApp;
using Hotline.Repository.SqlSugar.Extensions;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Order.OrderDelay;
using MapsterMapper;
using Microsoft.AspNetCore.Mvc;

namespace Hotline.Api.Controllers.OrderApi;

public class OrderDelayController : BaseController
{
    private readonly IOrderDelayApplication _orderDelayApplication;
    private readonly IMapper _mapper;

    public OrderDelayController(
        IOrderDelayApplication orderDelayApplication,
        IMapper mapper)
    {
        _orderDelayApplication = orderDelayApplication;
        _mapper = mapper;
    }

    /// <summary>
    /// 查询延期待审批
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("waited")]
    public async Task<IReadOnlyList<OrderDelayStepIdDto>> QueryWaited([FromQuery] DelayListDto dto)
    {
        var delays = await _orderDelayApplication.QueryWaited(dto)
            .ToPageListWithoutTotalAsync(dto, HttpContext.RequestAborted);
        var list = _mapper.Map<IReadOnlyList<OrderDelayStepIdDto>>(delays);
        return list;
    }

    /// <summary>
    /// 延期待审批总量
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("waited/count")]
    public Task<int> WaitedCount([FromQuery] DelayListDto dto) =>
        _orderDelayApplication.QueryWaited(dto)
            .CountAsync(HttpContext.RequestAborted);

    /// <summary>
    /// 延期审核
    /// </summary>
    [HttpPost("review")]
    public Task Review([FromBody]OrderDelayReviewRequest request) =>
        _orderDelayApplication.ReviewAsync(request, HttpContext.RequestAborted);

    /// <summary>
    /// 延期批量审核
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost("batch-review")]
    public Task BatchReview([FromBody]BatchOrderDelayReviewRequest request) =>
        _orderDelayApplication.BatchReviewAsync(request, HttpContext.RequestAborted);
}