using System;
using System.Collections.Generic;

using BS.Shared;
using BS.Shared.Core;

namespace BeWo.Data.Entities
{
	public class Customer : BeWoEntityBase
	{
        public static string PropertyName_AbsenceTimes                  = "AbsenceTimes";
        public static string PropertyName_Ansprechpartner               = "Ansprechpartner";
        public static string PropertyName_AssessmentSheetCategoryList   = "AssessmentSheetCategoryList";
        public static string PropertyName_Childs                        = "Childs";
        public static string PropertyName_Customer2CostBearerList       = "Customer2CostBearerList";
        public static string PropertyName_Customer2PersonList           = "Customer2PersonList";
        public static string PropertyName_Customer2OrganisationList     = "Customer2OrganisationList";
        public static string PropertyName_DebitorNumber                 = "DebitorNumber";
        public static string PropertyName_CostCenter                    = "CostCenter";
        public static string PropertyName_Diagnosis                     = "Diagnosis";
        public static string PropertyName_Diagnosis2CustomerList        = "Diagnosis2CustomerList";
        public static string PropertyName_Employee2CustomerList         = "Employee2CustomerList";
        public static string PropertyName_FamilyData                    = "FamilyData";
        public static string PropertyName_Team2CustomerList             = "Team2CustomerList";
        public static string PropertyName_EquityContribution            = "EquityContribution";
        public static string PropertyName_ICD10Diagnosis                = "ICD10Diagnosis";
        public static string PropertyName_IsAdvisedOrAttended           = "IsAdvisedOrAttended";
        public static string PropertyName_Medication                    = "Medication";
        public static string PropertyName_Jugendamt                     = "Jugendamt";
        public static string PropertyName_Person                        = "Person";
        public static string PropertyName_PlacementList                 = "PlacementList";
        public static string PropertyName_ReferenceNumber               = "ReferenceNumber";
        public static string PropertyName_ServiceRecordList             = "ServiceRecordList";
        public static string PropertyName_SupportConcepts               = "SupportConcepts";
        public static string PropertyName_TerminationDate               = "TerminationDate";
        public static string PropertyName_TerminationReason             = "TerminationReason";
        public static string PropertyName_ValueList                     = "ValueList";
        public static string PropertyName_VarFieldValueList             = "VarFieldValueList";
        public static string PropertyName_Medikamentenverordnungslisten = "Medikamentenverordnungslisten";
        public static string PropertyName_AssistanceBegin               = "AssistanceBegin";
        public static string PropertyName_AusstVersAmt                  = "AusstVersAmt";
        public static string PropertyName_AusweisGueltigVon             = "AusweisGueltigVon";
        public static string PropertyName_AusweisGueltigBis             = "AusweisGueltigBis";
        public static string PropertyName_AusweisUnbefristetGueltig     = "AusweisUnbefristetGueltig";
        public static string PropertyName_BeiblattGueltigBis            = "BeiblattGueltigBis";
        public static string PropertyName_GradDerBehinderung            = "GradDerBehinderung";
        public static string PropertyName_MerkzeichenListe              = "MerkzeichenListe";
        public static string PropertyName_BehinderungsartenListe        = "BehinderungsartenListe";
	    public static string PropertyName_CustomerAlias                 = "CustomerAlias";
        public static string PropertyName_Pflegegrad                    = "Pflegegrad";
        public static string Propertyname_CustomerImage                 = "CustomerImage";
        

