using BeWo.Data.Access;
using BeWo.Data.Entities;

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class AbsenceTimeDC_AppointmentAbsenceTime : AbstractIDCEntityMapper<AppointmentAbsenceTime, AbsenceTimeDC>
    {
        public override AbsenceTimeDC MergeWithDC(AppointmentAbsenceTime pEntity, AbsenceTimeDC pDataContract)
        {
            pDataContract.AbsenceTimeOid = pEntity.Oid;
            pDataContract.AbsenceTimeVersion = pEntity.Version;
            pDataContract.End = pEntity.End;
            pDataContract.Start = pEntity.Start;
            pDataContract.Notice = pEntity.Notice;
            pDataContract.Reason = MapperFactory.AbsenceReasonDC_AbsenceReason.MapToNewDC(pEntity.AbsenceReason);
            pDataContract.EmployeeOid = pEntity.EmployeeOid;
            pDataContract.CustomerOid = pEntity.CustomerOid;

            return pDataContract;
        }

        public override AppointmentAbsenceTime MergeWithEntity(AbsenceTimeDC pDataContract, AppointmentAbsenceTime pEntity)
        {
            this.ConcurrencyCheck(pDataContract.AbsenceTimeVersion, pEntity);

            pEntity.AbsenceReason = DAOFactory.GenericDAO.LoadByID<AbsenceReason>(pDataContract.Reason.AbsenceReasonOid.Value);
            pEntity.End = pDataContract.End;
            pEntity.Start = pDataContract.Start;
            pEntity.Notice = pDataContract.Notice;
            pEntity.Oid = pDataContract.AbsenceTimeOid;
            pEntity.CustomerOid = pDataContract.CustomerOid;
            pEntity.EmployeeOid = pDataContract.EmployeeOid;

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(AbsenceTimeDC pDC, AppointmentAbsenceTime pEntity)
        {
            if (pDC.AbsenceTimeOid == null)
            {
                return false;
            }

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