#include "SettingConfig.h"

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

    PORT_NAMES = getProperty("com", "portNames").toString();
    BAUD_RATE = getProperty("com", "baudRate").toUInt();
    PARITY = getProperty("com", "parity").toInt();
    DEV_CODES = getProperty("com", "devCodes").toString();

    NEED_KAFKA = getProperty("kafka", "needKafka").toUInt();
    KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
    KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
    KAFKA_CMD_TOPIC = getProperty("kafka", "cmdTopic").toString();
    KAFKA_CMDCB_TOPIC = getProperty("kafka", "cmdcbTopic").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_MODE = getProperty("client", "workMode").toString();
    MASTER = getProperty("client", "master").toInt();
    SERVER_PORT = getProperty("client", "serverPort").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;
}
