using FluentResults;
using NexusReader.Application.Abstractions.Messaging;
using NexusReader.Application.Abstractions.Services;

namespace NexusReader.Application.Commands.Quiz;

internal sealed class SubmitAnswerCommandHandler : ICommandHandler<SubmitAnswerCommand>
{
    private readonly IPlatformService _platformService;

    public SubmitAnswerCommandHandler(IPlatformService platformService)
    {
        _platformService = platformService;
    }

    public async Task<Result> Handle(SubmitAnswerCommand request, CancellationToken cancellationToken)
    {
        if (request.SelectedIndex == request.CorrectIndex)
        {
            await _platformService.VibrateAsync(50);
            return Result.Ok();
        }
        
        return Result.Fail("Incorrect answer.");
    }
}
