using MediatR;
using TakeoutSaaS.Application.App.QuotaPackages.Commands;
using TakeoutSaaS.Domain.Tenants.Repositories;

namespace TakeoutSaaS.Application.App.QuotaPackages.Handlers;

/// <summary>
/// 删除配额包命令处理器。
/// </summary>
public sealed class DeleteQuotaPackageCommandHandler(IQuotaPackageRepository quotaPackageRepository)
    : IRequestHandler<DeleteQuotaPackageCommand, bool>
{
    /// <inheritdoc />
    public async Task<bool> Handle(DeleteQuotaPackageCommand request, CancellationToken cancellationToken)
    {
        // 1. 软删除配额包
        var deleted = await quotaPackageRepository.SoftDeleteAsync(request.QuotaPackageId, cancellationToken);

        if (!deleted)
        {
            return false;
        }

        // 2. 保存变更
        await quotaPackageRepository.SaveChangesAsync(cancellationToken);

        return true;
    }
}
