"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genAccount = exports.genAddingOperationsInAccount = void 0;
const prando_1 = __importDefault(require("prando"));
const bignumber_js_1 = require("bignumber.js");
const account_1 = require("@ledgerhq/coin-framework/mocks/account");
const bridge_1 = require("../bridge");
const mock_1 = __importDefault(require("../generated/mock"));
const types_1 = require("@ledgerhq/coin-cardano/types");
/**
 * @memberof mock/account
 */
function genAddingOperationsInAccount(account, count, seed) {
    const rng = new prando_1.default(seed);
    const copy = { ...account };
    copy.operations = Array(count)
        .fill(null)
        .reduce(ops => {
        const op = (0, account_1.genOperation)(copy, copy, ops, rng);
        return ops.concat(op);
    }, copy.operations);
    copy.spendableBalance = copy.balance = (0, account_1.ensureNoNegative)(copy.operations);
    const perFamilyOperation = mock_1.default[account.currency.id];
    const postSyncAccount = perFamilyOperation && perFamilyOperation.postSyncAccount;
    if (postSyncAccount)
        postSyncAccount(copy);
    return copy;
}
exports.genAddingOperationsInAccount = genAddingOperationsInAccount;
function genAccount(id, opts = {}) {
    return (0, account_1.genAccount)(id, opts, (account, currency, address) => {
        switch (currency.family) {
            case "solana":
                account.solanaResources = {
                    stakes: [],
                    unstakeReserve: new bignumber_js_1.BigNumber(0),
                };
                break;
            case "cosmos":
                account.cosmosResources = {
                    // TODO variation in these
                    delegations: [],
                    redelegations: [],
                    unbondings: [],
                    delegatedBalance: new bignumber_js_1.BigNumber(0),
                    pendingRewardsBalance: new bignumber_js_1.BigNumber(0),
                    unbondingBalance: new bignumber_js_1.BigNumber(0),
                    withdrawAddress: address,
                    sequence: 0,
                };
                break;
            case "bitcoin":
                account.bitcoinResources = {
                    utxos: [],
                    walletAccount: undefined,
                };
                break;
            case "polkadot":
                account.polkadotResources = {
                    stash: null,
                    controller: null,
                    nonce: 0,
                    lockedBalance: new bignumber_js_1.BigNumber(0),
                    unlockingBalance: new bignumber_js_1.BigNumber(0),
                    unlockedBalance: new bignumber_js_1.BigNumber(0),
                    unlockings: [],
                    nominations: [],
                    numSlashingSpans: 0,
                };
                break;
            case "tezos":
                account.tezosResources = {
                    revealed: true,
                    counter: 0,
                };
                break;
            case "tron":
                // TODO variation in these. you could use the account.name as a way to split cases
                account.tronResources = {
                    frozen: {
                        bandwidth: null,
                        energy: null,
                    },
                    unFrozen: {
                        bandwidth: null,
                        energy: null,
                    },
                    delegatedFrozen: {
                        bandwidth: null,
                        energy: null,
                    },
                    legacyFrozen: {
                        bandwidth: null,
                        energy: null,
                    },
                    votes: [],
                    tronPower: 0,
                    energy: (0, bignumber_js_1.BigNumber)(0),
                    bandwidth: {
                        freeUsed: (0, bignumber_js_1.BigNumber)(0),
                        freeLimit: (0, bignumber_js_1.BigNumber)(opts.bandwidth ? 1 : 0),
                        gainedUsed: (0, bignumber_js_1.BigNumber)(0),
                        gainedLimit: (0, bignumber_js_1.BigNumber)(0),
                    },
                    unwithdrawnReward: (0, bignumber_js_1.BigNumber)(0),
                    lastWithdrawnRewardDate: null,
                    lastVotedDate: null,
                    cacheTransactionInfoById: {},
                };
                break;
            case "cardano":
                account.cardanoResources = {
                    delegation: {
                        status: true,
                        deposit: "2000000",
                        poolId: "45",
                        ticker: "ADA",
                        name: "Cardano",
                        dRepHex: undefined,
                        rewards: new bignumber_js_1.BigNumber(42),
                    },
                    externalCredentials: [
                        {
                            isUsed: false,
                            key: "test",
                            path: {
                                purpose: 1852,
                                coin: 1815,
                                account: 4,
                                chain: types_1.PaymentChain.external,
                                index: 0,
                            },
                        },
                    ],
                    internalCredentials: [
                        {
                            isUsed: false,
                            key: "test",
                            path: {
                                purpose: 1852,
                                coin: 1815,
                                account: 4,
                                chain: types_1.PaymentChain.internal,
                                index: 0,
                            },
                        },
                    ],
                    utxos: [
                        {
                            hash: "",
                            index: 0,
                            address: "",
                            amount: new bignumber_js_1.BigNumber(10),
                            tokens: [],
                            paymentCredential: {
                                key: "",
                                path: { purpose: 0, coin: 0, account: 0, chain: types_1.PaymentChain.internal, index: 0 },
                            },
                        },
                    ],
                    protocolParams: {
                        minFeeA: "",
                        minFeeB: "",
                        stakeKeyDeposit: "",
                        lovelacePerUtxoWord: "",
                        collateralPercent: "",
                        priceMem: "",
                        priceSteps: "",
                        maxTxSize: "",
                        maxValueSize: "",
                        utxoCostPerByte: "",
                        minFeeRefScriptCostPerByte: "",
                        languageView: {},
                    },
                };
                break;
            default: {
                try {
                    const bridge = (0, bridge_1.getAccountBridge)(account);
                    const initAccount = bridge.initAccount;
                    if (initAccount) {
                        initAccount(account);
                    }
                }
                catch {
                    // to fix /src/__tests__/cross.ts, skip bridge error if there is no bridge in such currency
                }
            }
        }
    }, (account, currency, rng) => {
        const perFamilyOperation = mock_1.default[currency.id];
        const genAccountEnhanceOperations = perFamilyOperation && perFamilyOperation.genAccountEnhanceOperations;
        if (genAccountEnhanceOperations) {
            genAccountEnhanceOperations(account, rng);
        }
    });
}
exports.genAccount = genAccount;
//# sourceMappingURL=account.js.map