package com.yuchen.saas.device.api.wrapper;

import com.yuchen.saas.device.api.vo.assets.SaasAssetsCategoryTreeVO;
import com.yuchen.saas.device.api.vo.assets.SaasAssetsCategoryVO;
import org.nest.springwrap.core.mp.support.BaseEntityWrapper;
import org.nest.springwrap.core.tool.constant.NestConstant;
import org.nest.springwrap.core.tool.node.ForestNodeMerger;
import org.nest.springwrap.core.tool.utils.BeanUtil;
import org.nest.springwrap.core.tool.utils.Func;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;


public class SaasAssetsCategoryTreeWrapper extends BaseEntityWrapper<SaasAssetsCategoryVO, SaasAssetsCategoryTreeVO> {

    public static SaasAssetsCategoryTreeWrapper build() {
        return new SaasAssetsCategoryTreeWrapper();
    }

    @Override
    public SaasAssetsCategoryTreeVO entityVO(SaasAssetsCategoryVO deviceInfo) {
        SaasAssetsCategoryTreeVO deviceTreeVO = Objects.requireNonNull(BeanUtil.copy(deviceInfo, SaasAssetsCategoryTreeVO.class));
        if (Func.equals(deviceInfo.getParentId(), NestConstant.TOP_PARENT_ID)) {
            deviceTreeVO.setParentName(NestConstant.TOP_PARENT_NAME);
        }
        return deviceTreeVO;
    }

    public List<SaasAssetsCategoryTreeVO> listNodeVO(List<SaasAssetsCategoryVO> list) {
        List<SaasAssetsCategoryTreeVO> collect = list.stream().map(deviceInfo -> BeanUtil.copy(deviceInfo, SaasAssetsCategoryTreeVO.class))
                .collect(Collectors.toList());
        return ForestNodeMerger.merge(collect);
    }

    public List<SaasAssetsCategoryTreeVO> listNodeLazyVO(List<SaasAssetsCategoryTreeVO> list) {
        return ForestNodeMerger.merge(list);
    }

}
