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

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

internal sealed class AssignSupportAlertCommandHandler(ISupportAlertService supportAlerts)
    : IRequestHandler<AssignSupportAlertCommand, OperationResult<bool>>
{
    public async ValueTask<OperationResult<bool>> Handle(AssignSupportAlertCommand request, CancellationToken cancellationToken)
    {
        var assigned = await supportAlerts.AssignAsync(request.AlertId, request.OwnerUserId, cancellationToken);

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