#include "SettingConfig.h"

SettingConfig::SettingConfig()
{
    filename = QApplication::applicationDirPath() + "/conf/config.ini";
    setting = new QSettings(this->filename, QSettings::IniFormat);

    BAUD_RATE = getProperty("com", "baudRate").toInt();

    NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
    KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
    KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
    KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
    NEED_SASL = getProperty("kafka", "needSasl").toInt();
    SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
    SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();

    CLIENT_ID = getProperty("client", "clientId").toString();
    APP_KEY = getProperty("client", "appKey").toString();
    DEV_TYPES = getProperty("client", "devTypes").toString();
    SYSTEM = getProperty("client", "system").toString();
    WORK_TYPE = getProperty("client", "workMode").toString();
    MASTER = getProperty("client", "master").toInt();
    SERVER_PORT = getProperty("client", "serverPort").toInt();
    AUTO_STOP_TIME = getProperty("client", "autoStopTime").toInt();
    AUTO_START_TIME = getProperty("client", "autoStartTime").toInt();

    BASE_URL = getProperty("http", "baseUrl").toString();

    BASE_LOG_PATH = getProperty("log", "basePath").toString();
}


QVariant SettingConfig::getProperty(QString nodeName, QString keyName) {
    QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName));
    return var;
}
