import { Contract } from 'web3';
import BigNumber from 'bignumber.js';

/**
 * Copyright (c) 2025, Everstake.
 * Licensed under the BSD-3-Clause License. See LICENSE file for details.
 */
/**
 * `WalletSDKError` is a custom error class that extends the built-in `Error` class.
 * It provides additional properties for error handling within the Wallet SDK.
 *
 * @remarks
 * This class is needed to provide additional context for errors, such as a code
 * and the original error, if any.
 *
 * @public
 *
 * @param message - The error message.
 * @param code - A string representing the error code.
 * @param originalError - The original error that caused this error, if any.
 */
declare class WalletSDKError extends Error {
    code: string;
    originalError?: Error | undefined;
    constructor(message: string, code: string, originalError?: Error | undefined);
}
/**
 * `Blockchain` is an abstract class that provides a structure for blockchain-specific classes.
 * It includes methods for error handling and throwing errors.
 *
 * @remarks
 * This class should be extended by classes that implement blockchain-specific functionality.
 * The extending classes should provide their own `ERROR_MESSAGES` and `ORIGINAL_ERROR_MESSAGES`.
 *
 * @property ERROR_MESSAGES - An object that maps error codes to error messages.
 * @property ORIGINAL_ERROR_MESSAGES - An object that maps original error messages to user-friendly error messages.
 *
 *
 * **/
declare abstract class Blockchain {
    protected abstract ERROR_MESSAGES: {
        [key: string]: string;
    };
    protected abstract ORIGINAL_ERROR_MESSAGES: {
        [key: string]: string;
    };
    /**
     * Handles errors that occur within the Ethereum class.
     *
     * @param {keyof typeof ERROR_MESSAGES} code - The error code associated with the error.
     * @param {Error | WalletSDKError | unknown} originalError - The original error that was thrown.
     *
     * If the original error is an instance of WalletSDKError, it is thrown as is.
     * If the original error is an instance of the built-in Error class, a new WalletSDKError is thrown with the original error as the cause.
     * If the original error is not an instance of WalletSDKError or Error, a new WalletSDKError is thrown with a generic message and code.
     */
    handleError(code: keyof typeof this.ERROR_MESSAGES, originalError: Error | WalletSDKError | unknown): void;
    /**
     * Throws a WalletSDKError with a specified error code and message.
     *
     * @param {keyof typeof ERROR_MESSAGES} code - The error code associated with the error.
     * @param {...string[]} values - The values to be inserted into the error message.
     *
     * The method retrieves the error message template associated with the provided code from the ERROR_MESSAGES object.
     * It then replaces placeholders in the message template with provided values and throws a WalletSDKError with the final message and the provided code.
     */
    throwError(code: keyof typeof this.ERROR_MESSAGES, ...values: string[]): void;
    /**
     * Check if the URL is valid
     *
     * @param {string} url - URL
     * @returns a bool type result.
     *
     */
    isValidURL(url: string): boolean;
}

