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

namespace Baya.Application.Features.SupportAlerts.Commands.ResolveSupportAlert;

internal sealed class ResolveSupportAlertCommandHandler(ISupportAlertService supportAlerts)
    : IRequestHandler<ResolveSupportAlertCommand, OperationResult<bool>>
{
    public async ValueTask<OperationResult<bool>> Handle(ResolveSupportAlertCommand request, CancellationToken cancellationToken)
    {
        var resolved = await supportAlerts.ResolveAsync(request.AlertId, request.Note, cancellationToken);

        return resolved
            ? OperationResult<bool>.SuccessResult(true)
            : OperationResult<bool>.NotFoundResult($"Support alert {request.AlertId} was not found or is already resolved.");
    }
}
