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

namespace BeWo.ViewModel
{
    public class PersonOrganisationRelationVM : AbstractDCMapperVM<Organisation2PersonDC>
    {
        public static string PropertyName_Fax = "Fax";

        public static string PropertyName_Mail = "Mail";

        public static string PropertyName_Notice = "Notice";

        public static string PropertyName_Organisation = "Organisation";

		public static string PropertyName_OrganisationString = "OrganisationString";

        public static string PropertyName_Phone = "Phone";

        private string _Fax;

        private string _Mail;

        private string _Notice;

		private CompactOrganisationDC _Organisation;

        private string _Phone;

        public PersonOrganisationRelationVM(Organisation2PersonDC pDataContract) : base(pDataContract, pDataContract.Organisation2PersonOid == null)
        {
        }

        public string Fax
        {
            get { return this._Fax; }

            set
            {
                if (this.AreDifferent(this._Fax, value))
                {
                    this._Fax = value;
					this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Fax, value), PropertyName_Fax);
                    this.FirePropertyChanged(PropertyName_Fax);
                }
            }
        }

        public string Mail
        {
            get { return this._Mail; }

            set
            {
                if (this.AreDifferent(this._Mail, value))
                {
                    this._Mail = value;
					this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Mail, value), PropertyName_Mail);
                    this.FirePropertyChanged(PropertyName_Mail);
                }
            }
        }

        public string Notice
        {
            get { return this._Notice; }

            set
            {
                if (this.AreDifferent(this._Notice, value))
                {
                    this._Notice = value;
                    this.FirePropertyChanged(PropertyName_Notice);
                }
            }
        }

		public CompactOrganisationDC Organisation
        {
            get { return this._Organisation; }

            set
            {
				if (this.AreDifferent(this._Organisation, value))
                {
					this._Organisation = value;
                    this.FirePropertyChanged(PropertyName_Organisation);
					this.FirePropertyChanged(PropertyName_OrganisationString);
                }
            }
        }

		[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
		public string OrganisationString
		{
			get { return this._Organisation.ToStringNullCheck(); } // Validation Workaround
			set
			{
				if (this._Organisation != null)
					this._Organisation.Name = value;
				this.FirePropertyChanged(PropertyName_OrganisationString);
			}
		}

        public string Phone
        {
            get { return this._Phone; }

            set
            {
                if (this.AreDifferent(this._Phone, value))
                {
                    this._Phone = value;
					this.StoreDirtyInformation(this.AreDifferent(this.DataContract.Phone, value), PropertyName_Phone);
                    this.FirePropertyChanged(PropertyName_Phone);
                }
            }
        }

        protected override void InitByDataContract(Organisation2PersonDC pDataContract)
        {
            if (!this.IsNew)
            {
                this._Notice = pDataContract.Notice;
	            this._Fax = pDataContract.Fax;
				this._Phone = pDataContract.Phone;
				this._Mail = pDataContract.Mail;
                this._Organisation = pDataContract.Organisation;

            }

        }

        protected override Organisation2PersonDC MapToDataContract(Organisation2PersonDC pDataContract, bool doCommit)
        {
            pDataContract.Notice = this._Notice;
			pDataContract.Fax = this._Fax;
			pDataContract.Mail = this._Mail;
			pDataContract.Phone = this._Phone;
	        pDataContract.Organisation = this._Organisation;
            return pDataContract;
        }

		
    }
}