using System;

using BS.Shared.DataContracts;

namespace BeWo.ViewModel
{
    public class WohnheimbuchungCostbearerSupportConceptRelationVM : AbstractDCMapperVM<Wohnheimbuchung2Costbearer2SupportConceptRelationDC>
    {
        public static String PropertyName_StartDate                 = "StartDate";
        public static String PropertyName_EndDate                   = "EndDate";
        public static String PropertyName_Notice                    = "Notice";
        public static String PropertyName_Costbearer2SupportConcept = "Costbearer2SupportConcept";

        private DateTime?               _EndDate;
        private String                  _Notice;
        private DateTime?               _StartDate;
        private SupportConceptCostBearerRelDC _Costbearer2SupportConcept;

        public WohnheimbuchungCostbearerSupportConceptRelationVM(Wohnheimbuchung2Costbearer2SupportConceptRelationDC pDC) : base(pDC, pDC.Wohnheimbuchung2Costbearer2SupportConceptOid == null)
        {
        }

        public String Notice
        {
            get { return _Notice; }

            set
            {
                if (AreDifferent(_Notice, value))
                {
                    _Notice = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Notice, value), PropertyName_Notice);
                    FirePropertyChanged(PropertyName_Notice);
                }
            }
        }

        public DateTime? StartDate
        {
            get { return _StartDate; }

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

        public DateTime? EndDate
        {
            get { return _EndDate; }

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

        public SupportConceptCostBearerRelDC Costbearer2SupportConcept
        {
            get { return _Costbearer2SupportConcept; }

            set
            {
                if (AreDifferent(_Costbearer2SupportConcept, value))
                {
                    _Costbearer2SupportConcept = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Costbearer2SupportConcept, value), PropertyName_Costbearer2SupportConcept);
                    FirePropertyChanged(PropertyName_Costbearer2SupportConcept);
                }
            }
        }

        public String DetailString
        {
            get { return String.Format("{0}\n{1} {2}", Costbearer2SupportConcept.SupportConcept.Customer,  Costbearer2SupportConcept.DateRangeString, Costbearer2SupportConcept.CostBearer); }
        }

        protected override void InitByDataContract(Wohnheimbuchung2Costbearer2SupportConceptRelationDC pDataContract)
        {
            if (!IsNew)
            {
                _StartDate                 = pDataContract.StartDate;
                _EndDate                   = pDataContract.EndDate;
                _Notice                    = pDataContract.Notice;
                _Costbearer2SupportConcept = pDataContract.Costbearer2SupportConcept;
            }
        }

        protected override Wohnheimbuchung2Costbearer2SupportConceptRelationDC MapToDataContract(Wohnheimbuchung2Costbearer2SupportConceptRelationDC pDataContract, bool doCommit)
        {
            pDataContract.StartDate                 = _StartDate;
            pDataContract.EndDate                   = _EndDate;
            pDataContract.Notice                    = _Notice;
            pDataContract.Costbearer2SupportConcept = _Costbearer2SupportConcept;

            return pDataContract;
        }
    }
}