package org.springblade.flow.visual.onlinedev.common.dynamic;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import cn.hutool.core.collection.CollUtil;

/**
 * 每个表的数据，key是表，value是多行数据
 * 
 * @author William
 * @date 2022年9月26日 上午10:54:24
 */
public class TableData extends LinkedHashMap<String, List<TableRowData>> {
	private static final long serialVersionUID = 1L;

	public TableData() {
	}

	public void add(String table, List<TableRowData> rowList) {
		this.put(table, rowList);
	}

	public void add(String table, TableRowData row) {
		List<TableRowData> rowList = null;
		if (containsKey(table)) {
			rowList = get(table);
		}
		if (rowList == null) {
			rowList = new ArrayList<>();
		}

		rowList.add(row);
		this.put(table, rowList);
	}

	public Set<String> getTableList() {
		return this.keySet();
	}

	public List<TableRowData> getRowList(String table) {
		return get(table);
	}

	public int getTableSize() {
		return this.size();
	}

	public int getDataSize() {
		List<String> tableSet = new ArrayList<>(keySet());
		List<TableRowData> rowList = CollUtil.isNotEmpty(tableSet) ? getRowList(tableSet.get(0)) : null;
		return CollUtil.isNotEmpty(rowList) ? rowList.size() : 0;
	}
}
