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

namespace TakeoutSaaS.Application.App.Tenants.Handlers;

/// <summary>
/// 删除租户套餐处理器。
/// </summary>
public sealed class DeleteTenantPackageCommandHandler(ITenantPackageRepository packageRepository)
    : IRequestHandler<DeleteTenantPackageCommand, bool>
{
    /// <inheritdoc />
    public async Task<bool> Handle(DeleteTenantPackageCommand request, CancellationToken cancellationToken)
    {
        // 1. 删除套餐
        await packageRepository.DeleteAsync(request.TenantPackageId, cancellationToken);
        await packageRepository.SaveChangesAsync(cancellationToken);

        // 2. 返回执行结果
        return true;
    }
}
