using Newtonsoft.Json;
using System;

namespace BBWY.Client.Models
{
    public class RelationPurchaseOrderSku : NotifyObject
    {
        public RelationPurchaseOrderSku()
        {
            SingleSkuAmountStr = (0).ToString();
        }
        private bool isSelected;
        private string singleSkuAmountStr;
        private decimal singleSkuAmount;
        private decimal skuAmount;

        public string ProductId { get; set; }

        public string SkuId { get; set; }

        public string Logo { get; set; }

        public int Quantity { get; set; }

        public string Title { get; set; }

        public string SingleSkuAmountStr
        {
            get => singleSkuAmountStr; set
            {
                if (Set(ref singleSkuAmountStr, value))
                {
                    if (decimal.TryParse(value, out decimal d))
                        SingleSkuAmount = d;
                }
            }
        }

        public decimal SingleSkuAmount
        {
            get => singleSkuAmount;
            set
            {
                if (Set(ref singleSkuAmount, value))
                    SkuAmount = SingleSkuAmount * Quantity;

            }
        }

        public decimal SkuAmount
        {
            get => skuAmount;
            set
            {
                if (Set(ref skuAmount, value))
                    OnSkuAmountChanged?.Invoke();
            }
        }

        /// <summary>
        /// 代发信息Id
        /// </summary>
        public long? OrderDropShippingId { get; set; }

        [JsonIgnore]
        public Action OnSkuAmountChanged { get; set; }

        public bool IsSelected { get => isSelected; set { Set(ref isSelected, value); } }
    }
}