using System;
using System.Drawing;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
	public class ResourceAppointmentDC_ResourceAppointment : AbstractIDCEntityMapper<ResourceAppointment, ResourceAppointmentDC>
	{
		public override ResourceAppointmentDC MergeWithDC(ResourceAppointment pEntity, ResourceAppointmentDC pDataContract)
		{
			pDataContract.ResourceAppointmentOid = pEntity.Oid;
			pDataContract.ResourceAppointmentVersion = pEntity.Version;
			pDataContract.AllDay = pEntity.AllDay;
			pDataContract.EndDate = pEntity.EndDate;
			pDataContract.StartDate = pEntity.StartDate;
			pDataContract.Status = pEntity.Status;
			pDataContract.Subject = pEntity.Subject;
			pDataContract.Type = pEntity.Type;
			pDataContract.Location = pEntity.Location;
			pDataContract.Description = pEntity.Notice;
			pDataContract.RecurrenceInfo = pEntity.RecurrenceInfo;
			pDataContract.ReminderInfo = pEntity.ReminderInfo;
			pDataContract.FormerBookingOid = pEntity.FormerBookingOid;
			pDataContract.FormerBookingSequenceOid = pEntity.FormerBookingSequenceOid;

			if (pEntity.Employee != null)
				pDataContract.Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(pEntity.Employee);

			if (pEntity.Resource != null)
				pDataContract.Resource = MapperFactory.ResourceDC_Resource.MapToNewDC(pEntity.Resource);

			return pDataContract;
		}

		public override ResourceAppointment MergeWithEntity(ResourceAppointmentDC pDataContract, ResourceAppointment pEntity)
		{
			pEntity.Oid = pDataContract.ResourceAppointmentOid;
			pEntity.Version = pDataContract.ResourceAppointmentVersion;
			pEntity.AllDay = pDataContract.AllDay;
			pEntity.EndDate = pDataContract.EndDate;
			pEntity.StartDate = pDataContract.StartDate;
			pEntity.Status = pDataContract.Status;
			pEntity.Subject = pDataContract.Subject;
			pEntity.Type = pDataContract.Type;
			pEntity.Location = pDataContract.Location;
			pEntity.Notice = pDataContract.Description;
			pEntity.RecurrenceInfo = pDataContract.RecurrenceInfo;
			pEntity.ReminderInfo = pDataContract.ReminderInfo;
			pEntity.FormerBookingOid = pDataContract.FormerBookingOid;
			pEntity.FormerBookingSequenceOid = pDataContract.FormerBookingSequenceOid;

			if (pDataContract.Employee != null)
				pEntity.Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewEntity(pDataContract.Employee);

			if (pDataContract.Resource != null)
				pEntity.Resource = pDataContract.Resource.ResourceOid.HasValue
					? DAOFactory.GenericDAO.LoadByID<Resource>(pDataContract.Resource.ResourceOid.Value)
					: null;

			return pEntity;
		}

		protected override bool AreDCAndEntityEqual(ResourceAppointmentDC pDC, ResourceAppointment pEntity)
		{
			if (pDC.ResourceAppointmentOid == null)
				return false;

			return pDC.ResourceAppointmentOid == pEntity.Oid;
		}
	}
}