		private Auszahlungsintervall                _Auszahlungsintervall;
        private IList<AbsenceTime>                  _AbsenceTimes;
        private Person                              _Ansprechpartner;
        private IList<AssessmentSheetCategory>      _AssessmentSheetCategoryList;
        private string                              _Childs;
		private string                              _CostCenter;
        private IList<Customer2CostBearer>          _Customer2CostBearerList;
        private IList<Customer2Organisation>        _Customer2OrganisationList;
		private IList<Customer2Person>              _Customer2PersonList;
        private string                              _DebitorNumber;
		private string                              _Diagnosis;
        private IList<Diagnosis2Customer>           _Diagnosis2CustomerList;
        private IList<Employee2Customer>            _Employee2CustomerList;
		private string                              _Environment;
        private decimal?                            _EquityContribution;
        private FamilyData                          _FamilyData;
        private string                              _ICD10Diagnosis;
        private bool?                               _IsAdvisedOrAttended;
        private Organisation                        _Jugendamt;
		private string                              _Medication;
		private IList<Medikamentenverordnungsliste> _Medikamentenverordnungslisten;
        private Person                              _Person;
        private IList<Placement>                    _PlacementList;
        private string                              _ReferenceNumber;
        private IList<ServiceRecord>                _ServiceRecordList;
        private IList<SupportConcept>               _SupportConcepts;
		private IList<Team2Customer>                _Team2CustomerList;
        private DateTime?                           _TerminationDate;
        private ValueListEntry                      _TerminationReason;
        private IList<ValueListEntry2Object>        _ValueList;
        private IList<VarFieldValue>                _VarFieldValueList;
        private DateTime?                           _AssistanceBegin;
	    private string                              _AusstVersAmt;
        private DateTime?                           _AusweisGueltigVon;
        private DateTime?                           _AusweisGueltigBis;
        private bool?                               _AusweisUnbefristetGueltig;
        private DateTime?                           _BeiblattGueltigBis;
        private string                              _GradDerBehinderung;
        private IList<Merkzeichen>                  _MerkzeichenListe;
        private IList<Behinderungsart>              _BehinderungsartenListe;
	    private string                              _CustomerAlias;
        private Pflegegrad?                         _Pflegegrad;
        private byte[]                              _CustomerImage;
	  


		public Customer()
		{
			_Tid = TableID.Customer;
		}

		
		public virtual int? DistanceInMeter { get; set; }

		public virtual IList<AbsenceTime> AbsenceTimes
		{
			get { return _AbsenceTimes ?? (_AbsenceTimes = new List<AbsenceTime>()); }

			set
			{
				if (AreDifferent(_AbsenceTimes, value))
				{
					_AbsenceTimes = value;
				}
			}
		}

		public virtual Person Ansprechpartner
		{
			get { return _Ansprechpartner; }

			set
			{
				if (AreDifferent(_Ansprechpartner, value))
					_Ansprechpartner = value;
			}
		}


		public virtual IList<AssessmentSheetCategory> AssessmentSheetCategoryList
		{
			get { return _AssessmentSheetCategoryList ?? (_AssessmentSheetCategoryList = new List<AssessmentSheetCategory>()); }

			set
			{
				if (AreDifferent(_AssessmentSheetCategoryList, value))
				{
					_AssessmentSheetCategoryList = value;
				}
			}
		}

		public virtual string Childs
		{
			get { return _Childs; }

			set
			{
				if (AreDifferent(_Childs, value))
				{
					_Childs = value;
				}
			}
		}

		public virtual IList<Customer2CostBearer> Customer2CostBearerList
		{
			get { return _Customer2CostBearerList ?? (_Customer2CostBearerList = new List<Customer2CostBearer>()); }

			set
			{
				if (AreDifferent(_Customer2CostBearerList, value))
				{
					_Customer2CostBearerList = value;
				}
			}
		}

		public virtual IList<Customer2Person> Customer2PersonList
		{
			get { return _Customer2PersonList ?? (_Customer2PersonList = new List<Customer2Person>()); }

			set
			{
				if (AreDifferent(_Customer2PersonList, value))
				{
					_Customer2PersonList = value;
				}
			}
		}

		public virtual IList<Customer2Organisation> Customer2OrganisationList
		{
			get { return _Customer2OrganisationList ?? (_Customer2OrganisationList = new List<Customer2Organisation>()); }

			set
			{
				if (AreDifferent(_Customer2OrganisationList, value))
				{
					_Customer2OrganisationList = value;
				}
			}
		}

		public virtual string DebitorNumber
		{
			get { return _DebitorNumber; }

			set
			{
				if (AreDifferent(_DebitorNumber, value))
				{
					_DebitorNumber = value;
				}
			}
		}

		public virtual string CostCenter
		{
			get { return _CostCenter; }

			set
			{
				if (AreDifferent(_CostCenter, value))
				{
					_CostCenter = value;
				}
			}
		}

		public virtual string Diagnosis
		{
			get { return _Diagnosis; }

			set
			{
				if (AreDifferent(_Diagnosis, value))
				{
					_Diagnosis = value;
				}
			}
		}

		public virtual IList<Diagnosis2Customer> Diagnosis2CustomerList
		{
			get { return _Diagnosis2CustomerList ?? (_Diagnosis2CustomerList = new List<Diagnosis2Customer>()); }

			set
			{
				if (AreDifferent(_Diagnosis2CustomerList, value))
				{
					_Diagnosis2CustomerList = value;
				}
			}
		}

