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

#ifndef TEST_MODEL_CONFIG_H
#define TEST_MODEL_CONFIG_H

// kysdk-ai model config
#include <kylin-ai/private/aiconfig/modelconfig.h>

enum class ModelName { UNKNOWN = -1, BAIDU, XUNFEI };

inline void setBaiduAuthentication() {
    kyai::config::model::ModelConfig modelConfig;
    std::vector<kyai::config::model::MultiAuthentication> multiAuthentication;
    multiAuthentication.push_back(
        {"",
         {{"", "appId", ""},
          {"", "apiKey", ""},
          {"", "secretKey", ""}}});

    modelConfig.setModelAuthentications("百度-语音大模型", multiAuthentication);
}

inline void setXunfeiAuthentication() {
    kyai::config::model::ModelConfig modelConfig;
    std::vector<kyai::config::model::MultiAuthentication> multiAuthentication;
    multiAuthentication.push_back(
        {"",
         {{"", "appIdContinuous", ""},
          {"", "apiKeyContinuous", ""},
          {"", "secretKeyContinuous", ""}}});
    multiAuthentication.push_back(
        {"",
         {
             {"", "appIdRealTime", ""},
             {"", "apiKeyRealTime", ""},
         }});

    modelConfig.setModelAuthentications("讯飞-语音大模型", multiAuthentication);
}

inline void setAllAuthentications() {
    setBaiduAuthentication();
    setXunfeiAuthentication();
}

inline void setCurrentModel(ModelName type) {
    std::string modelName;
    switch (type) {
        case ModelName::BAIDU:
            modelName = "百度-语音大模型";
            break;
        case ModelName::XUNFEI:
            modelName = "讯飞-语音大模型";
            break;
        default:
            return;
    }
    kyai::config::model::ModelConfig modelConfig;
    modelConfig.setCurrentModelName(
        kyai::config::model::AiCapability::Speech,
        kyai::config::model::DeployType::PublicCloud, modelName);
}

inline std::string getCurrentModelName() {
    kyai::config::model::ModelConfig modelConfig;
    return modelConfig.getCurrentModelName(
        kyai::config::model::AiCapability::Speech,
        kyai::config::model::DeployType::PublicCloud);
}

inline ModelName getCurrentModel() {
    std::string modelName = getCurrentModelName();
    if (modelName == "百度-语音大模型") {
        return ModelName::BAIDU;
    } else if (modelName == "讯飞-语音大模型") {
        return ModelName::XUNFEI;
    } else {
        return ModelName::UNKNOWN;
    }
}

inline bool clearBaiduAuthentication() {
    kyai::config::model::ModelConfig modelConfig;
    return modelConfig.clearModelAuthentications("百度-语音大模型");
}

inline bool clearXunfeiAuthentication() {
    kyai::config::model::ModelConfig modelConfig;
    return modelConfig.clearModelAuthentications("讯飞-语音大模型");
}

inline void clearAllAuthentications() {
    clearBaiduAuthentication();
    clearXunfeiAuthentication();
}

#endif  // TEST_MODEL_CONFIG_H
