/**
 *
 * Agora Real Time Engagement
 * Created by Wei Hu in 2021-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/metadata/metadata.h"
#include "rte_runtime/sanitizer/thread_check.h"

#define RTE_NODEJS_METADATA_INFO_SIGNATURE 0x4799357888A06FDFU

typedef struct rte_nodejs_metadata_info_t {
  rte_signature_t signature;

  // Used to determine the timing of destroying this metadata_info bridge.
  rte_sharedptr_t* shared_ptr;

  // Point to the corresponding C metadata_info.
  rte_metadata_info_t* c_metadata_info;

  // Point to the corresponding JS metadata_info.
  napi_ref js_ref;

  rte_sanitizer_thread_check_t thread_check;
} rte_nodejs_metadata_info_t;

AGORA_RTE_API napi_value rte_nodejs_metadata_module_init(napi_env env,
                                                         napi_value exports);

AGORA_RTE_API napi_value
rte_nodejs_metadata_info_wrap(napi_env env, rte_metadata_info_t* metadata);

AGORA_RTE_API void rte_nodejs_metadata_info_invalidate_js(
    napi_env env, napi_value js_metadata);
