/**
 *
 * Agora Real Time Engagement
 * Created by Wei Hu in 2022-09.
 * Copyright (c) 2022 Agora IO. All rights reserved.
 *
 */
#pragma once

#include "rte_config.h"

#include <node_api.h>

#include "lib/shared_ptr.h"
#include "lib/signature.h"
#include "rte_runtime/binding/nodejs/src/common/tsfn.h"
#include "rte_runtime/sanitizer/thread_check.h"
#include "schema/value.h"

#define RTE_NODEJS_JS_REF_SIGNATURE 0x77AFD42D1EC5B8C3U

typedef struct rte_nodejs_js_ref_t {
  rte_signature_t signature;

  napi_ref js_ref;

  // Important! All operations related to this js_ref_bridge would all occurred
  // in the JS main thread, so we keep the napi_env for later use.
  napi_env env;

  rte_sanitizer_thread_check_t thread_check;
} rte_nodejs_js_ref_t;

AGORA_RTE_PRIVATE_API rte_value_t* rte_nodejs_js_ref_create(
    napi_env env, napi_value js_value);