declare const ABI_CONTRACT_APPROVE: ({
    constant: boolean;
    inputs: {
        name: string;
        type: string;
    }[];
    name: string;
    outputs: {
        name: string;
        type: string;
    }[];
    payable: boolean;
    stateMutability: string;
    type: string;
    anonymous?: undefined;
} | {
    inputs: {
        name: string;
        type: string;
    }[];
    payable: boolean;
    stateMutability: string;
    type: string;
    constant?: undefined;
    name?: undefined;
    outputs?: undefined;
    anonymous?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    constant?: undefined;
    outputs?: undefined;
    payable?: undefined;
    stateMutability?: undefined;
})[];
declare const ABI_CONTRACT_BUY: ({
    inputs: never[];
    payable: boolean;
    stateMutability: string;
    type: string;
    anonymous?: undefined;
    name?: undefined;
    constant?: undefined;
    outputs?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    payable?: undefined;
    stateMutability?: undefined;
    constant?: undefined;
    outputs?: undefined;
} | {
    constant: boolean;
    inputs: {
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    outputs: {
        internalType: string;
        name: string;
        type: string;
    }[];
    payable: boolean;
    stateMutability: string;
    type: string;
    anonymous?: undefined;
})[];

type TransactionRequest = {
    from: string;
    to: string;
    gasLimit: bigint;
    data: string;
};
type UnbondInfo = {
    amount: BigNumber;
    withdrawEpoch: bigint;
    unbondNonces: bigint;
};

/**
 * Copyright (c) 2025, Everstake.
 * Licensed under the BSD-3-Clause License. See LICENSE file for details.
 */

/**
 * The `Polygon` class extends the `Blockchain` class and provides methods for interacting with the Polygon network.
 *
 * It handles initialization of Web3 and multiple contract instances, including approval contracts,
 * buy contracts, and staking contracts. It also manages error messages related to contract operations.
 *
 * @property {Web3} web3 - The Web3 instance used for interacting with the Polygon network.
 * @property {Contract} contract_approve - The contract instance for token approval.
 * @property {Contract} contract_approve_pol - The contract instance for POL token approval.
 * @property {Contract} contract_buy - The contract instance for token purchase logic.
 * @property {Contract} contract_staking - The contract instance for staking logic.
 * @property ERROR_MESSAGES - The standardized error messages for the Polygon class.
 * @property ORIGINAL_ERROR_MESSAGES - The raw/original error messages for internal mapping or debugging.
 *
 * @constructor
 * Creates an instance of the `Polygon` class.
 * @param {string} [rpc=RPC_URL] - The RPC URL of the Polygon network.
 */
declare class Polygon extends Blockchain {
    contract_approve: Contract<typeof ABI_CONTRACT_APPROVE>;
    contract_approve_pol: Contract<typeof ABI_CONTRACT_APPROVE>;
    contract_buy: Contract<typeof ABI_CONTRACT_BUY>;
    contract_staking: Contract<typeof ABI_CONTRACT_BUY>;
    private web3;
    protected ERROR_MESSAGES: {
        TRANSACTION_LOADING_ERR: string;
        APPROVE_ERR: string;
        DELEGATE_ERR: string;
        GET_ALLOWANCE_ERR: string;
        UNDELEGATE_ERR: string;
        GET_TOTAL_DELEGATE_ERR: string;
        GET_UNBOND_ERR: string;
        GET_UNBOND_NONCE_ERR: string;
        GET_REWARD_ERR: string;
        ALLOWANCE_ERR: string;
        DELEGATED_BALANCE_ERR: string;
    };
    protected ORIGINAL_ERROR_MESSAGES: {};
    constructor(rpc?: string);
    /**
     * Checks if a transaction is still pending or has been confirmed.
     *
     * @param {string} hash - The transaction hash to check.
     * @returns {Promise<{ result: boolean }>}
     *
     * @throws {Error} Throws an error with code `'TRANSACTION_LOADING_ERR'` if an issue occurs while fetching the transaction status.
     *
     */
    isTransactionLoading(hash: string): Promise<{
        result: boolean;
    }>;
    /** approve returns TX loading status
     * @param {string} address - user's address
     * @param {string} amount - amount for approve
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @returns {Promise<Object>} Promise object the result of boolean type
     */
    approve(address: string, amount: string, isPOL?: boolean): Promise<{
        from: string;
        to: string | undefined;
        gasLimit: bigint;
        data: string;
    } | undefined>;
    /** delegate makes unsigned delegation TX
     * @param {string} token - auth token
     * @param {string} address - user's address
     * @param {string} amount - amount for approve
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @returns {Promise<Object>} Promise object represents the unsigned TX object
     */
    delegate(token: string, address: string, amount: string, isPOL?: boolean): Promise<TransactionRequest | undefined>;
    /** undelegate makes unsigned undelegate TX
     * @param {string} token - auth token
     * @param {string} address - user's address
     * @param {string} amount - amount for approve
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @returns {Promise<Object>} Promise object represents the unsigned TX object
     */
    undelegate(token: string, address: string, amount: string, isPOL?: boolean): Promise<TransactionRequest | undefined>;
    /** claimUndelegate makes unsigned claim undelegate TX
     * @param {string} address - user's address
     * @param {bigint} unbondNonce - unbound nonce
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @returns {Promise<Object>} Promise object represents the unsigned TX object
     */
    claimUndelegate(address: string, unbondNonce?: bigint, isPOL?: boolean): Promise<TransactionRequest | undefined>;
    /** reward makes unsigned claim reward TX
     * @param {string} address - user's address
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @returns {Promise<Object>} Promise object represents the unsigned TX object
     */
    reward(address: string, isPOL?: boolean): Promise<TransactionRequest | undefined>;
    /** restake makes unsigned restake reward TX
     * @param {string} address - user's address
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @returns {Promise<Object>} Promise object represents the unsigned TX object
     */
    restake(address: string, isPOL?: boolean): Promise<TransactionRequest | undefined>;
    /** getReward returns reward number
     * @param {string} address - user's address
     * @returns {Promise<BigNumber>} Promise with number of the reward
     */
    getReward(address: string): Promise<BigNumber | undefined>;
    /** getAllowance returns allowed number for spender
     * @param {string} owner - tokens owner
     * @param {boolean} isPOL - is POL token (false - old MATIC)
     * @param {string} spender - contract spender
     * @returns {Promise<bigint>} Promise allowed bigint for spender
     */
    getAllowance(owner: string, isPOL?: boolean, spender?: string): Promise<bigint | undefined>;
    /** getTotalDelegate returns total delegated number
     * @param {string} address - user's address
     * @returns {Promise<BigNumber>} Promise with BigNumber of the delegation
     */
    getTotalDelegate(address: string): Promise<BigNumber | undefined>;
    /** getUnbond returns unbound data
     * @param {string} address - user's address
     * @param {bigint} unbondNonce - unbound nonce
     * @returns {Promise<Object>} Promise Object with unbound data
     */
    getUnbond(address: string, unbondNonce?: bigint): Promise<UnbondInfo | undefined>;
    /** getUnbondNonces returns unbound nonce
     * @param {string} address - user's address
     * @returns {Promise<bigint>} Promise with unbound nonce bigint
     */
    getUnbondNonces(address: string): Promise<bigint | undefined>;
    /** getCurrentEpoch returns current epoch
     * @returns {Promise<bigint>} Promise with current epoch bigint
     */
    getCurrentEpoch(): Promise<bigint | undefined>;
    private isNumbers;
}

export { Polygon };