		public virtual IList<Employee2Customer> Employee2CustomerList
		{
			get { return _Employee2CustomerList ?? (_Employee2CustomerList = new List<Employee2Customer>()); }

			set
			{
				if (AreDifferent(_Employee2CustomerList, value))
				{
					_Employee2CustomerList = value;
				}
			}
		}

		public virtual FamilyData FamilyData
		{
			get { return _FamilyData ?? (_FamilyData = new FamilyData()); }

			set
			{
				if (AreDifferent(_FamilyData, value))
					_FamilyData = value;
			}
		}

        public virtual Pflegegrad? Pflegegrad
        {
            get { return _Pflegegrad; }

            set
            {
                if (AreDifferent(_Pflegegrad, value))
                    _Pflegegrad = value;
            }
        }



		public virtual IList<Team2Customer> Team2CustomerList
		{
			get { return _Team2CustomerList ?? (_Team2CustomerList = new List<Team2Customer>()); }
			set
			{
				if (base.AreDifferent(_Team2CustomerList, value))
					_Team2CustomerList = value;
			}
		}

		public virtual decimal? EquityContribution
		{
			get { return _EquityContribution; }

			set
			{
				if (AreDifferent(_EquityContribution, value))
				{
					_EquityContribution = value;
				}
			}
		}
		
		public virtual string ICD10Diagnosis
		{
			get { return _ICD10Diagnosis; }

			set
			{
				if (AreDifferent(_ICD10Diagnosis, value))
				{
					_ICD10Diagnosis = value;
				}
			}
		}

		public virtual bool? IsAdvisedOrAttended
		{
			get { return _IsAdvisedOrAttended; }

			set
			{
				if (AreDifferent(_IsAdvisedOrAttended, value))
				{
					_IsAdvisedOrAttended = value;
				}
			}
		}

		public virtual string Medication
		{
			get { return _Medication; }

			set
			{
				if (AreDifferent(_Medication, value))
				{
					_Medication = value;
				}
			}
		}

		public virtual string Environment
		{
			get { return _Environment; }

			set
			{
				if (AreDifferent(_Environment, value))
				{
					_Environment = value;
				}
			}
		}

		public virtual Organisation Jugendamt
		{
			get { return _Jugendamt; }

			set
			{
				if (AreDifferent(_Jugendamt, value))
					_Jugendamt = value;
			}
		}

		public virtual Person Person
		{
			get { return _Person; }

			set
			{
				if (AreDifferent(_Person, value))
				{
					_Person = value;
					_Person.Type = PersonType.Customer;
				}
			}
		}

		public virtual IList<Placement> PlacementList
		{
			get { return _PlacementList ?? (_PlacementList = new List<Placement>()); }

			set
			{
				if (AreDifferent(_PlacementList, value))
				{
					_PlacementList = value;
				}
			}
		}

		public virtual string ReferenceNumber
		{
			get { return _ReferenceNumber; }

			set
			{
				if (AreDifferent(_ReferenceNumber, value))
				{
					_ReferenceNumber = value;
				}
			}
		}

		public virtual IList<ServiceRecord> ServiceRecordList
		{
			get { return _ServiceRecordList; }

			set
			{
				if (AreDifferent(_ServiceRecordList, value))
				{
					_ServiceRecordList = value;
				}
			}
		}

		public virtual IList<SupportConcept> SupportConcepts
		{
			get { return _SupportConcepts ?? (_SupportConcepts = new List<SupportConcept>()); }

			set
			{
				if (AreDifferent(_SupportConcepts, value))
				{
					_SupportConcepts = value;
				}
			}
		}

		public virtual IList<Medikamentenverordnungsliste> Medikamentenverordnungslisten
		{
			get { return _Medikamentenverordnungslisten ?? (_Medikamentenverordnungslisten = new List<Medikamentenverordnungsliste>()); }
			set
			{
				if (AreDifferent(_Medikamentenverordnungslisten, value))
					_Medikamentenverordnungslisten = value;
			}
		}

		public virtual DateTime? TerminationDate
		{
			get { return _TerminationDate; }

			set
			{
				if (AreDifferent(_TerminationDate, value))
				{
					_TerminationDate = value;
				}
			}
		}

