#nullable enable
using Baya.Application.Contracts.Persistence;
using Baya.Application.Models.Common;
using Baya.Application.Models.PartnerCenters;
using Mediator;

namespace Baya.Application.Features.PartnerCenters.Queries.GetPartnerCenterById;

internal sealed class GetPartnerCenterByIdQueryHandler(IUnitOfWork unitOfWork)
    : IRequestHandler<GetPartnerCenterByIdQuery, OperationResult<PartnerCenterDetailDto>>
{
    public async ValueTask<OperationResult<PartnerCenterDetailDto>> Handle(GetPartnerCenterByIdQuery request, CancellationToken cancellationToken)
    {
        var detail = await unitOfWork.PartnerCenterRepository.GetDetailAsync(request.Id, cancellationToken);
        return detail is null
            ? OperationResult<PartnerCenterDetailDto>.NotFoundResult("Partner center not found.")
            : OperationResult<PartnerCenterDetailDto>.SuccessResult(detail);
    }
}
