using BS.Shared.DataContracts;
using BeWo.Data.Entities;

namespace BeWo.Service.DCEntityMapper
{
    public class AdditionalServiceGroupOfPeopleCD_AdditionalServiceGroupOfPeople : AbstractIDCEntityMapper<AdditionalServiceGroupOfPeople, AdditionalServiceGroupOfPeopleDC>
    {
        public override AdditionalServiceGroupOfPeopleDC MergeWithDC(AdditionalServiceGroupOfPeople pEntity, AdditionalServiceGroupOfPeopleDC pDataContract)
        {
            pDataContract.Name = pEntity.Name;
            pDataContract.AdditionalServiceGroupOfPeopleOid = pEntity.Oid;
            pDataContract.AdditionalServiceGroupOfPeopleVersion = pEntity.Version;
            pDataContract.CustomerList = MapperFactory.CompactCustomerDC_Customer.MapToNewDCs(pEntity.CustomerList);
            pDataContract.AppointmentDayOfWeek = pEntity.AppointmentDayOfWeek;

            return pDataContract;
        }

        public override AdditionalServiceGroupOfPeople MergeWithEntity(AdditionalServiceGroupOfPeopleDC pDataContract, AdditionalServiceGroupOfPeople pEntity)
        {
            ConcurrencyCheck(pDataContract.AdditionalServiceGroupOfPeopleVersion, pEntity);

            pEntity.Name = pDataContract.Name;
            pEntity.Oid = pDataContract.AdditionalServiceGroupOfPeopleOid;
            pEntity.AppointmentDayOfWeek = pDataContract.AppointmentDayOfWeek;

            if (pDataContract.CustomerList != null)
                MapperFactory.CompactCustomerDC_Customer.MergeWithEntitys(pDataContract.CustomerList, pEntity.CustomerList);

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(AdditionalServiceGroupOfPeopleDC pDC, AdditionalServiceGroupOfPeople pEntity)
        {
            if (pDC.AdditionalServiceGroupOfPeopleOid == null)
                return false;

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