using System;

using BeWo.Validation;

using BS.Shared.DataContracts;

namespace BeWo.ViewModel
{
    public class PlacementVM : AbstractDCMapperVM<PlacementDC>
    {
        public static string PropertyName_Objective = "Objective";

        public static string PropertyName_PlacementDate = "PlacementDate";

        private ValueListEntryDC _Objective;

        private DateTime? _PlacementDate;

        public PlacementVM(PlacementDC pDC) : base(pDC, pDC.PlacementOid == null)
        {
        }

        public ValueListEntryDC Objective
        {
            get { return this._Objective; }

            set
            {
                if (this.AreDifferent(this._Objective, value))
                {
                    this._Objective = value;

                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Objective, value), PropertyName_Objective);

                    this.FirePropertyChanged(PropertyName_Objective);
                }
            }
        }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public DateTime? PlacementDate
        {
            get { return this._PlacementDate; }

            set
            {
                if (this.AreDifferent(this._PlacementDate, value))
                {
                    this._PlacementDate = value;
                    this.StoreDirtyInformation(this.AreDifferent(this.DataContract.PlacementDate, value), PropertyName_PlacementDate);
                    this.FirePropertyChanged(PropertyName_PlacementDate);
                }
            }
        }

        protected override void InitByDataContract(PlacementDC pDataContract)
        {
            this._PlacementDate = pDataContract.PlacementDate;
            this._Objective = pDataContract.Objective;
        }

        protected override PlacementDC MapToDataContract(PlacementDC pDataContract, bool doCommit)
        {
            pDataContract.PlacementDate = this._PlacementDate;
            pDataContract.Objective = this._Objective;

            return pDataContract;
        }
    }
}