package com.docus.server.report.config;

import cn.hutool.core.collection.CollUtil;
import com.docus.core.util.Func;
import com.docus.server.report.util.TableJsonRead;
import lombok.Data;

import java.util.List;

/**
 * 文件分段配置
 * @author WYBDEV
 */
@Data
public class SystemAssortConfig {

    private String key;
    private String desc;
    private Assort assort;

    private final static TableJsonRead JSON_READ = new TableJsonRead();

    public static SystemAssortConfig getSystemAssortConfig(String collectorId) {
        List<SystemAssortConfig> configs = getSystemAssortConfig();
        if (CollUtil.isNotEmpty(configs)) {
            for (SystemAssortConfig config : configs) {
                if (collectorId.equals(config.getKey())) {
                    return config;
                }
            }
        }
        return null;
    }

    public synchronized static List<SystemAssortConfig> getSystemAssortConfig() {
        String configJson = JSON_READ.ReadContent("data-config", "system-assort-config.json");
        return Func.parseJsonArray(configJson, SystemAssortConfig.class);
    }

    @Data
    public static class Assort {
        private String defaultAssortId;
        private List<AssortObj> other;
    }

    @Data
    public static class AssortObj {
        private String title;
        private String assortId;
    }

    public static void main(String[] args) {
        System.out.println(getSystemAssortConfig());
    }
}
