"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genericGetTransactionStatus = void 0;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const alpaca_1 = require("./alpaca");
// => alpaca validateIntent
function genericGetTransactionStatus(network, kind) {
    return async (account, transaction) => {
        const { freshAddress, balance, currency } = account;
        const alpacaApi = (0, alpaca_1.getAlpacaApi)(network, kind);
        const { errors, warnings } = await alpacaApi.validateIntent({
            currencyName: currency.name,
            address: freshAddress,
            balance: BigInt(balance.toString()),
            currencyUnit: currency.units[0],
        }, {
            type: "PAYMENT",
            recipient: transaction.recipient,
            amount: BigInt(transaction.amount?.toString() ?? "0"),
            fee: BigInt(transaction.fees?.toString() ?? "0"),
        });
        const estimatedFees = transaction.fees || new bignumber_js_1.default(0);
        return Promise.resolve({
            errors,
            warnings,
            estimatedFees,
            amount: transaction.amount,
            totalSpent: transaction.amount.plus(transaction.fees),
        });
    };
}
exports.genericGetTransactionStatus = genericGetTransactionStatus;
//# sourceMappingURL=getTransactionStatus.js.map