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

using DomainResults.Mvc;

using WeatherForecast.Services;

namespace WeatherForecast.Controllers;

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

  private readonly ICategoryItemsService _categoryItemsService;

  /// <summary>
  /// 
  /// </summary>
  /// <param name="categoryItemsService"></param>
  public CategoryItemsController(
  ICategoryItemsService categoryItemsService
  ) {
    _categoryItemsService = categoryItemsService;
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="siteId"></param>
  /// <param name="locale"></param>
  /// <returns></returns>
  [HttpGet("{siteId}")]
  public IActionResult Get([FromRoute] Guid siteId, [FromQuery] string? locale) {
    var result = _categoryItemsService.Get(siteId, locale);
    return result.ToActionResult();
  }

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

