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 ShopItemController : ControllerBase {

  private readonly IShopItemService _shopItemService;

  /// <summary>
  /// 
  /// </summary>
  /// <param name="shopItemService"></param>
  public ShopItemController(
    IShopItemService shopItemService
  ) {
    _shopItemService = shopItemService;
  }

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

  /// <summary>
  /// Returns full object
  /// </summary>
  /// <param name="siteId"></param>
  /// <param name="sku"></param>
  /// <returns></returns>
  [HttpGet("{siteId}/{sku}")]
  public IActionResult Get([FromRoute] Guid siteId, [FromRoute] string sku) {
    var result = _shopItemService.Get(siteId, sku);
    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 = _shopItemService.GetSlug(siteId, slug);
    return result.ToActionResult();
  }

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

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

