using MediatR;
using Microsoft.Extensions.Logging;
using TakeoutSaaS.Application.App.Stores.Commands;
using TakeoutSaaS.Domain.Stores.Repositories;
using TakeoutSaaS.Shared.Abstractions.Tenancy;

namespace TakeoutSaaS.Application.App.Stores.Handlers;

/// <summary>
/// 删除自提档期处理器。
/// </summary>
public sealed class DeleteStorePickupSlotCommandHandler(
    IStoreRepository storeRepository,
    ITenantProvider tenantProvider,
    ILogger<DeleteStorePickupSlotCommandHandler> logger)
    : IRequestHandler<DeleteStorePickupSlotCommand, bool>
{
    /// <inheritdoc />
    public async Task<bool> Handle(DeleteStorePickupSlotCommand request, CancellationToken cancellationToken)
    {
        // 1. 删除档期
        var tenantId = tenantProvider.GetCurrentTenantId();
        await storeRepository.DeletePickupSlotAsync(request.SlotId, tenantId, cancellationToken);
        await storeRepository.SaveChangesAsync(cancellationToken);
        logger.LogInformation("删除自提档期 {SlotId}", request.SlotId);
        return true;
    }
}
