package com.liangjian.dataplatform.member.entity.vo.datanodes;

import com.liangjian.dataplatform.member.constant.MetaCoreConstant;
import com.liangjian.dataplatform.member.entity.po.primary.MetaCore;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @Author: 黄子奇
 * @Date: 2019/8/26 16:51
 */
@Component
public class MetaCorePackageTransfer implements DataNodeTransfer<MetaCorePackage> {
    @Override
    public boolean matchTypeKey(String key) {
        return key.equals(MetaCoreConstant.CORE_BASEPACKAGE);
    }

    @Override
    public DataNode transfer(MetaCore metaCore) {
        Integer packageType = 0;
        switch (StringUtils.isEmpty(metaCore.getNamespace()) ?
                metaCore.getBizDomain() : metaCore.getNamespace() ){
            case MetaCoreConstant.ROOT_TYPE_PDM: packageType = MetaCorePackage.TYPE_PDM; break;
            case MetaCoreConstant.ROOT_TYPE_ITF: packageType = MetaCorePackage.TYPE_ITF; break;
            case MetaCoreConstant.ROOT_TYPE_DB: packageType = MetaCorePackage.TYPE_DB; break;
            case MetaCoreConstant.ROOT_TYPE_HOST: packageType = MetaCorePackage.TYPE_HOST; break;
            default: packageType = MetaCorePackage.TYPE_REGULAR;
        }

        MetaCorePackage metaCorePackage = new MetaCorePackage(
                metaCore.getId(),
                metaCore.getPrtId(),
                metaCore.getName(),
                metaCore.getBizDomain(),
                metaCore.getMetaMdl(),
                true,
                metaCore.getCmt(),
                metaCore.getRemarks(),
                metaCore.getCrtDate(),
                metaCore.getLastUpdate(),
                metaCore.getCrtUser(),
                metaCore.getNamespace(),
                metaCore.getChName(),
                packageType
        );
        return metaCorePackage;
    }

    @Override
    public MetaCore reTransfer(MetaCore metaCore, MetaCorePackage node) {
        metaCore.setPrtId(node.getPrtId());
        metaCore.setName(node.getName());
        metaCore.setBizDomain(node.getBizDomain());
        metaCore.setMetaMdl(node.getNodeType());
        metaCore.setCmt(node.getComment());
        metaCore.setLastUpdate(node.getLastUpdate());
        metaCore.setChName(node.getCnName());
        return metaCore;
    }
}
