using BeWo.Data.Entities;

using BS.Shared.DataContracts;

namespace BeWo.Service.DCEntityMapper
{
    public class BeWoFolderDC_BeWoFolder : AbstractIDCEntityMapper<BeWoFolder, BeWoFolderDC>
    {
        public override BeWoFolderDC MergeWithDC(BeWoFolder pEntity, BeWoFolderDC pDataContract)
        {
            pDataContract.BeWoFolderOid = pEntity.Oid;
            pDataContract.BeWoFolderVersion = pEntity.Version;

            pDataContract.Files = new System.Collections.Generic.List<FileAttachmentDC>();
            pDataContract.SubFolders = new System.Collections.Generic.List<BeWoFolderDC>();
            //pDataContract.Files = MapperFactory.FileAttachmentDC_FileAttachmentInfo.MapToNewDCs(pEntity.Files);
            //pDataContract.SubFolders = MapperFactory.BeWoFolderDC_BeWoFolder.MapToNewDCs(pEntity.SubFolders);
            pDataContract.ObjectOid = pEntity.ObjectOid;
            pDataContract.ObjectTid = pEntity.ObjectTid;
            pDataContract.Name = pEntity.Name;
            pDataContract.ParentBeWoFolderOid = pEntity.ParentBeWoFolderOid;
            
            return pDataContract;
        }

        public override BeWoFolder MergeWithEntity(BeWoFolderDC pDataContract, BeWoFolder pEntity)
        {
            this.ConcurrencyCheck(pDataContract.BeWoFolderVersion, pEntity);
            //MapperFactory.FileAttachmentDC_FileAttachmentInfo.MergeWithEntitys(pDataContract.Files, pEntity.Files);
            //MapperFactory.BeWoFolderDC_BeWoFolder.MergeWithEntitys(pDataContract.SubFolders, pEntity.SubFolders);
            pEntity.Oid = pDataContract.BeWoFolderOid;

            pEntity.ObjectOid = pDataContract.ObjectOid;
            pEntity.ObjectTid = pDataContract.ObjectTid;
            pEntity.Name = pDataContract.Name;
            pEntity.ParentBeWoFolderOid = pDataContract.ParentBeWoFolderOid;

            return pEntity;
        }

        protected override bool AreDCAndEntityEqual(BeWoFolderDC pDC, BeWoFolder pEntity)
        {
            if (pDC.BeWoFolderOid == null)
            {
                return false;
            }

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