package cn.superdesk.uniorder.dto.utils;

import cn.superdesk.uniorder.dto.vo.sys.role.ViewMenuTree;
import cn.superdesk.uniorder.dto.vo.marketing.department.UnifiedAreaTJ;
import cn.superdesk.uniorder.dto.vo.marketing.department.UnifiedAreaWeb;

import java.util.ArrayList;
import java.util.List;

public class ConvertTreeUtils {

	public static UnifiedAreaTJ buildTree(List<UnifiedAreaTJ> list, UnifiedAreaTJ node) {

		List<UnifiedAreaTJ> children = new ArrayList<>();

		for (UnifiedAreaTJ item : list) {
			if (item.getParentId() != null && item.getParentId().equals(node.getId())) {
				children.add(buildTree(list, item));
			}
		}

		node.setChildrens(children);

		return node;

	}

	public static ViewMenuTree buildTreeMenu(List<ViewMenuTree> list, ViewMenuTree node) {

		List<ViewMenuTree> children = new ArrayList<>();

		for (ViewMenuTree item : list) {
			if (item.getPid() != null && item.getPid().equals(node.getId())) {
				children.add(buildTreeMenu(list, item));
			}
		}

		node.setChildList(children);

		return node;

	}

	public static UnifiedAreaWeb buildTreeArea(List<UnifiedAreaWeb> list, UnifiedAreaWeb node) {

		List<UnifiedAreaWeb> children = new ArrayList<>();

		for (UnifiedAreaWeb item : list) {
			if (item.getParentId() != null && item.getParentId().equals(node.getId())) {
				children.add(buildTreeArea(list, item));
			}
		}

		node.setChildren(children);

		return node;

	}
}
