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

namespace TakeoutSaaS.Application.App.Stores.Handlers;

/// <summary>
/// 门店详情查询处理器。
/// </summary>
public sealed class GetStoreByIdQueryHandler(
    IStoreRepository storeRepository)
    : IRequestHandler<GetStoreByIdQuery, StoreDto?>
{
    /// <inheritdoc />
    public async Task<StoreDto?> Handle(GetStoreByIdQuery request, CancellationToken cancellationToken)
    {
        // 1. 查询门店详情（默认跨租户，支持包含软删除）
        var store = await storeRepository.FindByIdAsync(request.StoreId, null, cancellationToken, includeDeleted: request.IncludeDeleted);
        return store == null ? null : StoreMapping.ToDto(store);
    }
}
