package com.config;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.springframework.context.annotation.Bean;

import java.io.File;

public class AppConfig {
    private static final Config config;

    static {
        // 加载配置文件
        File configFile = new File("application.properties");
        if (configFile.exists()) {
            config = ConfigFactory.parseFile(configFile);
        } else {
            config = ConfigFactory.load("application.properties");
        }
    }
    // Syslog 配置
    public static int getSyslogTcpPort() {
        return config.getInt("syslog.tcp.port");
    }

    public static int getSyslogUdpPort() {
        return config.getInt("syslog.udp.port");
    }

    public static int getSyslogMaxFrameLength() {
        return config.getInt("syslog.max.frame.length");
    }

    public static int getSyslogBufferSize() {
        return config.getInt("syslog.buffer.size");
    }

    // InfluxDB 配置
    public static String getInfluxUrl() {
        return config.getString("influxdb.url");
    }

    public static String getInfluxToken() {
        return config.getString("influxdb.token");
    }

    public static String getInfluxOrg() {
        return config.getString("influxdb.org");
    }

    public static String getInfluxBucket() {
        return config.getString("influxdb.bucket");
    }

    public static int getInfluxBatchSize() {
        return config.getInt("influxdb.batch.size");
    }

    public static int getInfluxFlushInterval() {
        return config.getInt("influxdb.flush.interval");
    }

    public static int getInfluxRetryAttempts() {
        return config.getInt("influxdb.retry.attempts");
    }

    public static int getInfluxRetryDelay() {
        return config.getInt("influxdb.retry.delay");
    }

    // 应用配置
    public static int getWorkerThreads() {
        return config.getInt("app.worker.threads");
    }

    public static int getMaxQueueSize() {
        return config.getInt("app.max.queue.size");
    }

    public static boolean isMetricsEnabled() {   return config.getBoolean("app.metrics.enabled");   }

    //kafka consumer应用配置

    public static String getBootstrapServers() {
        return config.getString("spring.kafka.consumer.bootstrap-servers");
    }

    public static String getGroupId() {
        return config.getString("spring.kafka.consumer.group-id");
    }

    public static String getAutoOffsetReset() {
        return config.getString("spring.kafka.consumer.auto-offset-reset");
    }

    public static boolean getEnableAutoCommit() { return config.getBoolean("spring.kafka.consumer.enable-auto-commit");     }

    public static String getAutoCommitIntervalMS() {      return config.getString("spring.kafka.consumer.auto-commit-interval");}

    public static String getTopic() {  return config.getString("spring.kafka.consumer.topic"); }

    public static String geRunEnvironment‌() {  return config.getString("server.run.environment"); }

    public static String  getSM4Key() {
        return config.getString("syslog.sm4.generateKey");
    }
}
