using System;
using BS.Shared;

namespace BeWo.Data.Entities
{
    public class ServiceRecordHistory : BeWoEntityBase
    {
        public static string PropertyName_CostBearer2SupportConcept = "CostBearer2SupportConcept";

        public static string PropertyName_CostBearer2SupportConceptOid = "CostBearer2SupportConceptOid";

        public static string PropertyName_Customer = "Customer";

        public static string PropertyName_CustomerOid = "CustomerOid";

        public static string PropertyName_Employee = "Employee";
        
        public static string PropertyName_EmployeeOid = "EmployeeOid";

        public static string PropertyName_End = "End";

        public static string PropertyName_GroupEmployeeCount = "GroupEmployeeCount";

        public static string PropertyName_GroupOid = "GroupOid";

        public static string PropertyName_GroupPersonCount = "GroupPersonCount";

        public static string PropertyName_GroupRoundedDuration = "GroupRoundedDuration";

        public static string PropertyName_IP = "IP";

        public static string PropertyName_RoundedDuration = "RoundedDuration";

        public static string PropertyName_ServiceDescription = "ServiceDescription";

        public static string PropertyName_Start = "Start";

        public static string PropertyName_SupportConcept = "SupportConcept";

        public static string PropertyName_ValueList = "ValueList";

        public static string PropertyName_ServiceRecordType = "ServiceRecordType";

        public static string PropertyName_ChangeType = "ChangeType";

        public static string PropertyName_ServiceRecordOid = "ServiceRecordOid";

        public static string PropertyName_TimeStamp = "TimeStamp";

        public static string PropertyName_ServiceRecordInsTs = "ServiceRecordInsTs";

        public static string PropertyName_ServiceRecordInsUser = "ServiceRecordInsUser";

        public static string PropertyName_ServiceRecordVersion = "ServiceRecordVersion";

        public static string PropertyName_ServiceRecordUdpUser = "ServiceRecordUdpUser";

		public static string PropertyName_IsCreatedInMobileClient = "IsCreatedInMobileClient";


		private bool _IsCreatedInMobileClient;

