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

namespace Baya.Application.Features.Verification.Queries.GetVerificationDetail;

internal sealed class AdminGetVerificationDetailQueryHandler(IUnitOfWork unitOfWork, IObjectStorage objectStorage)
    : IRequestHandler<AdminGetVerificationDetailQuery, OperationResult<AdminVerificationDetailDto>>
{
    public async ValueTask<OperationResult<AdminVerificationDetailDto>> Handle(
        AdminGetVerificationDetailQuery request, CancellationToken cancellationToken)
    {
        var detail = await unitOfWork.VerificationRepository.GetDetailAsync(
            request.NurseVerificationId, key => objectStorage.GetUrl(key), cancellationToken);

        return detail is null
            ? OperationResult<AdminVerificationDetailDto>.NotFoundResult("Verification not found.")
            : OperationResult<AdminVerificationDetailDto>.SuccessResult(detail);
    }
}
