package org.security.trans.settings.wrapper;

import org.security.trans.settings.entity.DeviceCategorySettings;
import org.security.trans.settings.vo.DeviceCategorySettingsVO;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.utils.BeanUtil;

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


public class DCWrapper extends BaseEntityWrapper<DeviceCategorySettings, DeviceCategorySettingsVO>{

	public static DCWrapper build() {
		return new DCWrapper();
	}
	@Override
	public DeviceCategorySettingsVO entityVO(DeviceCategorySettings deviceCategorySettings) {
		DeviceCategorySettingsVO deviceCategorySettingsVO = Objects.requireNonNull(BeanUtil.copy(deviceCategorySettings, DeviceCategorySettingsVO.class));
		if (deviceCategorySettings.getParentId() == null || deviceCategorySettings.getParentId().longValue() == 0) {
			deviceCategorySettingsVO.setParentName(BladeConstant.TOP_PARENT_NAME);
		} else {
//			查询parentName
//			IDeviceCategorySettingsService settingsService;
//			String pName = settingsService.getById(deviceCategorySettings.getParentId()).getName();
			deviceCategorySettingsVO.setParentName("pName");

		}
		return deviceCategorySettingsVO;
	}
	public List<DeviceCategorySettingsVO> listNodeVO(List<DeviceCategorySettings> list) {
		List<DeviceCategorySettingsVO> collect = list.stream().map(deviceCategorySettings -> BeanUtil.copy(deviceCategorySettings, DeviceCategorySettingsVO.class)).collect(Collectors.toList());
		return ForestNodeMerger.merge(collect);
	}
	public List<DeviceCategorySettingsVO> listNodeLazyVO(List<DeviceCategorySettingsVO> list) {
		return ForestNodeMerger.merge(list);
	}

}
