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

import com.yuchen.saas.device.api.vo.assets.SaasAssetsAddressTreeVO;
import com.yuchen.saas.device.api.vo.assets.SaasAssetsAddressVO;
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 SaasAssetsAddressTreeWrapper extends BaseEntityWrapper<SaasAssetsAddressVO, SaasAssetsAddressTreeVO> {

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

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

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

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

}
