using MediatR;
using TakeoutSaaS.Application.App.Tenants.Dto;
using TakeoutSaaS.Application.App.Tenants.Queries;
using TakeoutSaaS.Domain.Tenants.Repositories;

namespace TakeoutSaaS.Application.App.Tenants.Handlers;

/// <summary>
/// 套餐详情查询处理器。
/// </summary>
public sealed class GetTenantPackageByIdQueryHandler(ITenantPackageRepository packageRepository)
    : IRequestHandler<GetTenantPackageByIdQuery, TenantPackageDto?>
{
    /// <inheritdoc />
    public async Task<TenantPackageDto?> Handle(GetTenantPackageByIdQuery request, CancellationToken cancellationToken)
    {
        // 1. 查询套餐
        var package = await packageRepository.FindByIdAsync(request.TenantPackageId, cancellationToken);

        // 2. 返回 DTO 或 null
        return package?.ToDto();
    }
}
