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

namespace Baya.Application.Features.Nurses.Queries.GetNursePublicProfile;

internal sealed class GetNursePublicProfileQueryHandler(IUnitOfWork unitOfWork)
    : IRequestHandler<GetNursePublicProfileQuery, OperationResult<NursePublicProfileDto>>
{
    public async ValueTask<OperationResult<NursePublicProfileDto>> Handle(GetNursePublicProfileQuery request, CancellationToken cancellationToken)
    {
        var dto = await unitOfWork.NurseProfileRepository.GetPublicProfileAsync(request.NurseId, cancellationToken);
        return dto is null
            ? OperationResult<NursePublicProfileDto>.NotFoundResult("Nurse not found.")
            : OperationResult<NursePublicProfileDto>.SuccessResult(dto);
    }
}
