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

using DomainResults.Mvc;

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

namespace WeatherForecast.Controllers;


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

  private readonly IShopCartItemService _shopCartItemService;

  /// <summary>
  /// 
  /// </summary>
  /// <param name="shopCartItemService"></param>
  public ShopCartItemController(
    IShopCartItemService shopCartItemService
  ) {
    _shopCartItemService = shopCartItemService;
  }

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

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

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

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

