using System;
using BeWo.Validation;

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

namespace BeWo.ViewModel
{
    public class OrganisationPersonRelationVM : AbstractDCMapperVM<OrganisationPersonRelationDC>
    {
        public static string PropertyName_Organisation = "Organisation";

        public static string PropertyName_OrganisationString = "OrganisationString";

        public static string PropertyName_Person = "Person";

        public static string PropertyName_PersonString = "PersonString";

		public static string PropertyName_Notice = "Notice";

        private CompactOrganisationDC _Organisation;

        private CompactPersonDC _Person;

	    private string _Notice;

        public OrganisationPersonRelationVM(OrganisationPersonRelationDC pDC)
            : base(pDC, pDC.Organisation2PersonOid == null)
        {
        }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public CompactOrganisationDC Organisation
        {
            get { return _Organisation; }

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

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string OrganisationString
        {
            get { return _Organisation.ToStringNullCheck(); }
            set { }
        }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public CompactPersonDC Person
        {
            get { return _Person; }

            set
            {
                if(AreDifferent(_Person, value))
                {
                    _Person = value;
                    StoreDirtyInformation(AreDifferent(DataContract.Person, value), PropertyName_Person);
                    FirePropertyChanged(PropertyName_Person);
                    FirePropertyChanged(PropertyName_PersonString);
                }
            }
        }

        [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
        public string PersonString
        {
            get { return _Person.ToStringNullCheck(); }
            set { }
        }


		public String Notice
		{
			get { return _Notice; }

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

        protected override void InitByDataContract(OrganisationPersonRelationDC pDataContract)
        {
            if(!IsNew)
            {
                _Person = pDataContract.Person;
                _Organisation = pDataContract.Organisation;
	            _Notice = pDataContract.Notice;
            }
        }

        protected override OrganisationPersonRelationDC MapToDataContract(OrganisationPersonRelationDC pDataContract, bool doCommit)
        {
            pDataContract.Person = _Person;
            pDataContract.Organisation = _Organisation;
	        pDataContract.Notice = _Notice;

            return pDataContract;
        }
    }
}
