using System;
using System.Runtime.Serialization;
using BS.Shared.DataContracts.Compact;

namespace BS.Shared.DataContracts
{
	[DataContract]
	public class ResourceAppointmentDC : IDataContract
	{
		[DataMember]
		public long? ResourceAppointmentOid { get; set; }

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

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

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

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

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

		[DataMember]
		public CompactEmployeeDC ResponsibleEmployee { get; set; }

		[DataMember]
		public CompactEmployeeDC CreatorEmployee { get; set; }

		[DataMember]
		public int LabelId { get; set; }

		[DataMember]
		public bool AllDay { get; set; }

		[DataMember]
		public CompactEmployeeDC Employee { get; set; }

		[DataMember]
		public int Status { get; set; }

		[DataMember]
		public int Type { get; set; }

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

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

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

		[DataMember]
		public ResourceDC Resource { get; set; }

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

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

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

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

				if (StartDate == y.StartDate &&
					EndDate == y.EndDate &&
					Type == y.Type &&
					Description == y.Description &&
					Employee.Equals(y.Employee))
				{
					if (Resource == null && y.Resource.ResourceCategory.ValueListEntryOid == null)
						return true;
					if (Resource != null && y.Resource.ResourceCategory.ValueListEntryOid != null &&
						Resource.ResourceCategory.ValueListEntryOid == y.Resource.ResourceCategory.ValueListEntryOid)
						return true;
				}
			}

			return false;
		}

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