using System;
using System.Collections.Generic;

using BeWo.ViewModel.ListViewModel;

using BS.Shared;
using BS.Shared.DataContracts;

namespace BeWo.ViewModel
{
    public class SupportConceptApprovalPeriodVM : AbstractDCMapperVM<SupportConceptApprovalPeriodDC>
    {
        #region Constants and Fields

        public static string PropertyName_ApprovedBEInterval                      = "ApprovedBEInterval";
        public static string PropertyName_ApprovedBEPerInterval                   = "ApprovedBEPerInterval";
		public static string PropertyName_ContactCountInterval                    = "ContactCountInterval";
		public static string PropertyName_ContactCountPerInterval                 = "ContactCountPerInterval";
        public static string PropertyName_ApprovedBETotal                         = "ApprovedBETotal";
        public static string PropertyName_ApprovedFixedAmount                     = "ApprovedFixedAmount";
        public static string PropertyName_ApprovedFixedAmountInterval             = "ApprovedFixedAmountInterval";
        public static string PropertyName_EndDate                                 = "EndDate";
        public static string PropertyName_IsApprovedBEShifting                    = "IsApprovedBEShifting";
        public static string PropertyName_IsApprovedFixedAmountShifting           = "IsApprovedFixedAmountShifting";
        public static string PropertyName_MonthlyPayment                          = "MonthlyPayment";
        public static string PropertyName_ServiceUnitName                         = "ServiceUnitName";
        public static string PropertyName_StartDate                               = "StartDate";
        public static string PropertyName_Percentage                              = "Percentage";
        public static string PropertyName_ServiceCategory                         = "ServiceCategory";
        public static string PropertyName_SupportConceptApprovalEmployeeRelations = "SupportConceptApprovalEmployeeRelations";

        private SupportConceptApprovalInterval?               _ApprovedBEInterval;
        private decimal?                                      _ApprovedBEPerInterval;
        private SupportConceptApprovalInterval?               _ContactCountInterval;
        private decimal?                                      _ContactCountPerInterval;
        private decimal?                                      _ApprovedBETotal;
        private decimal?                                      _ApprovedFixedAmount;
        private SupportConceptApprovalInterval?               _ApprovedFixedAmountInterval;
        private DateTime?                                     _EndDate;
        private bool                                          _IsApprovedBEShifting;
        private bool                                          _IsApprovedFixedAmountShifting;
        private decimal?                                      _MonthlyPayment;
        private string                                        _ServiceUnitName;
        private DateTime?                                     _StartDate;
        private decimal?                                      _Percentage;
        private ServiceCategoryDC                             _ServiceCategory;
        private SupportConceptApprovalPeriodEmployeeRelListVM _SupportConceptApprovalEmployeeRelations;

        #endregion

        #region Constructors and Destructors

        public SupportConceptApprovalPeriodVM(SupportConceptApprovalPeriodDC pdc) : base(pdc, !pdc.SupportConceptApprovalPeriodOid.HasValue) {}

        #endregion

        #region Properties

