use alloc::string::String;
use alloc::vec::Vec;

use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::js_sys;

// ChainData IndexedDB Operations
#[wasm_bindgen(module = "/src/js/chainData.js")]
extern "C" {
    // GETS
    // ================================================================================================

    #[wasm_bindgen(js_name = getBlockHeaders)]
    pub fn idxdb_get_block_headers(db_id: &str, block_numbers: Vec<u32>) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getTrackedBlockHeaders)]
    pub fn idxdb_get_tracked_block_headers(db_id: &str) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getTrackedBlockHeaderNumbers)]
    pub fn idxdb_get_tracked_block_header_numbers(db_id: &str) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getPartialBlockchainNodesAll)]
    pub fn idxdb_get_partial_blockchain_nodes_all(db_id: &str) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getPartialBlockchainNodes)]
    pub fn idxdb_get_partial_blockchain_nodes(db_id: &str, ids: Vec<String>) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getPartialBlockchainNodesUpToInOrderIndex)]
    pub fn idxdb_get_partial_blockchain_nodes_up_to_inorder_index(
        db_id: &str,
        max_in_order_index: String,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getCurrentBlockchainPeaks)]
    pub fn idxdb_get_current_blockchain_peaks(db_id: &str) -> js_sys::Promise;

    // INSERTS
    // ================================================================================================

    #[wasm_bindgen(js_name = insertBlockHeader)]
    pub fn idxdb_insert_block_header(
        db_id: &str,
        block_num: u32,
        header: Vec<u8>,
        has_client_notes: bool,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = insertPartialBlockchainNodes)]
    pub fn idxdb_insert_partial_blockchain_nodes(
        db_id: &str,
        ids: Vec<String>,
        nodes: Vec<String>,
    ) -> js_sys::Promise;

    // DELETES
    // ================================================================================================

    #[wasm_bindgen(js_name = pruneIrrelevantBlocks)]
    pub fn idxdb_prune_irrelevant_blocks(
        db_id: &str,
        blocks_to_untrack: Vec<u32>,
        node_ids_to_remove: Vec<String>,
    ) -> js_sys::Promise;
}
