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

namespace TakeoutSaaS.Application.App.Tenants.Handlers;

/// <summary>
/// 删除公告处理器。
/// </summary>
public sealed class DeleteTenantAnnouncementCommandHandler(ITenantAnnouncementRepository announcementRepository)
    : IRequestHandler<DeleteTenantAnnouncementCommand, bool>
{
    /// <summary>
    /// 处理删除公告请求。
    /// </summary>
    /// <param name="request">删除命令。</param>
    /// <param name="cancellationToken">取消标记。</param>
    /// <returns>执行结果。</returns>
    public async Task<bool> Handle(DeleteTenantAnnouncementCommand request, CancellationToken cancellationToken)
    {
        // 1. 删除公告
        await announcementRepository.DeleteAsync(request.TenantId, request.AnnouncementId, cancellationToken);
        await announcementRepository.SaveChangesAsync(cancellationToken);

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