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 ListStoreDeliveryZonesQueryHandler(
    IStoreRepository storeRepository)
    : IRequestHandler<ListStoreDeliveryZonesQuery, IReadOnlyList<StoreDeliveryZoneDto>>
{
    /// <inheritdoc />
    public async Task<IReadOnlyList<StoreDeliveryZoneDto>> Handle(ListStoreDeliveryZonesQuery request, CancellationToken cancellationToken)
    {
        // 1. 查询配送区域
        var zones = await storeRepository.GetDeliveryZonesAsync(request.StoreId, null, cancellationToken);

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