using Baya.Application.Contracts.Holidays;
using Baya.Application.Models.Common;
using Mediator;

namespace Baya.Application.Features.Holidays.Commands.DeleteHoliday;

internal sealed class DeleteHolidayCommandHandler(IHolidayCalendar holidayCalendar)
    : IRequestHandler<DeleteHolidayCommand, OperationResult<bool>>
{
    public async ValueTask<OperationResult<bool>> Handle(DeleteHolidayCommand request, CancellationToken cancellationToken)
    {
        var deleted = await holidayCalendar.DeleteAsync(request.HolidayDate, cancellationToken);

        return deleted
            ? OperationResult<bool>.SuccessResult(true)
            : OperationResult<bool>.NotFoundResult($"No holiday exists on {request.HolidayDate:yyyy-MM-dd}.");
    }
}
