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

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

// Notes IndexedDB Operations
#[wasm_bindgen(module = "/src/js/notes.js")]

extern "C" {
    // GETS
    // ================================================================================================

    #[wasm_bindgen(js_name = getInputNotes)]
    pub fn idxdb_get_input_notes(db_id: &str, states: Vec<u8>) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getInputNotesFromIds)]
    pub fn idxdb_get_input_notes_from_ids(db_id: &str, note_ids: Vec<String>) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getInputNotesFromNullifiers)]
    pub fn idxdb_get_input_notes_from_nullifiers(
        db_id: &str,
        nullifiers: Vec<String>,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getInputNotesFromDetailsCommitments)]
    pub fn idxdb_get_input_notes_from_details_commitments(
        db_id: &str,
        details_commitments: Vec<String>,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getOutputNotes)]
    pub fn idxdb_get_output_notes(db_id: &str, states: Vec<u8>) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getOutputNotesFromIds)]
    pub fn idxdb_get_output_notes_from_ids(db_id: &str, note_ids: Vec<String>) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getOutputNotesFromNullifiers)]
    pub fn idxdb_get_output_notes_from_nullifiers(
        db_id: &str,
        nullifiers: Vec<String>,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getOutputNotesFromDetailsCommitments)]
    pub fn idxdb_get_output_notes_from_details_commitments(
        db_id: &str,
        details_commitments: Vec<String>,
    ) -> js_sys::Promise;

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

    #[wasm_bindgen(js_name = getNoteScript)]
    pub fn idxdb_get_note_script(db_id: &str, script_root: String) -> js_sys::Promise;

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

    #[wasm_bindgen(js_name = upsertInputNote)]
    pub fn idxdb_upsert_input_note(
        db_id: &str,
        details_commitment: String,
        note_id: Option<String>,
        assets: Vec<u8>,
        attachments: Vec<u8>,
        serial_number: Vec<u8>,
        inputs: Vec<u8>,
        note_script_root: String,
        serialized_note_script: Vec<u8>,
        nullifier: Option<String>,
        serialized_created_at: String,
        state_discriminant: u8,
        state: Vec<u8>,
        consumed_block_height: Option<u32>,
        consumed_tx_order: Option<u32>,
        consumer_account_id: Option<String>,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = getInputNoteByOffset)]
    pub fn idxdb_get_input_note_by_offset(
        db_id: &str,
        states: Vec<u8>,
        consumer_account_id: String,
        block_start: Option<u32>,
        block_end: Option<u32>,
        offset: u32,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = upsertOutputNote)]
    pub fn idxdb_upsert_output_note(
        db_id: &str,
        details_commitment: String,
        note_id: String,
        assets: Vec<u8>,
        attachments: Vec<u8>,
        recipient_digest: String,
        metadata: Vec<u8>,
        nullifier: Option<String>,
        expected_height: u32,
        state_discriminant: u8,
        state: Vec<u8>,
    ) -> js_sys::Promise;

    #[wasm_bindgen(js_name = upsertNoteScript)]
    pub fn idxdb_upsert_note_script(
        db_id: &str,
        note_script_root: String,
        serialized_note_script: Vec<u8>,
    ) -> js_sys::Promise;
}
