#include "SettingConfig.h"

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

    init();
}


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

void SettingConfig::setProperty(QString nodeName, QString keyName, QString value) {
    this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName), value);
}

void SettingConfig::init() {
    BAUD_RATE = getProperty("com", "baudRate").toInt();

    WINDOW_WIDTH = getProperty("window", "width").toInt();
    WINDOW_HEIGHT = getProperty("window", "height").toInt();

    NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
    KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
    KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
    KAFKA_MSG_TOPIC = getProperty("kafka", "msgTopic").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();
    DISPLAY_COUNT = getProperty("client", "displayCount", "4").toInt();
    SERVER_PORT = getProperty("client", "serverPort").toInt();
    RESIDUAL_CALC_SEC = getProperty("client", "residualCalcSec").toInt();

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

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