/*
 * Copyright 2025 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 <https://www.gnu.org/licenses/>.
 */

#ifndef MODELORDERMANAGER_H
#define MODELORDERMANAGER_H

#include <QObject>
#include <QMap>
#include <aiconfig/modelconfig.h>
#include <QSettings>

class ModelOrderManager : public QObject
{
    Q_OBJECT
public:
    explicit ModelOrderManager(QObject *parent = nullptr);
    ~ModelOrderManager();

    void addModel(kyai::config::model::AiCapability aiCapability, const QString& modelName);
    void deleteModel(kyai::config::model::AiCapability aiCapability, const QString& modelName);

    QStringList getModelOrder(kyai::config::model::AiCapability aiCapability);

private:
    QString getModelTypeString(kyai::config::model::AiCapability aiCapability);

    void checkConfigFile();
    void initSettings();
    void getModelOrderFormConfigFile();
    void createDefaultConfig();
    void saveModelOrder(kyai::config::model::AiCapability aiCapability, const QStringList& order);

signals:

private:
    QSettings* m_settings;
    QMap<QString, QStringList> m_modelOrders;

    const std::string m_configDir =
        std::string(getenv("HOME")) + "/.config/kylin-ai-subsystem-modelconfig";
    const std::string m_configFile =
        std::string(getenv("HOME")) + "/.config/kylin-ai-subsystem-modelconfig/modelOrder.conf";
};

#endif // MODELORDERMANAGER_H