		public virtual bool IsCreatedInMobileClient
		{
			get
			{
				return _IsCreatedInMobileClient;
			}

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

        private CostBearer2SupportConcept _CostBearer2SupportConcept;

        private long? _CostBearer2SupportConceptOid;

        private Customer _Customer;

        private long? _CustomerOid;

        private Employee _Employee;

        private long? _EmployeeOid;

        private DateTime? _End;

        private ServiceRecordGroup _Group;

        private int? _GroupEmployeeCount;

        private long? _GroupOid;

        private int? _GroupPersonCount;

        private decimal? _GroupRoundedDuration;

        private string _IP;

        private decimal _RoundedDuration;

        private ServiceRecordTypeId? _ServiceRecordType;

        private ServiceDescription _ServiceDescription;

        private DateTime? _Start;

        private SupportConcept _SupportConcept;

        private StatementType _ChangeType;

        private long? _ServiceRecordOid;

        private DateTime? _TimeStamp;

        private DateTime? _ServiceRecordInsTs;

        private string _ServiceRecordInsUser;

        private string _ServiceRecordUdpUser;

        private long _ServiceRecordVersion;


        public virtual CostBearer2SupportConcept CostBearer2SupportConcept
        {
            get
            {
                return this._CostBearer2SupportConcept;
            }

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

        public virtual long? CostBearer2SupportConceptOid
        {
            get
            {
                return this._CostBearer2SupportConceptOid;
            }

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

        public virtual Customer Customer
        {
            get
            {
                return this._Customer;
            }

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

        public virtual long? CustomerOid
        {
            get
            {
                return this._CustomerOid;
            }

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

        public virtual double DurationMinutes
        {
            get
            {
                return this.GetDurationMinutes();
            }
        }

        public virtual Employee Employee
        {
            get
            {
                return this._Employee;
            }

            set
            {
                if (this.AreDifferent(this._Employee, value))
                {
                    this._Employee = value;
                    if (this._Employee != null)
                    {
                        this.EmployeeOid = this._Employee.Oid;
                    }
                    else
                    {
                        this.EmployeeOid = null;
                    }
                }
            }
        }

        public virtual long? EmployeeOid
        {
            get
            {
                return this._EmployeeOid;
            }

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

        public virtual DateTime? End
        {
            get
            {
                return this._End;
            }

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

        public virtual ServiceRecordGroup Group
        {
            get
            {
                return this._Group;
            }

            set
            {
                if (this.AreDifferent(this._Group, value))
                {
                    this._Group = value;
                    if (this._Group != null)
                    {
                        this.GroupOid = this._Group.Oid;
                    }
                    else
                    {
                        this.GroupOid = null;
                    }
                }
            }
        }

        public virtual int? GroupEmployeeCount
        {
            get
            {
                return this._GroupEmployeeCount;
            }

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

        public virtual long? GroupOid
        {
            get
            {
                return this._GroupOid;
            }

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

        public virtual int? GroupPersonCount
        {
            get
            {
                return this._GroupPersonCount;
            }

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

        public virtual decimal? GroupRoundedDuration
        {
            get
            {
                return this._GroupRoundedDuration;
            }

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

        public virtual string IP
        {
            get
            {
                return this._IP;
            }

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

        public virtual decimal RoundedDuration
        {
            get
            {
                return this._RoundedDuration;
            }

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

        public virtual ServiceDescription ServiceDescription
        {
            get
            {
                return this._ServiceDescription;
            }

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

        public virtual DateTime? Start
        {
            get
            {
                return this._Start;
            }

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

        public virtual SupportConcept SupportConcept
        {
            get
            {
                return this._SupportConcept;
            }

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

        public virtual ServiceRecordTypeId? ServiceRecordType
        {
            get
            {
                return this._ServiceRecordType;
            }

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

        public virtual string Title
        {
            get
            {
                String date = "";
                String time = "";

                if (Start.HasValue)
                {
                    date = Start.Value.Date.ToShortDateString();

                    DateTime timeDt = Start.Value;

                    if (timeDt.Second == 0)
                    {
                        time = timeDt.ToShortTimeString();
                        if (GroupOid != null && GroupRoundedDuration != null)
                            timeDt = timeDt.AddMinutes((double)GroupRoundedDuration);
                        else
                            timeDt = timeDt.AddMinutes((double)RoundedDuration);
                        time = time + " - " + timeDt.ToShortTimeString();
                    }

                }


                date += " " + time;

                if (GroupOid != null && GroupPersonCount != null && GroupRoundedDuration != null)
                {
                    date += String.Format(" Gruppe ({0} Teilnehmer, {1} Betreuer). Dauer: {2:0.##} Minuten.", GroupPersonCount.Value, GroupEmployeeCount.Value, GroupRoundedDuration.Value);
                }
                return date;

            }
        }

        public virtual double GetDurationMinutes()
        {
            if (GroupOid.HasValue)
            {
                return (double)RoundedDuration;
            }
            else
            {
                return (End.Value - Start.Value).TotalMinutes;
            }
        }

        public virtual StatementType ChangeType
        {
            get { return _ChangeType; }

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

        public virtual long? ServiceRecordOid
        {
            get { return _ServiceRecordOid; }

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

        public virtual DateTime? TimeStamp
        {
            get { return _TimeStamp; }

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

        public virtual DateTime? ServiceRecordInsTs
        {
            get { return _ServiceRecordInsTs; }
            set
            {
                if (AreDifferent(_ServiceRecordInsTs, value))
                    _ServiceRecordInsTs = value;
            }
        }

        public virtual string ServiceRecordInsUser
        {
            get { return _ServiceRecordInsUser; }

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

        public virtual string ServiceRecordUdpUser
        {
            get { return _ServiceRecordUdpUser; }

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

        public virtual long ServiceRecordVersion
        {
            get { return _ServiceRecordVersion; }

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

		public virtual int? DistanceInMeter { get; set; }

		public virtual int? Relevance { get; set; }

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