//
// Created by Allen on 24/08/28.
//

#ifndef REACT_NATIVE_DCV_ANDROID_SRC_MAIN_CPP_CVR_JSICVR_H_
#define REACT_NATIVE_DCV_ANDROID_SRC_MAIN_CPP_CVR_JSICVR_H_

#include "jsi/jsi.h"
#include "string"
#include "ImgHO.h"
#include "JsiDbr.h"
#include "JsiDlr.h"
#include "JsiDdn.h"
#include "JsiDcp.h"
#include "jni.h"

using namespace facebook::jsi;
using namespace std;

int CRIT_BARCODE = 1 << 1;
int CRIT_TEXT_LINE = 1 << 2;
int CRIT_DETECTED_QUAD = 1 << 3;
int CRIT_DESKEWED_IMAGE = 1 << 4;
int CRIT_PARSED_RESULT = 1 << 5;
int CRIT_ENHANCED_IMAGE = 1 << 6;

#define SET_STRING_PROPERTY_BY_FIELD(jClass, jObj, jsObj, propertyName) \
jfieldID propertyName =env->GetFieldID(jClass, #propertyName, "Ljava/lang/String;"); \
jstring j##propertyName = (jstring) env->GetObjectField(jObj, propertyName);            \
const char* p##propertyName = j##propertyName?env->GetStringUTFChars(j##propertyName, nullptr):""; \
jsObj.setProperty(rt, #propertyName, std::move(p##propertyName));                     \
if(j##propertyName) env->ReleaseStringUTFChars(j##propertyName, p##propertyName);    \

namespace jsiConversion::cvr {
void jCapturedResultToJsiObject(Runtime &rt, JNIEnv *env, jobject jCapturedResult, Object &jsCapturedResult);
}//namespace jsiConversion::cvr

namespace jsi_install::cvr {
    void install_captureImageData(Runtime &jsiRuntime);
    void install_getCurrentDeskewedImages(Runtime &jsiRuntime);
    void install_getCurrentEnhancedImages(Runtime &jsiRuntime);
    void install_captureFile(Runtime &jsiRuntime);
    void install_captureFileBytes(Runtime &jsiRuntime);
    void install_cvr_getOriginalImage(Runtime &jsiRuntime);
}//namespace jsi_install::cvr

Object captureImageDataHO(ImageDataHostObject &imageDataHO, Runtime &rt, string templateName);
Object captureFile(string filePath, Runtime &rt, string templateName);
Object captureFileBytes(ArrayBuffer &fileBytes, Runtime &rt, string templateName);
Array getCurrentDeskewedImages(Runtime &runtime);
Array getCurrentEnhancedImages(Runtime &runtime);
ImageDataHostObject getOriginalImage(Runtime &runtime, string imageHashId);

#endif //REACT_NATIVE_DCV_ANDROID_SRC_MAIN_CPP_CVR_JSICVR_H_
