using MediatR;
using TakeoutSaaS.Application.App.Billings.Commands;
using TakeoutSaaS.Domain.Tenants.Services;

namespace TakeoutSaaS.Application.App.Billings.Handlers;

/// <summary>
/// 处理逾期账单命令处理器（后台任务）。
/// </summary>
public sealed class ProcessOverdueBillingsCommandHandler(
    IBillingDomainService billingDomainService)
    : IRequestHandler<ProcessOverdueBillingsCommand, int>
{
    /// <inheritdoc />
    public async Task<int> Handle(ProcessOverdueBillingsCommand request, CancellationToken cancellationToken)
    {
        // 1. 委托领域服务执行逾期账单处理（Pending && DueDate < Now -> Overdue）
        return await billingDomainService.ProcessOverdueBillingsAsync(cancellationToken);
    }
}
