using Core.Abstractions.Models;
using Core.DomainObjects.Documents;
using Core.Enumerations;

namespace WeatherForecast.Models.Responses {

  /// <summary>
  /// 
  /// </summary>
  public class ShopCartItemResponseModel : ResponseModelBase {

    /// <summary>
    /// 
    /// </summary>
    public string Slug { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string Sku { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public MediaAttachmentResponseModel? Image { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string BrandName { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string ShortText { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public DateTime Created { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public decimal Price { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public decimal? NewPrice { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public uint? Quantity { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="shopItem"></param>
    /// <param name="shopCartItem"></param>
    /// <param name="locale"></param>
    public ShopCartItemResponseModel(ShopItem shopItem, ShopCartItem shopCartItem, Locales locale) {

      Sku = shopItem.Sku;
      BrandName = shopItem.BrandName;
      Created = shopItem.Created;
      Price = shopItem.Price;
      NewPrice = shopItem.NewPrice;
      Quantity = shopCartItem.Quantity;

      var l10n = shopItem.L10n.SingleOrDefault(x => x.Locale == locale);

      if (l10n != null) {
        Slug = l10n.Slug;
        Title = l10n.Title;
        ShortText = l10n.ShortText;
      }

      if(shopItem.MediaAttachments != null)
        Image = new MediaAttachmentResponseModel(shopItem.MediaAttachments.First(), locale);

    }
  }
}
