using System;
using System.Runtime.Serialization;

namespace BS.Shared.DataContracts
{
	[DataContract, Serializable]
    public partial class AbsenceTimeDC : IDataContract
    {
        [DataMember]
        public long? AbsenceTimeOid { get; set; }

        [DataMember]
        public long? AbsenceTimeVersion { get; set; }

        [DataMember]
        public DateTime? End { get; set; }

        [DataMember]
        public string Notice { get; set; }

        [DataMember]
        public AbsenceReasonDC Reason { get; set; }

        [DataMember]
        public long? EmployeeOid { get; set; }

        [DataMember]
        public long? CustomerOid { get; set; }

        [DataMember]
        public DateTime? Start { get; set; }

        public override bool Equals(object obj)
        {
            if (obj is AbsenceTimeDC)
            {
                var y = (AbsenceTimeDC) obj;
                if (AbsenceTimeOid == null && y.AbsenceTimeOid == null)
                {
                    return GetHashCode() == y.GetHashCode();
                }

                if (AbsenceTimeOid != null && y.AbsenceTimeOid != null)
                {
                    return AbsenceTimeOid == y.AbsenceTimeOid;
                }

                if (Start == y.Start && End == y.End
                    && Notice == y.Notice
                    && CustomerOid == y.CustomerOid && EmployeeOid == y.EmployeeOid)
                {
                    if (Reason == null && y.Reason == null)
                        return true;
                    if (Reason != null && y.Reason != null && Reason.AbsenceReasonOid == y.Reason.AbsenceReasonOid)
                        return true;
                }
            }

            return false;
        }

        public override int GetHashCode()
        {
            return AbsenceTimeOid.HasValue
                ? GetType().Name.GetHashCode() ^ AbsenceTimeOid.GetHashCode()
                : base.GetHashCode();
        }
    }
}