using System;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using MyHN.Application;
using MyHN.Domain;

namespace Website.Controllers
{
  public class CommentsController : BaseController
  {
    private readonly IMediator _bus;

    public CommentsController(IMediator bus)
    {
      _bus = bus;
    }

    [HttpPost("{controller}/{id:guid}/vote")]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Vote(Guid id, VoteType direction, string redirectTo)
    {
      await _bus.Send(new VoteForCommentCommand()
      {
        CommentId = id,
        Direction = direction,
      });

      Success("Votre vote a bien été pris en compte");

      return Redirect(redirectTo);
    }
  }
}