using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BeWo.ServiceProxy;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using DevExpress.Xpf.Layout.Core;

namespace BeWo.ViewModel.ListViewModel
{
    public class InvoiceBaseListVM : AbstractDCListMapperVM<InvoiceBaseDC, InvoiceBaseVM>
    {
        #region Constants and Fields

        public static string PropertyName_DateTimeSpanFilter = "DateTimeSpanFilter";

        public static string PropertyName_FilterResultAmountSum = "FilterResultAmountSum";
		
        private DateTimeSpan _DateTimeSpanFilter;

        private BindingList<InvoiceBaseVM> _FilteredInvoices;

        #endregion

        #region Constructors and Destructors

        public InvoiceBaseListVM(List<InvoiceBaseDC> pDCs) : base(pDCs)
        {
			this.VMList.ListChanged += (s, e) => this.FirePropertyChanged(PropertyName_FilterResultAmountSum);
        }

        #endregion

	    
        #region Properties

        public DateTimeSpan DateTimeSpanFilter
        {
            get
            {
                return this._DateTimeSpanFilter;
            }

            set
            {
                if (this.AreDifferent(this._DateTimeSpanFilter, value))
                {
                    this._DateTimeSpanFilter = value;
                    this.FirePropertyChanged(PropertyName_DateTimeSpanFilter);

                }
            }
        }

        public decimal? FilterResultAmountSum
        {
            get
            {
                return this.VMList.Sum(e => e.TotalAmount);
            }
        }


        #endregion

		internal void UpdateList(IList<InvoiceBaseDC> dcList)
		{
			this.VMList.Clear();
			this.VMList.AddRange(dcList.Select(CreateVM));

			this.FirePropertyChanged(PropertyName_FilterResultAmountSum);
		}
	}
}