using System.Windows;
using BeWo.Validation;

using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;

namespace BeWo.ViewModel
{
    public class SupportConceptApprovalPeriodEmployeeRelVM : AbstractDCMapperVM<SupportConceptApprovalPeriodEmployeeRelDC>
    {
        public static string PropertyName_Employee             = "Employee";
        public static string PropertyName_Betreuungsschluessel = "Betreuungsschluessel";
        public static string PropertyName_EmployeeString       = "EmployeeString";

        private CompactEmployeeDC _Employee;
        private decimal _Betreuungsschluessel;

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public CompactEmployeeDC Employee
        {
            get { return _Employee; }

            set
            {
                if (AreDifferent(_Employee, value))
                {
                    _Employee = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Employee, value), PropertyName_Employee);
                    FirePropertyChanged(PropertyName_Employee);
                    FirePropertyChanged(PropertyName_EmployeeString);
                }
            }
        }

        [ValidationAttribute(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string EmployeeString
        {
            get { return _Employee.ToStringNullCheck(); } // Validation Workaround
            set { }
        }

        public decimal Betreuungsschluessel
        {
            get { return _Betreuungsschluessel; }

            set
            {
                if (AreDifferent(_Betreuungsschluessel, value))
                {
                    _Betreuungsschluessel = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Betreuungsschluessel, value), PropertyName_Betreuungsschluessel);
                    FirePropertyChanged(PropertyName_Betreuungsschluessel);
                }
            }
        }

        public SupportConceptApprovalPeriodEmployeeRelVM(SupportConceptApprovalPeriodEmployeeRelDC pDataContract) : base(pDataContract, pDataContract.SupportConceptApprovalPeriod2EmployeeOid == null) { }

        protected override void InitByDataContract(SupportConceptApprovalPeriodEmployeeRelDC pDataContract)
        {
            if (!IsNew)
            {
                _Employee             = pDataContract.Employee;
                _Betreuungsschluessel = pDataContract.Betreuungsschluessel;
            }
        }

        protected override SupportConceptApprovalPeriodEmployeeRelDC MapToDataContract(SupportConceptApprovalPeriodEmployeeRelDC pDataContract, bool doCommit)
        {
            pDataContract.Employee             = _Employee;
            pDataContract.Betreuungsschluessel = _Betreuungsschluessel;

            return pDataContract;
        }
    }
}