using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using BS.Shared.DataContracts.Compact;

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

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

		[DataMember]
		public bool IsPrivate { 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 Originator { get; set; }

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

		[DataMember]
		public bool AllDay { 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 List<CompactCustomerDC> CustomerList { get; set; }

		[DataMember]
		public List<Employee2SchedulerAppointmentDC> EmployeeList { get; set; }

		[DataMember]
		public List<ResourceDC> ResourceList { get; set; }

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

		public override bool Equals(object obj)
		{
			if (!(obj is SchedulerAppointmentDC)) return false;

			var y = (SchedulerAppointmentDC) obj;

			if (SchedulerAppointmentOid == null && y.SchedulerAppointmentOid == null)
				return GetHashCode() == y.GetHashCode();

			if (SchedulerAppointmentOid != null && y.SchedulerAppointmentOid != null)
				return SchedulerAppointmentOid == y.SchedulerAppointmentOid;

			var value = StartDate == y.StartDate && EndDate == y.EndDate && Type == y.Type && (Description == y.Description) &&
				EmployeeList.SequenceEqual(y.EmployeeList) && ResourceList.SequenceEqual(y.ResourceList) && CustomerList.SequenceEqual(y.CustomerList);

			return value;
		}

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