package com.bsmlab.dfx.agent.config;

import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class AgentConfigDto {
    private String description;
    private String myHostId;
    private String myHostName;
    private int myListenPort;
    private boolean sslEnabled;
    private List<KnownAgent> knownAgentList;
    private StatusChecker statusChecker;
    private List<DataSourceConfig> dataSourceConfig;
    private List<String> sqlMapperLocations;
    private DropBoxConfig dropBoxConfig;
    private PostmanConfig postmanConfig;
    private LoggingConfig logging;


    // ============================ INNER CLASSES ============================
    @Data
    public static class KnownAgent {
        private String hostId;
        private String hostName;
        private int listenPort;
        private boolean sslEnabled;
        private List<String> dropBoxIdList;
        private List<String> routingHostIdList;
    }

    @Data
    public static class StatusChecker {
        private String cron;
        private String consoleHostName;
        private int consoleListenPort;
        private boolean consoleSslEnabled;
    }

    @Data
    public static class DataSourceConfig {
        private String dataSourceId;
        private String driverClassName;
        private String url;
        private String username;
        private String password;
        private int initialSize;
        private int minIdle;
        private int maxIdle;
        private int maxTotal;
        private int maximumRowForTransaction;
    }

    @Data
    public static class DropBoxConfig {
        private String sentMessageStorageRoot;
        private String receivedMessageStorageRoot;
        private String processedMessageStorageRoot;
        private String failureMessageStorageRoot;
        private String manualMessageStorageRoot;
        private List<DropBox> dropBoxList;
        private int threadPoolSize;
        private int retentionDaysOfProcessedMessage;
    }

    @Data
    public static class DropBox {
        private String dropBoxId;
        private TaskType taskType;
        private String dataSourceId;
        private String sqlId;
        private String saveDirectoryRoot;
        private String description;
    }

    @Data
    public static class PostmanConfig {
        private int threadPoolSize;
        private List<Postman> postmanList;
    }

    @Data
    public static class Postman {
        private String postmanId;
        private TaskType taskType;
        private PostmanAction action;
        private PostmanMessage message;
        private String recipientHostId;
        private String recipientDropBoxId;
        private String description;
    }

    @Data
    public static class PostmanAction {
        private ActionType type;
        private String command;
        private List<String> parametersKeyList;
        private String cron;
    }

    @Data
    public static class PostmanMessage {
        private MessageType messageType;
        private String dataSourceId;
        private String sqlId;
        private String watchDirectory;
        private String metaDataDataSourceId;
        private String metaDataSqlId;
        private String metaDropBoxId;
        private String postProcessingSqlId;
    }

    public static enum ActionType {
        TRIGGER,
        SCHEDULED
    }

    public static enum MessageType {
        TRANSFER_DB_TO_DB,
        TRANSFER_FILE;
    }

    public static enum TaskType {
        DB_READ_THEN_SEND,
        FILE_READ_THEN_SEND,
        RECEIVE_DB_TO_DB_SAVE,
        RECEIVE_FILE
    }

    @Data
    public static class LoggingConfig {
        private String logDirectory;
        private String logFileName;
        private String logName;
        private int maxHistory;
        private String logPattern;
        private String rootLogLevel;
        private List<Map<String, String>> packages;
    }
}