        public SupportConceptApprovalInterval? ApprovedBEInterval
        {
            get
            {
                return this._ApprovedBEInterval;
            }

            set
            {
                if (this.AreDifferent(this._ApprovedBEInterval, value))
                {
                    this._ApprovedBEInterval = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovedBEInterval, value), PropertyName_ApprovedBEInterval);
                    this.FirePropertyChanged(PropertyName_ApprovedBEInterval);
                }
            }
        }

        public decimal? ApprovedBEPerInterval
        {
            get
            {
                return this._ApprovedBEPerInterval;
            }

            set
            {
                if (this.AreDifferent(this._ApprovedBEPerInterval, value))
                {
                    this._ApprovedBEPerInterval = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovedBEPerInterval, value), PropertyName_ApprovedBEPerInterval);
                    this.FirePropertyChanged(PropertyName_ApprovedBEPerInterval);
                }
            }
        }

		public SupportConceptApprovalInterval? ContactCountInterval
		{
			get
			{
				return this._ContactCountInterval;
			}

			set
			{
				if (this.AreDifferent(this._ContactCountInterval, value))
				{
					this._ContactCountInterval = value;
					this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ContactCountInterval, value), PropertyName_ContactCountInterval);
					this.FirePropertyChanged(PropertyName_ContactCountInterval);
				}
			}
		}

		public decimal? ContactCountPerInterval
		{
			get
			{
				return this._ContactCountPerInterval;
			}

			set
			{
				if (this.AreDifferent(this._ContactCountPerInterval, value))
				{
					this._ContactCountPerInterval = value;
					this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ContactCountPerInterval, value), PropertyName_ContactCountPerInterval);
					this.FirePropertyChanged(PropertyName_ContactCountPerInterval);
				}
			}
		}

        public decimal? ApprovedBETotal
        {
            get
            {
                return this._ApprovedBETotal;
            }

            set
            {
                if (this.AreDifferent(this._ApprovedBETotal, value))
                {
                    this._ApprovedBETotal = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovedBETotal, value), PropertyName_ApprovedBETotal);
                    this.FirePropertyChanged(PropertyName_ApprovedBETotal);
                }
            }
        }

        public decimal? ApprovedFixedAmount
        {
            get
            {
                return this._ApprovedFixedAmount;
            }

            set
            {
                if (this.AreDifferent(this._ApprovedFixedAmount, value))
                {
                    this._ApprovedFixedAmount = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovedFixedAmount, value), PropertyName_ApprovedFixedAmount);
                    this.FirePropertyChanged(PropertyName_ApprovedFixedAmount);
                }
            }
        }

        public SupportConceptApprovalInterval? ApprovedFixedAmountInterval
        {
            get
            {
                return this._ApprovedFixedAmountInterval;
            }

            set
            {
                if (this.AreDifferent(this._ApprovedFixedAmountInterval, value))
                {
                    this._ApprovedFixedAmountInterval = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ApprovedFixedAmountInterval, value), PropertyName_ApprovedFixedAmountInterval);
                    this.FirePropertyChanged(PropertyName_ApprovedFixedAmountInterval);
                }
            }
        }

        public DateTime? EndDate
        {
            get
            {
                return this._EndDate;
            }

            set
            {
                if (this.AreDifferent(this._EndDate, value))
                {
                    this._EndDate = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.EndDate, value), PropertyName_EndDate);
                    this.FirePropertyChanged(PropertyName_EndDate);
                }
            }
        }

        public bool IsApprovedBEShifting
        {
            get
            {
                return this._IsApprovedBEShifting;
            }

            set
            {
                if (this.AreDifferent(this._IsApprovedBEShifting, value))
                {
                    this._IsApprovedBEShifting = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.IsApprovedBEShifting, value), PropertyName_IsApprovedBEShifting);
                    this.FirePropertyChanged(PropertyName_IsApprovedBEShifting);
                }
            }
        }

        public decimal? Percentage
        {
            get { return this._Percentage; }

            set
            {
                if (this.AreDifferent(this._Percentage, value))
                {
                    this._Percentage = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Percentage, value), PropertyName_Percentage);
                    this.FirePropertyChanged(PropertyName_Percentage);
                }
            }
        }

        public ServiceCategoryDC ServiceCategory
        {
            get { return this._ServiceCategory; }

            set
            {
                if (this.AreDifferent(this._ServiceCategory, value))
                {
                    this._ServiceCategory = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ServiceCategory, value), PropertyName_ServiceCategory);
                    this.FirePropertyChanged(PropertyName_ServiceCategory);
                }
            }
        }

        public bool IsApprovedFixedAmountShifting
        {
            get
            {
                return this._IsApprovedFixedAmountShifting;
            }

            set
            {
                if (this.AreDifferent(this._IsApprovedFixedAmountShifting, value))
                {
                    this._IsApprovedFixedAmountShifting = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.IsApprovedFixedAmountShifting, value), PropertyName_IsApprovedFixedAmountShifting);
                    this.FirePropertyChanged(PropertyName_IsApprovedFixedAmountShifting);
                }
            }
        }

        public decimal? MonthlyPayment
        {
            get
            {
                return this._MonthlyPayment;
            }

            set
            {
                if (this.AreDifferent(this._MonthlyPayment, value))
                {
                    this._MonthlyPayment = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.MonthlyPayment, value), PropertyName_MonthlyPayment);
                    this.FirePropertyChanged(PropertyName_MonthlyPayment);
                }
            }
        }

        public string ServiceUnitName
        {
            get
            {
                return this._ServiceUnitName;
            }

            set
            {
                if (this.AreDifferent(this._ServiceUnitName, value))
                {
                    this._ServiceUnitName = value;
                    this.FirePropertyChanged(PropertyName_ServiceUnitName);
                }
            }
        }

        public string TranslatedServiceUnitName
        {
            get
            {
                if (this._ServiceUnitName == "FLS")
                    return "Std.";
                return this._ServiceUnitName;
            }

        }

        public DateTime? StartDate
        {
            get
            {
                return this._StartDate;
            }

            set
            {
                if (this.AreDifferent(this._StartDate, value))
                {
                    this._StartDate = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.StartDate, value), PropertyName_StartDate);
                    this.FirePropertyChanged(PropertyName_StartDate);
                }
            }
        }

		public static bool ShowContactCountFields
		{
			get
			{
				return BeWoApp.Mandator.BeWoClientType == 11;
			}
		}

        public SupportConceptApprovalPeriodEmployeeRelListVM SupportConceptApprovalEmployeeRelations
        {
            get { return _SupportConceptApprovalEmployeeRelations; }

            set
            {
                _SupportConceptApprovalEmployeeRelations = value;
                FirePropertyChanged(PropertyName_SupportConceptApprovalEmployeeRelations);
            }
        }

        public override bool IsDirty
        {
            get { return base.IsDirty || SupportConceptApprovalEmployeeRelations.IsDirty; }
        }

        #endregion

        #region Methods

        protected override void InitByDataContract(SupportConceptApprovalPeriodDC pDataContract)
        {
            _ApprovedBEInterval            = pDataContract.ApprovedBEInterval;
            _ApprovedBETotal               = pDataContract.ApprovedBETotal;
            _ApprovedBEPerInterval         = pDataContract.ApprovedBEPerInterval;
            _ContactCountInterval          = pDataContract.ContactCountInterval;
            _ContactCountPerInterval       = pDataContract.ContactCountPerInterval;
            _ApprovedFixedAmount           = pDataContract.ApprovedFixedAmount;
            _ApprovedFixedAmountInterval   = pDataContract.ApprovedFixedAmountInterval;
            _EndDate                       = pDataContract.EndDate;
            _IsApprovedBEShifting          = pDataContract.IsApprovedBEShifting;
            _IsApprovedFixedAmountShifting = pDataContract.IsApprovedFixedAmountShifting;
            _MonthlyPayment                = pDataContract.MonthlyPayment;
            _StartDate                     = pDataContract.StartDate;
            _Percentage                    = pDataContract.Percentage;
            _ServiceCategory               = pDataContract.ServiceCategory;

            SupportConceptApprovalEmployeeRelations = VMFactory.CreateSupportConceptApprovalPeriodEmployeeRelListVM(pDataContract.SupportConceptApprovalPeriodEmployeeRelations ?? (pDataContract.SupportConceptApprovalPeriodEmployeeRelations = new List<SupportConceptApprovalPeriodEmployeeRelDC>()));
        }

        protected override SupportConceptApprovalPeriodDC MapToDataContract(SupportConceptApprovalPeriodDC pDataContract, bool doCommit)
        {
            pDataContract.ApprovedBEInterval            = _ApprovedBEInterval;
            pDataContract.ApprovedBETotal               = _ApprovedBETotal;
            pDataContract.ApprovedBEPerInterval         = _ApprovedBEPerInterval;
            pDataContract.ContactCountInterval          = _ContactCountInterval;
            pDataContract.ContactCountPerInterval       = _ContactCountPerInterval;
            pDataContract.ApprovedFixedAmount           = _ApprovedFixedAmount;
            pDataContract.ApprovedFixedAmountInterval   = _ApprovedFixedAmountInterval;
            pDataContract.EndDate                       = _EndDate;
            pDataContract.IsApprovedBEShifting          = _IsApprovedBEShifting;
            pDataContract.IsApprovedFixedAmountShifting = _IsApprovedFixedAmountShifting;
            pDataContract.MonthlyPayment                = _MonthlyPayment;
            pDataContract.StartDate                     = _StartDate;
            pDataContract.Percentage                    = _Percentage;
            pDataContract.ServiceCategory               = _ServiceCategory;

            pDataContract.SupportConceptApprovalPeriodEmployeeRelations = _SupportConceptApprovalEmployeeRelations.CopyToDCList(doCommit);

            return pDataContract;
        }

        #endregion
    }
}