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

namespace Baya.Application.Features.Bookings.Queries.ListCancellationPolicies;

// Admin-only access is enforced by the controller policy.
internal sealed class ListCancellationPoliciesQueryHandler(IUnitOfWork unitOfWork)
    : IRequestHandler<ListCancellationPoliciesQuery, OperationResult<IReadOnlyList<CancellationPolicyDto>>>
{
    public async ValueTask<OperationResult<IReadOnlyList<CancellationPolicyDto>>> Handle(ListCancellationPoliciesQuery request, CancellationToken cancellationToken)
    {
        var policies = await unitOfWork.CancellationPolicyRepository.ListAsync(cancellationToken);
        return OperationResult<IReadOnlyList<CancellationPolicyDto>>.SuccessResult(policies);
    }
}
