using System;

using BS.Shared;

namespace BeWo.Data.Entities
{
    public class Mandator : BeWoEntityBase
    {
        public static string PropertyName_BeWoClientType = "BeWoClientType";

        public static string PropertyName_ClientId = "ClientId";

        public static string PropertyName_Country = "Country";

        public static string PropertyName_Name = "Name";

        public static string PropertyName_PostalCode = "PostalCode";

        public static string PropertyName_Settings = "Settings";

        public static string PropertyName_State = "State";

        public static string PropertyName_Street = "Street";

        public static string PropertyName_Town = "Town";

        public static string Setting_IsServiceRecordNoticeMandatory = "IsServiceRecordNoticeMandatory";

        public static string Setting_IsPasswordSecurityActiv = "IsPasswordSecurityActiv";

        public static string Setting_IsEndDateVisible = "IsEndDateVisible";

        public static string Setting_MaxDaysEditServiceRecordsAllowed = "MaxDaysEditServiceRecordsAllowed";

        public static string Setting_HilfeplanAuslaufAuswahl = "HilfeplanAuslaufAuswahl";

        public static string Setting_AnzTageZeiterfassErfolgt = "HilfeplanAuslaufAuswahl";
        
        private long _BeWoClientType;

        private string _ClientId;

        private string _Country;

        private string _Name;

        private string _PostalCode;

        private string _Settings;

        private string _State;

        private string _Street;

        private string _Town;

		private string _RssFeedUrl;

        public Mandator()
        {
            this._Tid = TableID.Mandator;
        }

        public virtual long BeWoClientType
        {
            get
            {
                return this._BeWoClientType;
            }

            set
            {
                if (this.AreDifferent(this._BeWoClientType, value))
                {
                    this._BeWoClientType = value;
                }
            }
        }

        public virtual string ClientId
        {
            get
            {
                return this._ClientId;
            }

            set
            {
                if (this.AreDifferent(this._ClientId, value))
                {
                    this._ClientId = value;
                }
            }
        }

        public virtual string Country
        {
            get
            {
                return this._Country;
            }

            set
            {
                if (this.AreDifferent(this._Country, value))
                {
                    this._Country = value;
                }
            }
        }

        public virtual bool IsServiceRecordNoticeMandatory
        {
            get
            {
                var val = this.GetSettingValue(Setting_IsServiceRecordNoticeMandatory);
                if (val != null && val.Equals("0"))
                {
                    return false;
                }

                return true;
            }
        }

        public virtual bool IsPasswordSecurityActiv
        {
            get
            {
                var val = this.GetSettingValue(Setting_IsPasswordSecurityActiv);
                if (val != null && val.Equals("0"))
                {
                    return false;
                }

                return true;
            }
        }

        public virtual bool IsEndDateVisible
        {
            get
            {
                var val = this.GetSettingValue(Setting_IsEndDateVisible);
                if (val != null && val.Equals("0"))
                {
                    return false;
                }

                return true;
            }
        }


        public virtual int? MaxDaysEditServiceRecordsAllowed
        {
            get
            {
                var val = this.GetSettingValue(Setting_MaxDaysEditServiceRecordsAllowed);
                int result;
                if (Int32.TryParse(val, out result))
                {
                    return result;
                }

                return null;
            }
        }

        public virtual int? HilfeplanAuslaufAuswahl
        {
            get
            {
                var val = this.GetSettingValue(Setting_HilfeplanAuslaufAuswahl);
                int result;
                if (Int32.TryParse(val, out result))
                {
                    return result;
                }

                return null;
            }
        }

        public virtual int? AnzTageZeiterfassErfolgt
        {
            get
            {
                var val = this.GetSettingValue(Setting_AnzTageZeiterfassErfolgt);
                int result;
                if (Int32.TryParse(val, out result))
                {
                    return result;
                }

                return null;
            }
        }
        

        public virtual string Name
        {
            get
            {
                return this._Name;
            }

            set
            {
                if (this.AreDifferent(this._Name, value))
                {
                    this._Name = value;
                }
            }
        }

        public virtual string PostalCode
        {
            get
            {
                return this._PostalCode;
            }

            set
            {
                if (this.AreDifferent(this._PostalCode, value))
                {
                    this._PostalCode = value;
                }
            }
        }

        public virtual string Settings
        {
            get
            {
                return this._Settings;
            }

            set
            {
                if (this.AreDifferent(this._Settings, value))
                {
                    this._Settings = value;
                }
            }
        }

        public virtual string State
        {
            get
            {
                return this._State;
            }

            set
            {
                if (this.AreDifferent(this._State, value))
                {
                    this._State = value;
                }
            }
        }

        public virtual string Street
        {
            get
            {
                return this._Street;
            }

            set
            {
                if (this.AreDifferent(this._Street, value))
                {
                    this._Street = value;
                }
            }
        }

        public virtual string Town
        {
            get
            {
                return this._Town;
            }

            set
            {
                if (this.AreDifferent(this._Town, value))
                {
                    this._Town = value;
                }
            }
        }

		public virtual string RssFeedUrl
		{
			get
			{
				return this._RssFeedUrl;
			}

			set
			{
				if (this.AreDifferent(this._RssFeedUrl, value))
				{
					this._RssFeedUrl = value;
				}
			}
		}


        protected virtual string GetSettingValue(string key)
        {
            if (!String.IsNullOrEmpty(this.Settings))
            {
                if (this.Settings.IndexOf(";") == -1 && this.Settings.IndexOf("=") == -1)
                {
                    return this.Settings;
                }
                else
                {
                    string[] keyValuePairs = this.Settings.Split(';');

                    foreach (string pair in keyValuePairs)
                    {
                        string[] keyValuePair = pair.Split('=');
                        if (keyValuePair.Length == 2)
                        {
                            if (keyValuePair[0] == key)
                            {
                                return keyValuePair[1];
                            }
                        }
                    }
                }
            }

            return null;
        }

		public virtual bool IsSchedulerAllowed { get; set; }

		public virtual bool IsMedicationAllowed { get; set; }
		
    }
}