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

using DomainResults.Mvc;

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

namespace WeatherForecast.Controllers;

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

  private readonly ICategoryItemService _categoryItemService;

  /// <summary>
  /// 
  /// </summary>
  /// <param name="categoryItemService"></param>
  public CategoryItemController(
    ICategoryItemService categoryItemService) {
    _categoryItemService = categoryItemService;
  }

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

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

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

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

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

