package com.docus.server.message.config;

import com.docus.core.util.Func;
import com.docus.server.message.util.TableJsonRead;
import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * @author wyb
 */
public class CollectTaskConfig {
    private final static String CONFIG_FILE_PATH = "data-config";
    private final static String CONFIG_FILE_NAME = "collect-task-config.json";

    public static TaskConfig getTaskConfig(String method) {
        Objects.requireNonNull(method);
        TableJsonRead jsonReader = new TableJsonRead();
        String taskConfigJson = jsonReader.ReadContent(CONFIG_FILE_PATH, CONFIG_FILE_NAME);
        System.out.println(taskConfigJson);
        if (taskConfigJson == null) {
            return null;
        }
        List<TaskConfig> taskConfigList = Func.parseJsonArray(taskConfigJson, TaskConfig.class);
        if (Func.isEmpty(taskConfigList)) {
            return null;
        }
        for (TaskConfig taskConfig : taskConfigList) {
            if (method.equals(taskConfig.getMethod())) {
                return taskConfig;
            }
        }
        return null;
    }

    @Data
    public static class TaskConfig {
        private String method;
        private List<String> collectorIds;
        private int delaySeconds;
        private List<String> babyCollectorIds;
        private String haveBabyQuery;
    }

    public static void main(String[] args) {
        TaskConfig taskConfig = getTaskConfig("");
    }
}