        public virtual DateTime? AssistanceBegin
        {
            get { return _AssistanceBegin; }

            set
            {
                if (AreDifferent(_AssistanceBegin, value))
                {
                    _AssistanceBegin = value;
                }
            }
        }

		public virtual ValueListEntry TerminationReason
		{
			get { return _TerminationReason; }

			set
			{
				if (AreDifferent(_TerminationReason, value))
				{
					_TerminationReason = value;
				}
			}
		}

		public virtual IList<ValueListEntry2Object> ValueList
		{
			get { return _ValueList ?? (_ValueList = new List<ValueListEntry2Object>()); }

			set
			{
				if (AreDifferent(_ValueList, value))
				{
					_ValueList = value;
				}
			}
		}

		public virtual IList<VarFieldValue> VarFieldValueList
		{
			get { return _VarFieldValueList ?? (_VarFieldValueList = new List<VarFieldValue>()); }

			set
			{
				if (AreDifferent(_VarFieldValueList, value))
				{
					_VarFieldValueList = value;
				}
			}
		}

		public virtual Dictionary<DateTimeSpan, decimal> GetAbsencesTimesNotBillableWholeWeeks()
		{
			var lResult = new Dictionary<DateTimeSpan, decimal>();
			IList<AbsenceTime> times = AbsenceTimes;
			foreach (AbsenceTime at in times)
			{
				IEnumerable<DateTimeSpan> weeks = at.AbsenceSpan.GetWholeWeeks();
				foreach (DateTimeSpan span in weeks)
				{
					if (at.AbsenceReason.BillableMinutes.HasValue && at.AbsenceReason.BillableMinutes.Value > 0 && !lResult.ContainsKey(span))
					{
						lResult.Add(span, at.AbsenceReason.BillableMinutes.Value);
					}
				}
			}


			return lResult;
		}

        public virtual string AusstVersAmt
        {
            get { return _AusstVersAmt; }

            set
            {
                if (AreDifferent(_AusstVersAmt, value))
                {
                    _AusstVersAmt = value;
                }
            }
        }

        public virtual DateTime? AusweisGueltigVon
        {
            get { return _AusweisGueltigVon; }

            set
            {
                if (AreDifferent(_AusweisGueltigVon, value))
                {
                    _AusweisGueltigVon = value;
                }
            }
        }

        public virtual DateTime? AusweisGueltigBis
        {
            get { return _AusweisGueltigBis; }

            set
            {
                if (AreDifferent(_AusweisGueltigBis, value))
                {
                    _AusweisGueltigBis = value;
                }
            }
        }

        public virtual bool? AusweisUnbefristetGueltig
        {
            get { return _AusweisUnbefristetGueltig; }

            set
            {
                if (AreDifferent(_AusweisUnbefristetGueltig, value))
                {
                    _AusweisUnbefristetGueltig = value;
                }
            }
        }

        public virtual DateTime? BeiblattGueltigBis
        {
            get { return _BeiblattGueltigBis; }

            set
            {
                if (AreDifferent(_BeiblattGueltigBis, value))
                {
                    _BeiblattGueltigBis = value;
                }
            }
        }

        public virtual string GradDerBehinderung
        {
            get { return _GradDerBehinderung; }

            set
            {
                if (AreDifferent(_GradDerBehinderung, value))
                {
                    _GradDerBehinderung = value;
                }
            }
        }

        public virtual IList<Behinderungsart> BehinderungsartenListe
        {
            get { return _BehinderungsartenListe; }

            set
            {
                if (AreDifferent(_BehinderungsartenListe, value))
                {
                    _BehinderungsartenListe = value;
                }
            }
        }

        public virtual IList<Merkzeichen> MerkzeichenListe
        {
            get { return _MerkzeichenListe; }

            set
            {
                if (AreDifferent(_MerkzeichenListe, value))
                {
                    _MerkzeichenListe = value;
                }
            }
        }

	    public virtual string CustomerAlias
	    {
            get { return _CustomerAlias; }

	        set
	        {
	            if (AreDifferent(_CustomerAlias, value))
	            {
	                _CustomerAlias = value;
	            }
	        }
	    }

        public virtual Byte[] CustomerImage
        {
            get { return _CustomerImage; }

            set
            {
                if (AreDifferent(_CustomerImage, value))
                {
                    _CustomerImage = value;
                }
            }
        }

     
	}
}