using BeWo.Data.Entities;

using BS.Shared;
using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class ServiceRecordDC_ServiceRecordCompact : AbstractIDCEntityMapper<ServiceRecord, ServiceRecordDC>
    {
        public override ServiceRecordDC MergeWithDC(ServiceRecord pEntity, ServiceRecordDC pDataContract)
        {
            pDataContract.ServiceRecordOid = pEntity.Oid;
            pDataContract.ServiceRecordVersion = pEntity.Version;
            pDataContract.Start = pEntity.Start;
            pDataContract.End = pEntity.End;
            pDataContract.Notice = pEntity.Notice;
            pDataContract.ServiceRecordType = pEntity.ServiceRecordType ?? ServiceRecordTypeId.DefaultActivity;
                                                 // ? pEntity.ServiceRecordType.Value
                                                 // : ServiceRecordTypeId.DefaultActivity;

            if (pEntity.ServiceDescription != null)
            {
                pDataContract.ServiceDescription = MapperFactory.ServiceDescriptionDC_ServiceDescription.MapToNewDC(pEntity.ServiceDescription);
            }
            pDataContract.WohnheimbuchungsOid = pEntity.WohnheimbuchungsOid;
            pDataContract.RoundedDuration = pEntity.RoundedDuration;
            pDataContract.InsertedOn = pEntity.InsTs;
            pDataContract.InsUser = pEntity.InsUser;

            pDataContract.GroupEmployeeCount = pEntity.GroupEmployeeCount;
            pDataContract.GroupPersonCount = pEntity.GroupPersonCount;
            pDataContract.GroupRoundedDuration = pEntity.GroupRoundedDuration;
            pDataContract.GroupOid = pEntity.GroupOid;

            return pDataContract;
        }

        public override ServiceRecord MergeWithEntity(ServiceRecordDC pDataContract, ServiceRecord pEntity)
        {
            return null;
        }

        protected override bool AreDCAndEntityEqual(ServiceRecordDC pDC, ServiceRecord pEntity)
        {
            if (pDC.ServiceRecordOid == null)
            {
                return false;
            }

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