using System.Linq;
using MediatR;
using TakeoutSaaS.Application.App.Stores;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Application.App.Stores.Queries;
using TakeoutSaaS.Domain.Stores.Repositories;

namespace TakeoutSaaS.Application.App.Stores.Handlers;

/// <summary>
/// 门店节假日列表查询处理器。
/// </summary>
public sealed class ListStoreHolidaysQueryHandler(
    IStoreRepository storeRepository)
    : IRequestHandler<ListStoreHolidaysQuery, IReadOnlyList<StoreHolidayDto>>
{
    /// <inheritdoc />
    public async Task<IReadOnlyList<StoreHolidayDto>> Handle(ListStoreHolidaysQuery request, CancellationToken cancellationToken)
    {
        // 1. 查询节假日
        var holidays = await storeRepository.GetHolidaysAsync(request.StoreId, null, cancellationToken);

        // 2. (空行后) 映射 DTO
        return holidays.Select(StoreMapping.ToDto).ToList();
    }
}
