#include "config.h"

//

#include "_chatmodelconfig.h"
#include "jsoncpp/json/json.h"

ChatModelConfig *chat_model_config_create() { return new _ChatModelConfig(); }

void chat_model_config_destroy(ChatModelConfig **config) {
    if (config == nullptr) {
        return;
    }
    delete *config;
    *config = nullptr;
}

void chat_model_config_set_name(ChatModelConfig *config, const char *name) {
    if (config == nullptr) {
        return;
    }
    config->name_ = name;
}
void chat_model_config_set_top_k(ChatModelConfig *config, int top_k) {
    if (config == nullptr) {
        return;
    }
    config->topK_ = top_k;
}
void chat_model_config_set_deploy_type(ChatModelConfig *config,
                                       ModelDeployType type) {
    if (config == nullptr) {
        return;
    }
    config->type_ = type;
}
std::string modelConfigToJson(const ChatModelConfig &modelconfig) {
    Json::Value root;
    root["name"] = modelconfig.name_;
    switch (modelconfig.type_) {
        case ModelDeployType::OnDevice:
            root["type"] = "Local";
            break;
        case ModelDeployType::PrivateCloud:
            root["type"] = "PrivateCloud";
            break;
        case ModelDeployType::PublicCloud:
            root["type"] = "PublicCloud";
            break;
        default:
            root["type"] = "Default";
            break;
    }
    root["topK"] = modelconfig.topK_;
    Json::FastWriter writer;
    return writer.write(root);
}
