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 ListStoreBusinessHoursQueryHandler(
    IStoreRepository storeRepository)
    : IRequestHandler<ListStoreBusinessHoursQuery, IReadOnlyList<StoreBusinessHourDto>>
{
    /// <inheritdoc />
    public async Task<IReadOnlyList<StoreBusinessHourDto>> Handle(ListStoreBusinessHoursQuery request, CancellationToken cancellationToken)
    {
        // 1. 查询时段列表
        var hours = await storeRepository.GetBusinessHoursAsync(request.StoreId, null, cancellationToken);

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