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

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class SupportConceptApprovalPeriodEmployeeRelDC_SupportConceptApprovalPeriod2Employee : AbstractIDCEntityMapper<SupportConceptApprovalPeriod2Employee, SupportConceptApprovalPeriodEmployeeRelDC>
    {
        public override SupportConceptApprovalPeriodEmployeeRelDC MergeWithDC(SupportConceptApprovalPeriod2Employee pEntity, SupportConceptApprovalPeriodEmployeeRelDC pDataContract)
        {
            pDataContract.SupportConceptApprovalPeriod2EmployeeOid     = pEntity.Oid;
            pDataContract.SupportConceptApprovalPeriod2EmployeeVersion = pEntity.Version;
            pDataContract.Betreuungsschluessel                         = pEntity.Betreuungsschluessel;
            pDataContract.Employee                                     = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(pEntity.Employee);

            return pDataContract;
        }

        public override SupportConceptApprovalPeriod2Employee MergeWithEntity(SupportConceptApprovalPeriodEmployeeRelDC pDataContract, SupportConceptApprovalPeriod2Employee pEntity)
        {
            ConcurrencyCheck(pDataContract.SupportConceptApprovalPeriod2EmployeeVersion, pEntity);

            pEntity.Employee                     = DAOFactory.GenericDAO.LoadByID<Employee>(pDataContract.Employee.EmployeeOid);
            pEntity.Betreuungsschluessel         = pDataContract.Betreuungsschluessel;

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(SupportConceptApprovalPeriodEmployeeRelDC pDC, SupportConceptApprovalPeriod2Employee pEntity)
        {
            if (pDC.SupportConceptApprovalPeriod2EmployeeOid == null)
            {
                return false;
            }

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