#ifndef VISION_H
#define VISION_H

#include <kylin-ai/aiengine.h>
#include <kylin-ai/common/error.h>

#include <map>

typedef enum {
    NLP_INPUT_INVALID = 100,
    NLP_PARAM_ERROR,
} GenAiTextErrorCode;

namespace gen_ai::nlp::error {
inline std::map<int, int> NlpErrorCodeMap{
    {-1, AiSdkCommonErrorCode::AISDK_NO_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::NomoreMemory, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::FileNotFound, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::VersionMismatched, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},

    {(int)ai_engine::NlpEngineErrorCode::FilePermissionDenied, AiSdkCommonErrorCode::AISDK_AUTHENTICATION_FAILURE},
    {(int)ai_engine::NlpEngineErrorCode::NetworkDisconnected, AiSdkCommonErrorCode::AISDK_NET_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::NetworkLatencyTooLong, AiSdkCommonErrorCode::AISDK_NET_ERROR},

    {(int)ai_engine::NlpEngineErrorCode::FailedToConnectServer, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::ServerNoResponse, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::NoServerService, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},

    {(int)ai_engine::NlpEngineErrorCode::Unauthorized, AiSdkCommonErrorCode::AISDK_AUTHENTICATION_FAILURE},
    {(int)ai_engine::NlpEngineErrorCode::TooLittleParams, GenAiTextErrorCode::NLP_PARAM_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::TooManyParams, GenAiTextErrorCode::NLP_PARAM_ERROR},

    {(int)ai_engine::NlpEngineErrorCode::InvalidWords, AiSdkCommonErrorCode::AISDK_NET_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::InvalidParamType, GenAiTextErrorCode::NLP_PARAM_ERROR},
    {(int)ai_engine::NlpEngineErrorCode::TooLittleData, GenAiTextErrorCode::NLP_INPUT_INVALID},
    {(int)ai_engine::NlpEngineErrorCode::TooManyData, GenAiTextErrorCode::NLP_INPUT_INVALID},

    {(int)ai_engine::NlpEngineErrorCode::TooFrequentRequest, AiSdkCommonErrorCode::AISDK_TOO_MANY_REQUESTS},
    {(int)ai_engine::NlpEngineErrorCode::TooManyRequest, AiSdkCommonErrorCode::AISDK_TOO_MANY_REQUESTS},
    {(int)ai_engine::NlpEngineErrorCode::SslCertificateError, AiSdkCommonErrorCode::AISDK_SSL_CERTIFICATE_ERROR},
};

static int getNlpErrorCode(int engineErrorCode) {
    if (gen_ai::nlp::error::NlpErrorCodeMap.find(engineErrorCode) != gen_ai::nlp::error::NlpErrorCodeMap.end()) {
        return gen_ai::nlp::error::NlpErrorCodeMap.at(engineErrorCode);
    } else {
        return AiSdkCommonErrorCode::AISDK_NO_ERROR;
    }
}
}  // namespace gen_ai::nlp::error

#endif