using Caliburn.Micro;
using System.Collections.ObjectModel;

namespace Gremlin.MVVM.ViewModels
{
	public class LineItemViewModel : PropertyChangedBase
	{
		private ushort position;
		private ushort amount;
		private string productNumber;
		private string optionNumber;
		private string sapShortDescription;
		private CustomDescriptionViewModel customDescriptionVM;
		private string productLine;
		private decimal totalDiscount;
		private decimal calcNetPrice;
		private decimal calcTotalNet;
		private decimal listPrice;

		public ushort Position { get => position; set { position = value; NotifyOfPropertyChange(() => Position); } }
		public ushort Amount { get => amount; set { amount = value; NotifyOfPropertyChange(() => Amount); } }
		public string ProductNumber { get => productNumber; set { productNumber = value; NotifyOfPropertyChange(() => ProductNumber); } }
		public string OptionNumber { get => optionNumber; set { optionNumber = value; NotifyOfPropertyChange(() => OptionNumber); } }
		public string SapShortDescription { get => sapShortDescription; set { sapShortDescription = value; NotifyOfPropertyChange(() => SapShortDescription); } }
		public CustomDescriptionViewModel CustomDescriptionVM { get => customDescriptionVM; set { customDescriptionVM = value; NotifyOfPropertyChange(() => CustomDescriptionVM); } }
		public string ProductLine { get => productLine; set { productLine = value; NotifyOfPropertyChange(() => ProductLine); } }
		public decimal TotalDiscount { get => totalDiscount; set { totalDiscount = value; NotifyOfPropertyChange(() => TotalDiscount); } }
		public decimal CalcNetPrice { get => calcNetPrice; set { calcNetPrice = value; NotifyOfPropertyChange(() => CalcNetPrice); } }
		public decimal CalcTotalNet { get => calcTotalNet; set { calcTotalNet = value; NotifyOfPropertyChange(() => CalcTotalNet); } }
		public decimal ListPrice { get => listPrice; set { listPrice = value; NotifyOfPropertyChange(() => ListPrice); } }


		internal static decimal GetTotalNet(ObservableCollection<LineItemViewModel> lineItems)
		{
			decimal totalNet = 0;
			foreach (LineItemViewModel lineItem in lineItems)
			{
				totalNet += lineItem.CalcNetPrice;
			}
			return totalNet;
		}

		internal static decimal GetTotalDiscount(ObservableCollection<LineItemViewModel> lineItems)
		{
			decimal totalDiscount = 0;
			foreach (LineItemViewModel lineItem in lineItems)
			{
				totalDiscount += lineItem.TotalDiscount;
			}
			return totalDiscount;
		}

		internal static decimal GetTotalListprice(ObservableCollection<LineItemViewModel> lineItems)
		{
			decimal totalListprice = 0;
			foreach (LineItemViewModel lineItem in lineItems)
			{
				totalListprice += lineItem.ListPrice;
			}
			return totalListprice;
		}
	}
}
