"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashTransaction = exports.ZcashTransaction = exports.Transaction = void 0;
const wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
const transactionBase_js_1 = require("./transactionBase.js");
/**
 * Transaction wrapper (Bitcoin-like networks)
 *
 * Provides a camelCase, strongly-typed API over the snake_case WASM bindings.
 */
class Transaction extends transactionBase_js_1.TransactionBase {
    constructor(wasm) {
        super(wasm);
    }
    /**
     * Check if a coin is supported by this transaction class.
     * Bitcoin-like transactions support all coins except Zcash and Dash.
     */
    static supportsCoin(coin) {
        return !ZcashTransaction.supportsCoin(coin) && !DashTransaction.supportsCoin(coin);
    }
    /**
     * Create an empty transaction (version 1, locktime 0)
     */
    static create() {
        return new Transaction(wasm_utxo_js_1.WasmTransaction.create());
    }
    static fromBytes(bytes, coin) {
        if (coin !== undefined) {
            if (ZcashTransaction.supportsCoin(coin))
                return ZcashTransaction.fromBytes(bytes);
            if (DashTransaction.supportsCoin(coin))
                return DashTransaction.fromBytes(bytes);
        }
        return new Transaction(wasm_utxo_js_1.WasmTransaction.from_bytes(bytes));
    }
    /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
    static fromWasm(wasm) {
        return new Transaction(wasm);
    }
    /**
     * Add an input to the transaction
     * @param txid - Previous transaction ID (hex string)
     * @param vout - Output index being spent
     * @param sequence - Optional sequence number (default: 0xFFFFFFFF)
     * @returns The index of the newly added input
     */
    addInputAtIndex(index, txid, vout, sequence) {
        return this._wasm.add_input_at_index(index, txid, vout, sequence);
    }
    addInput(txid, vout, sequence) {
        return this._wasm.add_input(txid, vout, sequence);
    }
    addOutputAtIndex(index, script, value) {
        return this._wasm.add_output_at_index(index, script, value);
    }
    addOutput(script, value) {
        return this._wasm.add_output(script, value);
    }
    /**
     * Get the virtual size of the transaction
     *
     * Virtual size accounts for the segwit discount on witness data.
     *
     * @returns The virtual size in virtual bytes (vbytes)
     */
    getVSize() {
        return this._wasm.get_vsize();
    }
    /** @internal */
    get wasm() {
        return this._wasm;
    }
}
exports.Transaction = Transaction;
/**
 * Zcash Transaction wrapper
 *
 * Provides a camelCase, strongly-typed API over the snake_case WASM bindings.
 */
class ZcashTransaction extends transactionBase_js_1.TransactionBase {
    constructor(wasm) {
        super(wasm);
    }
    /**
     * Check if a coin is supported by this transaction class.
     * Zcash transactions support Zcash mainnet and testnet.
     */
    static supportsCoin(coin) {
        return coin === "zec" || coin === "tzec";
    }
    static fromBytes(bytes) {
        return new ZcashTransaction(wasm_utxo_js_1.WasmZcashTransaction.from_bytes(bytes));
    }
    /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
    static fromWasm(wasm) {
        return new ZcashTransaction(wasm);
    }
    /** @internal */
    get wasm() {
        return this._wasm;
    }
}
exports.ZcashTransaction = ZcashTransaction;
/**
 * Dash Transaction wrapper (supports EVO special transactions)
 *
 * Round-trip only: bytes -> parse -> bytes.
 */
class DashTransaction extends transactionBase_js_1.TransactionBase {
    constructor(wasm) {
        super(wasm);
    }
    /**
     * Check if a coin is supported by this transaction class.
     * Dash transactions support Dash mainnet and testnet.
     */
    static supportsCoin(coin) {
        return coin === "dash" || coin === "tdash";
    }
    static fromBytes(bytes) {
        return new DashTransaction(wasm_utxo_js_1.WasmDashTransaction.from_bytes(bytes));
    }
    /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
    static fromWasm(wasm) {
        return new DashTransaction(wasm);
    }
    /** @internal */
    get wasm() {
        return this._wasm;
    }
}
exports.DashTransaction = DashTransaction;
