using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

using DomainResults.Mvc;

using WeatherForecast.Services;
using WeatherForecast.Models.Requests;

namespace WeatherForecast.Controllers;

/// <summary>
/// 
/// </summary>
[Authorize(Policy = "")]
[ApiController]
[Route("api/[controller]")]
public class BlogItemController : ControllerBase {

  private readonly IBlogItemService _blogItemService;

  /// <summary>
  /// 
  /// </summary>
  /// <param name="blogItemService"></param>
  public BlogItemController(
    IBlogItemService blogItemService
    ) {
    _blogItemService = blogItemService;
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="siteId"></param>
  /// <param name="requestData"></param>
  /// <returns></returns>
  [HttpPost("{siteId}")]
  public IActionResult Post([FromRoute] Guid siteId, [FromBody] BlogItemRequestModel requestData) {
    var result = _blogItemService.Post(siteId, requestData);
    return result.ToActionResult();
  }

  /// <summary>
  /// Returns full object
  /// </summary>
  /// <returns></returns>
  [HttpGet("{siteId}/{blogId}")]
  public IActionResult Get([FromRoute] Guid siteId, [FromRoute] Guid blogId) {
    var result = _blogItemService.Get(siteId, blogId);
    return result.ToActionResult();
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="siteId"></param>
  /// <param name="slug"></param>
  /// <returns></returns>
  [AllowAnonymous]
  [HttpGet("{siteId}")]
  public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) {
    var result = _blogItemService.GetSlug(siteId, slug);
    return result.ToActionResult();
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="siteId"></param>
  /// <param name="blogId"></param>
  /// <param name="requestData"></param>
  /// <returns></returns>
  [HttpPut("{siteId}/{blogId}")]
  public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid blogId, [FromBody] BlogItemRequestModel requestData) {
    var result = _blogItemService.Update(siteId, blogId, requestData);
    return result.ToActionResult();
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="siteId"></param>
  /// <param name="blogId"></param>
  /// <returns></returns>
  [HttpDelete("{siteId}/{blogId}")]
  public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid blogId) {
    var result = _blogItemService.Delete(siteId, blogId);
    return result.ToActionResult();
  }
}

