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

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class CustomerCostBearerRelDC_Customer2CostBearer : AbstractIDCEntityMapper<Customer2CostBearer, CustomerCostBearerRelationDC>
    {
        public override CustomerCostBearerRelationDC MergeWithDC(Customer2CostBearer pEntity, CustomerCostBearerRelationDC pDataContract)
        {
            pDataContract.CostBearer = MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(pEntity.CostBearer.Organisation);
            pDataContract.Customer2CostBearerOid = pEntity.Oid;
            pDataContract.Customer2CostBearerVersion = pEntity.Version;
            pDataContract.Notice = pEntity.Notice;
            pDataContract.ReferenceNumber = pEntity.ReferenceNumber;

            return pDataContract;
        }

        public override Customer2CostBearer MergeWithEntity(CustomerCostBearerRelationDC pDataContract, Customer2CostBearer pEntity)
        {
            this.ConcurrencyCheck(pDataContract.Customer2CostBearerVersion, pEntity);
            pEntity.Oid = pDataContract.Customer2CostBearerOid;
            pEntity.Notice = pDataContract.Notice;
            pEntity.ReferenceNumber = pDataContract.ReferenceNumber;

            pEntity.CostBearer = DAOFactory.GenericDAO.LoadByID<CostBearer>(pDataContract.CostBearer.CostBearerOid.Value);

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(CustomerCostBearerRelationDC pDC, Customer2CostBearer pEntity)
        {
            if (pDC.Customer2CostBearerOid == null)
            {
                return false;
            }

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