/*
 * Copyright 2024 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UPMCUSTOMHARDWARECONFIG_H
#define UPMCUSTOMHARDWARECONFIG_H

#include <QObject>
#include <QSettings>

#define UPM_NO_THIS_KEY    QStringLiteral("no-this-key")

#define UPM_HARDWARE_INFO_FILE                QStringLiteral("/sys/class/dmi/id/modalias")
#define UPM_CPU_INFO_FILE                     QStringLiteral("/proc/cpuinfo")
#define UPM_GLOBAL_HARDWARE_CONFIG_FILE       QStringLiteral("/usr/share/ukui/ukui-power-manager/upm-hardware-global.conf")
#define UPM_EXTEND_HARDWARE_CONFIG_PATH       QStringLiteral("/usr/share/ukui/ukui-power-manager/upm-hardware-extend.d/")

#define UPM_GROUP_EXTEND_BRAND_GENERIC_CONFIG   QStringLiteral("Brand-generic-config")
#define UPM_KEY_FIRST_RUN_DONOT_SUSPEND         QStringLiteral("firstRunDonotSuspend")

#define UPM_KEY_BOARD_NAME                    QStringLiteral("boardName")

#define UPM_GROUP_THIS_PRODUCT                QStringLiteral("this_product")
#define UPM_KEY_FIRST_RUN                     QStringLiteral("firstRun")
#define UPM_KEY_EXTEND_CONFIG_PATH            QStringLiteral("extendConfigPath")
#define UPM_KEY_DEVICE_IDENTIFICATION         QStringLiteral("deviceIdentification")

#define UPM_GROUP_IGNORE_BRIGHTNESS_NODE      QStringLiteral("ignore-brightness-node")

#define UPM_KEY_EXTEND_BRIGHTNESS_NODE                    QStringLiteral("brightnessNode")
#define UPM_KEY_EXTEND_PERFORMANCE_IDEL_RESERVE_CPU0      QStringLiteral("performanceIdleReserveCpu0")
#define UPM_KEY_EXTEND_BALANCE_IDEL_RESERVE_CPU0          QStringLiteral("balanceIdleReserveCpu0")
#define UPM_KEY_EXTEND_POWERSAVE_IDEL_RESERVE_CPU0        QStringLiteral("powersaveIdleReserveCpu0")
#define UPM_KEY_EXTEND_BALANCE_MODE_REDUCE_FREQUENCY      QStringLiteral("balanceModeReduceFrequency")
#define UPM_KEY_EXTEND_BALANCE_MODE_MAX_FREQUENCY         QStringLiteral("balanceModeMaxFrequency")
#define UPM_KEY_EXTEND_PERFORMANCE_AUTO_SWITCH_CPU_CORE   QStringLiteral("performanceAutoSwitchCpuCore")
#define UPM_KEY_EXTEND_BALANCE_AUTO_SWITCH_CPU_CORE       QStringLiteral("balanceAutoSwitchCpuCore")
#define UPM_KEY_EXTEND_POWERSAVE_AUTO_SWITCH_CPU_CORE     QStringLiteral("powersaveAutoSwitchCpuCore")
#define UPM_KEY_EXTEND_BUS_DEVICE_AUTO_SUSPEND            QStringLiteral("busDeviceAutoSuspend")
#define UPM_KEY_EXTEND_GPU_FREQUENCY_STATE                QStringLiteral("gpuFrequencyState")
#define UPM_KEY_EXTEND_GPU_FREQUENCY_LEVEL                QStringLiteral("gpuFrequencyLevel")
#define UPM_KEY_EXTEND_INTEL_AUDIO_MODE                   QStringLiteral("intelAudioMode")

class UpmCustomHardwareConfig : public QObject
{
    Q_OBJECT
public:
    explicit UpmCustomHardwareConfig(QObject *parent = nullptr);
    ~UpmCustomHardwareConfig();
    static UpmCustomHardwareConfig *self();

    bool isPanguM900();
    bool isHygonCpu();
    bool isZhaoxinCpu();
    bool isD3000M();
    bool brightnessNodeEffective();
    QString getBrightnessNode();
    bool firstRunDonotSuspend();
    bool getExtendConfig(const QString &configKey, QString &config);

private:
    QString m_hardwareInfo = "";
    QString m_cpuType = "";
    QSettings *m_globalConfig = nullptr;
    QSettings *m_extendConfig = nullptr;
    QString m_productGroup = "";
    QString m_extendConfigPath = "";

    void getHardwareInfo();
    void getCpuType();

    bool readConfig(QSettings *settings, const QString &group,
                    const QString &key, QVariant &value);
    bool getExtendConfigFile(QString &configFilePath);
    bool readAll(const QString &filePath, QString &content);
signals:

};

#endif // UPMCUSTOMDEFAULTHARDWARECONFIG_H
