using BeWo.Data.Entities;

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class InvoiceNumberDC_InvoiceNumber : AbstractIDCEntityMapper<InvoiceNumber, InvoiceNumberDC>
    {
        public override InvoiceNumberDC MergeWithDC(InvoiceNumber pEntity, InvoiceNumberDC pDataContract)
        {
            pDataContract.InvoiceNumberOid = pEntity.Oid;
            pDataContract.InvoiceNumberVersion = pEntity.Version;
            pDataContract.CurrentNumber = pEntity.CurrentNumber;
            pDataContract.Pattern = pEntity.Pattern;
            pDataContract.Use = pEntity.Use;

            return pDataContract;
        }

        public override InvoiceNumber MergeWithEntity(InvoiceNumberDC pDataContract, InvoiceNumber pEntity)
        {
            this.ConcurrencyCheck(pDataContract.InvoiceNumberVersion, pEntity);

            pEntity.CurrentNumber = pDataContract.CurrentNumber;
            pEntity.Pattern = pDataContract.Pattern;
            pEntity.Use = pDataContract.Use;

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(InvoiceNumberDC pDC, InvoiceNumber pEntity)
        {
            if (pDC.InvoiceNumberOid == null)
            {
                return false;
            }

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