#ifndef VISION_H
#define VISION_H

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

#include <map>

#include "utils/logger.h"

typedef enum {
    OCR_IMAGE_FILE_ERROR = 100,
    OCR_PARAM_INVALID,
} OcrErrorCode;

namespace visionEngineError {
inline std::map<int, int> OcrErrorCodeMap{
    {-1, AiSdkCommonErrorCode::AISDK_NO_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::NomoreMemory, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::FileNotFound, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::VersionMismatched, AiSdkCommonErrorCode::AISDK_SERVICE_ERROR},

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

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

    {(int)ai_engine::VisionEngineErrorCode::Unauthorized, AiSdkCommonErrorCode::AISDK_AUTHENTICATION_FAILURE},
    {(int)ai_engine::VisionEngineErrorCode::TooLittleParams, OcrErrorCode::OCR_PARAM_INVALID},
    {(int)ai_engine::VisionEngineErrorCode::TooManyParams, OcrErrorCode::OCR_PARAM_INVALID},

    {(int)ai_engine::VisionEngineErrorCode::InvalidParamType, OcrErrorCode::OCR_IMAGE_FILE_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::TooLittleData, OcrErrorCode::OCR_IMAGE_FILE_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::TooManyData, OcrErrorCode::OCR_IMAGE_FILE_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::ImageFileReadError, OcrErrorCode::OCR_IMAGE_FILE_ERROR},
    {(int)ai_engine::VisionEngineErrorCode::OcrModelError, AiSdkCommonErrorCode::AISDK_MODEL_RUN_FAILED},
    {(int)ai_engine::VisionEngineErrorCode::ModelEarlyLoaded, AiSdkCommonErrorCode::AISDK_MODEL_RUN_FAILED},
    {(int)ai_engine::VisionEngineErrorCode::OcrTimeout, AiSdkCommonErrorCode::AISDK_MODEL_RUN_TIME_OUT},

    {(int)ai_engine::VisionEngineErrorCode::TooFrequentRequest, AiSdkCommonErrorCode::AISDK_TOO_MANY_REQUESTS},
    {(int)ai_engine::VisionEngineErrorCode::TooManyRequest, AiSdkCommonErrorCode::AISDK_TOO_MANY_REQUESTS}

};

static int getCoreVisionErrorCode(int engineErrorCode) {
    if (visionEngineError::OcrErrorCodeMap.find(engineErrorCode) != visionEngineError::OcrErrorCodeMap.end()) {
        return visionEngineError::OcrErrorCodeMap.at(engineErrorCode);
    } else {
        //        LOGE("Vision engine error code is not exists!");
        return AiSdkCommonErrorCode::AISDK_NO_ERROR;
    }
}
};  // namespace visionEngineError

#endif