using System;
using Application;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
  [Route("api/[controller]")]
  [ApiController]
  public class CommentsController : ControllerBase
  {
    private readonly CommentService _commentService;

    public CommentsController(CommentService commentService)
    {
      _commentService = commentService;
    }

    /// <summary>
    /// Affiche un commentaire.
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("{id:guid}")]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    [ProducesResponseType(StatusCodes.Status200OK)]
    public CommentDTO Show(Guid id)
    {
      return _commentService.GetCommentById(id);
    }

    /// <summary>
    /// Publie un nouveau commentaire sur la plateforme.
    /// </summary>
    /// <param name="cmd"></param>
    /// <returns></returns>
    [HttpPost]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    [ProducesResponseType(StatusCodes.Status201Created)]
    public IActionResult Create(PublishCommentCommand cmd)
    {
      var commentId = _commentService.PublishComment(cmd);

      return CreatedAtAction(nameof(Show), new { id = commentId }, null);
    }
  }
}