using Hotline.BatchTask;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Order.OrderDelay;
using XF.Domain.Dependency;

namespace Hotline.Application.OrderApp.OrderDelayApp;

public class OrderDelayReviewTaskExecutor : IApptaskExecutor<OrderDelayReviewWithSessionRequest>, IScopeDependency
{
    private readonly IOrderDelayApplication _orderDelayApplication;

    public OrderDelayReviewTaskExecutor(IOrderDelayApplication orderDelayApplication)
    {
        _orderDelayApplication = orderDelayApplication;
    }

    /// <summary>
    /// 执行任务
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellation"></param>
    /// <returns>是否成功执行</returns>
    public async Task<ApptaskExecuteResult> ExecuteAsync(OrderDelayReviewWithSessionRequest? request, CancellationToken cancellation)
    {
        if (request == null)
            return ApptaskExecuteResult.Fail("请求参数为空");
        try
        {
            await _orderDelayApplication.ReviewAsync(request, cancellation);
        }
        catch (Exception ex)
        {
            return ApptaskExecuteResult.Fail(ex.Message);
        }

        return ApptaskExecuteResult.Success();
    }
}