"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@atomicfinance/errors");
const types_1 = require("@atomicfinance/types");
const lodash_1 = require("lodash");
class Chain {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    constructor(client) {
        this.client = client;
    }
    /** @inheritdoc */
    async generateBlock(numberOfBlocks) {
        if (!(0, lodash_1.isNumber)(numberOfBlocks)) {
            throw new TypeError('First argument should be a number');
        }
        return this.client.getMethod('generateBlock')(numberOfBlocks);
    }
    /** @inheritdoc */
    async getBlockByHash(blockHash, includeTx = false) {
        if (!(0, lodash_1.isString)(blockHash)) {
            throw new TypeError('Block hash should be a string');
        }
        if (!(0, lodash_1.isBoolean)(includeTx)) {
            throw new TypeError('Second parameter should be boolean');
        }
        const block = await this.client.getMethod('getBlockByHash')(blockHash, includeTx);
        this.client.assertValidBlock(block);
        return block;
    }
    /** @inheritdoc */
    async getBlockByNumber(blockNumber, includeTx = false) {
        if (!(0, lodash_1.isNumber)(blockNumber)) {
            throw new TypeError('Invalid Block number');
        }
        if (!(0, lodash_1.isBoolean)(includeTx)) {
            throw new TypeError('Second parameter should be boolean');
        }
        const block = await this.client.getMethod('getBlockByNumber')(blockNumber, includeTx);
        this.client.assertValidBlock(block);
        return block;
    }
    /** @inheritdoc */
    async getBlockHeight() {
        const blockHeight = await this.client.getMethod('getBlockHeight')();
        if (!(0, lodash_1.isNumber)(blockHeight)) {
            throw new errors_1.InvalidProviderResponseError('Provider returned an invalid block height');
        }
        return blockHeight;
    }
    /** @inheritdoc */
    async getTransactionByHash(txHash) {
        if (!(0, lodash_1.isString)(txHash)) {
            throw new TypeError('Transaction hash should be a string');
        }
        const transaction = await this.client.getMethod('getTransactionByHash')(txHash);
        if (transaction) {
            this.client.assertValidTransaction(transaction);
        }
        return transaction;
    }
    /** @inheritdoc */
    async getBalance(addresses) {
        const balance = await this.client.getMethod('getBalance')(addresses);
        if (!types_1.BigNumber.isBigNumber(balance)) {
            throw new errors_1.InvalidProviderResponseError('Provider returned an invalid response');
        }
        return balance;
    }
    /** @inheritdoc */
    async sendTransaction(options) {
        const transaction = await this.client.getMethod('sendTransaction')(options);
        this.client.assertValidTransaction(transaction);
        return transaction;
    }
    /** @inheritdoc */
    async sendSweepTransaction(address, fee) {
        return this.client.getMethod('sendSweepTransaction')(address, fee);
    }
    /** @inheritdoc */
    async updateTransactionFee(tx, newFee) {
        if ((0, lodash_1.isObject)(tx)) {
            this.client.assertValidTransaction(tx);
        }
        else {
            if (!(0, lodash_1.isString)(tx)) {
                throw new TypeError('Transaction should be a string or object');
            }
        }
        const transaction = await this.client.getMethod('updateTransactionFee')(tx, newFee);
        this.client.assertValidTransaction(transaction);
        return transaction;
    }
    /** @inheritdoc */
    async sendBatchTransaction(transactions) {
        return this.client.getMethod('sendBatchTransaction')(transactions);
    }
    /** @inheritdoc */
    async sendRawTransaction(rawTransaction) {
        const txHash = await this.client.getMethod('sendRawTransaction')(rawTransaction);
        if (!(0, lodash_1.isString)(txHash)) {
            throw new errors_1.InvalidProviderResponseError('sendRawTransaction method should return a transaction id string');
        }
        return txHash;
    }
    /** @inheritdoc */
    async getFees() {
        return this.client.getMethod('getFees')();
    }
}
exports.default = Chain;
//# sourceMappingURL=Chain.js.map