"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputSupplementationMode = void 0;
const Amount_1 = __importDefault(require("./Amount"));
const Utxo_1 = __importDefault(require("./Utxo"));
/**
 * Input supplementation modes for DLC operations
 */
var InputSupplementationMode;
(function (InputSupplementationMode) {
    InputSupplementationMode["None"] = "none";
    InputSupplementationMode["Optional"] = "optional";
    InputSupplementationMode["Required"] = "required";
})(InputSupplementationMode || (exports.InputSupplementationMode = InputSupplementationMode = {}));
/**
 * Class for interfacing with inputs/utxos in Liquality Chainify
 * https://github.com/liquality/chainify
 *
 * These inputs can have different fields for value
 * satoshis (sats): https://github.com/liquality/chainify/blob/dev/packages/bitcoin-esplora-api-provider/lib/BitcoinEsploraApiProvider.js#L65
 * amount (btc): https://github.com/liquality/chainify/blob/dev/packages/bitcoin-esplora-api-provider/lib/BitcoinEsploraApiProvider.js#L74
 * value (sats): https://github.com/liquality/chainify/blob/dev/packages/bitcoin-wallet-provider/lib/BitcoinWalletProvider.js#L331
 *
 * This will be fixed once typescript branch is merged:
 * https://github.com/liquality/chainify/tree/typescript
 * satoshis and amount will not be necessary, only value
 * https://github.com/liquality/chainify/blob/typescript/packages/types/lib/bitcoin.ts#L46
 *
 * Extended to support DLC inputs for splice transactions.
 */
class Input {
    constructor(txid, vout, address, amount, // in BTC
    value, // in sats
    derivationPath, maxWitnessLength, redeemScript, inputSerialId, scriptPubKey, label, confirmations, spendable, solvable, safe, dlcInput) {
        this.txid = txid;
        this.vout = vout;
        this.address = address;
        this.amount = amount;
        this.value = value;
        this.derivationPath = derivationPath;
        this.maxWitnessLength = maxWitnessLength;
        this.redeemScript = redeemScript;
        this.inputSerialId = inputSerialId;
        this.scriptPubKey = scriptPubKey;
        this.label = label;
        this.confirmations = confirmations;
        this.spendable = spendable;
        this.solvable = solvable;
        this.safe = safe;
        this.dlcInput = dlcInput;
    }
    toUtxo() {
        let amount;
        if (this.value) {
            amount = Amount_1.default.FromSatoshis(this.value);
        }
        else if (this.amount) {
            amount = Amount_1.default.FromBitcoin(this.amount);
        }
        else {
            amount = Amount_1.default.FromSatoshis(0);
        }
        return {
            txid: this.txid,
            vout: this.vout,
            amount,
            address: this.address,
            derivationPath: this.derivationPath,
            maxWitnessLength: this.maxWitnessLength ? this.maxWitnessLength : 108,
            inputSerialId: this.inputSerialId,
            toJSON: Utxo_1.default.prototype.toJSON,
            toInput: Utxo_1.default.prototype.toInput,
            toTxInputInfo: Utxo_1.default.prototype.toTxInputInfo,
        };
    }
    /**
     * Check if this input contains DLC information (for splice transactions)
     */
    isDlcInput() {
        return !!this.dlcInput;
    }
    static fromUTXO(utxo) {
        const amount = Amount_1.default.FromSatoshis(utxo.value);
        return new Input(utxo.txid, utxo.vout, utxo.address, amount.GetBitcoinAmount(), utxo.value);
    }
    /**
     * Create a DLC input for splice transactions
     */
    static createDlcInput(txid, vout, multisigAddress, amount, // in BTC
    value, // in sats
    localFundPubkey, remoteFundPubkey, contractId, inputSerialId) {
        return new Input(txid, vout, multisigAddress, amount, value, undefined, // DLC inputs don't have derivation paths
        220, // DLC witness length for 2-of-2 multisig P2WSH
        undefined, // redeemScript
        inputSerialId, undefined, // scriptPubKey
        undefined, // label
        undefined, // confirmations
        undefined, // spendable
        undefined, // solvable
        undefined, // safe
        {
            localFundPubkey,
            remoteFundPubkey,
            contractId,
        });
    }
}
exports.default = Input;
//# sourceMappingURL=Input.js.map