/* tslint:disable */
/* eslint-disable */
/**
 * Stacks 2.0 Blockchain API
 * This is the documentation for the Stacks 2.0 Blockchain API.  It is comprised of two parts; the Stacks Blockchain API and the Stacks Core API.  [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/614feab5c108d292bffa#?env%5BStacks%20Blockchain%20API%5D=W3sia2V5Ijoic3R4X2FkZHJlc3MiLCJ2YWx1ZSI6IlNUMlRKUkhESE1ZQlE0MTdIRkIwQkRYNDMwVFFBNVBYUlg2NDk1RzFWIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJibG9ja19pZCIsInZhbHVlIjoiMHgiLCJlbmFibGVkIjp0cnVlfSx7ImtleSI6Im9mZnNldCIsInZhbHVlIjoiMCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoibGltaXRfdHgiLCJ2YWx1ZSI6IjIwMCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoibGltaXRfYmxvY2siLCJ2YWx1ZSI6IjMwIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJ0eF9pZCIsInZhbHVlIjoiMHg1NDA5MGMxNmE3MDJiNzUzYjQzMTE0ZTg4NGJjMTlhODBhNzk2MzhmZDQ0OWE0MGY4MDY4Y2RmMDAzY2RlNmUwIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJjb250cmFjdF9pZCIsInZhbHVlIjoiU1RKVFhFSlBKUFBWRE5BOUIwNTJOU1JSQkdRQ0ZOS1ZTMTc4VkdIMS5oZWxsb193b3JsZFxuIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJidGNfYWRkcmVzcyIsInZhbHVlIjoiYWJjIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJjb250cmFjdF9hZGRyZXNzIiwidmFsdWUiOiJTVEpUWEVKUEpQUFZETkE5QjA1Mk5TUlJCR1FDRk5LVlMxNzhWR0gxIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJjb250cmFjdF9uYW1lIiwidmFsdWUiOiJoZWxsb193b3JsZCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoiY29udHJhY3RfbWFwIiwidmFsdWUiOiJzdG9yZSIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoiY29udHJhY3RfbWV0aG9kIiwidmFsdWUiOiJnZXQtdmFsdWUiLCJlbmFibGVkIjp0cnVlfV0=) 
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import {
    AccountDataResponse,
    AccountDataResponseFromJSON,
    AccountDataResponseToJSON,
    AddressAssetsListResponse,
    AddressAssetsListResponseFromJSON,
    AddressAssetsListResponseToJSON,
    AddressBalanceResponse,
    AddressBalanceResponseFromJSON,
    AddressBalanceResponseToJSON,
    AddressStxBalanceResponse,
    AddressStxBalanceResponseFromJSON,
    AddressStxBalanceResponseToJSON,
    AddressTransactionsListResponse,
    AddressTransactionsListResponseFromJSON,
    AddressTransactionsListResponseToJSON,
} from '../models';

export interface GetAccountAssetsRequest {
    principal: string;
    limit?: number;
    offset?: number;
}

export interface GetAccountBalanceRequest {
    principal: string;
}

export interface GetAccountInfoRequest {
    principal: string;
    proof?: number;
    tip?: string;
}

export interface GetAccountStxBalanceRequest {
    principal: string;
}

export interface GetAccountTransactionsRequest {
    principal: string;
    limit?: number;
    offset?: number;
}

/**
 * AccountsApi - interface
 * 
 * @export
 * @interface AccountsApiInterface
 */
export interface AccountsApiInterface {
    /**
     * 
     * @summary Get account assets
     * @param {string} principal Stacks address or a Contract identifier (e.g. &#x60;SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info&#x60;)
     * @param {number} [limit] max number of account assets to fetch
     * @param {number} [offset] index of first account assets to fetch
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof AccountsApiInterface
     */
    getAccountAssetsRaw(requestParameters: GetAccountAssetsRequest): Promise<runtime.ApiResponse<AddressAssetsListResponse>>;

    /**
     * Get account assets
     */
    getAccountAssets(requestParameters: GetAccountAssetsRequest): Promise<AddressAssetsListResponse>;

    /**
     * 
     * @summary Get account balances
     * @param {string} principal Stacks address or a Contract identifier (e.g. &#x60;SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info&#x60;)
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof AccountsApiInterface
     */
    getAccountBalanceRaw(requestParameters: GetAccountBalanceRequest): Promise<runtime.ApiResponse<AddressBalanceResponse>>;

    /**
     * Get account balances
     */
    getAccountBalance(requestParameters: GetAccountBalanceRequest): Promise<AddressBalanceResponse>;

    /**
     * Get the account data for the provided principal  Where balance is the hex encoding of a unsigned 128-bit integer (big-endian), nonce is a unsigned 64-bit integer, and the proofs are provided as hex strings.  For non-existent accounts, this does not 404, rather it returns an object with balance and nonce of 0. 
     * @summary Get account info
     * @param {string} principal Stacks address or a Contract identifier (e.g. &#x60;SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info&#x60;)
     * @param {number} [proof] Returns object without the proof field if set to 0
     * @param {string} [tip] The Stacks chain tip to query from
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof AccountsApiInterface
     */
    getAccountInfoRaw(requestParameters: GetAccountInfoRequest): Promise<runtime.ApiResponse<AccountDataResponse>>;

    /**
     * Get the account data for the provided principal  Where balance is the hex encoding of a unsigned 128-bit integer (big-endian), nonce is a unsigned 64-bit integer, and the proofs are provided as hex strings.  For non-existent accounts, this does not 404, rather it returns an object with balance and nonce of 0. 
     * Get account info
     */
    getAccountInfo(requestParameters: GetAccountInfoRequest): Promise<AccountDataResponse>;

    /**
     * 
     * @summary Get account STX balance
     * @param {string} principal Stacks address or a Contract identifier (e.g. &#x60;SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info&#x60;)
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof AccountsApiInterface
     */
    getAccountStxBalanceRaw(requestParameters: GetAccountStxBalanceRequest): Promise<runtime.ApiResponse<AddressStxBalanceResponse>>;

    /**
     * Get account STX balance
     */
    getAccountStxBalance(requestParameters: GetAccountStxBalanceRequest): Promise<AddressStxBalanceResponse>;

    /**
     * 
     * @summary Get account transactions
     * @param {string} principal Stacks address or a Contract identifier (e.g. &#x60;SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info&#x60;)
     * @param {number} [limit] max number of account transactions to fetch
     * @param {number} [offset] index of first account transaction to fetch
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof AccountsApiInterface
     */
    getAccountTransactionsRaw(requestParameters: GetAccountTransactionsRequest): Promise<runtime.ApiResponse<AddressTransactionsListResponse>>;

    /**
     * Get account transactions
     */
    getAccountTransactions(requestParameters: GetAccountTransactionsRequest): Promise<AddressTransactionsListResponse>;

}

/**
 * 
 */
export class AccountsApi extends runtime.BaseAPI implements AccountsApiInterface {

    /**
     * Get account assets
     */
    async getAccountAssetsRaw(requestParameters: GetAccountAssetsRequest): Promise<runtime.ApiResponse<AddressAssetsListResponse>> {
        if (requestParameters.principal === null || requestParameters.principal === undefined) {
            throw new runtime.RequiredError('principal','Required parameter requestParameters.principal was null or undefined when calling getAccountAssets.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        if (requestParameters.limit !== undefined) {
            queryParameters['limit'] = requestParameters.limit;
        }

        if (requestParameters.offset !== undefined) {
            queryParameters['offset'] = requestParameters.offset;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/extended/v1/address/{principal}/assets`.replace(`{${"principal"}}`, encodeURIComponent(String(requestParameters.principal))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => AddressAssetsListResponseFromJSON(jsonValue));
    }

    /**
     * Get account assets
     */
    async getAccountAssets(requestParameters: GetAccountAssetsRequest): Promise<AddressAssetsListResponse> {
        const response = await this.getAccountAssetsRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get account balances
     */
    async getAccountBalanceRaw(requestParameters: GetAccountBalanceRequest): Promise<runtime.ApiResponse<AddressBalanceResponse>> {
        if (requestParameters.principal === null || requestParameters.principal === undefined) {
            throw new runtime.RequiredError('principal','Required parameter requestParameters.principal was null or undefined when calling getAccountBalance.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/extended/v1/address/{principal}/balances`.replace(`{${"principal"}}`, encodeURIComponent(String(requestParameters.principal))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => AddressBalanceResponseFromJSON(jsonValue));
    }

    /**
     * Get account balances
     */
    async getAccountBalance(requestParameters: GetAccountBalanceRequest): Promise<AddressBalanceResponse> {
        const response = await this.getAccountBalanceRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get the account data for the provided principal  Where balance is the hex encoding of a unsigned 128-bit integer (big-endian), nonce is a unsigned 64-bit integer, and the proofs are provided as hex strings.  For non-existent accounts, this does not 404, rather it returns an object with balance and nonce of 0. 
     * Get account info
     */
    async getAccountInfoRaw(requestParameters: GetAccountInfoRequest): Promise<runtime.ApiResponse<AccountDataResponse>> {
        if (requestParameters.principal === null || requestParameters.principal === undefined) {
            throw new runtime.RequiredError('principal','Required parameter requestParameters.principal was null or undefined when calling getAccountInfo.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        if (requestParameters.proof !== undefined) {
            queryParameters['proof'] = requestParameters.proof;
        }

        if (requestParameters.tip !== undefined) {
            queryParameters['tip'] = requestParameters.tip;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/v2/accounts/{principal}`.replace(`{${"principal"}}`, encodeURIComponent(String(requestParameters.principal))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => AccountDataResponseFromJSON(jsonValue));
    }

    /**
     * Get the account data for the provided principal  Where balance is the hex encoding of a unsigned 128-bit integer (big-endian), nonce is a unsigned 64-bit integer, and the proofs are provided as hex strings.  For non-existent accounts, this does not 404, rather it returns an object with balance and nonce of 0. 
     * Get account info
     */
    async getAccountInfo(requestParameters: GetAccountInfoRequest): Promise<AccountDataResponse> {
        const response = await this.getAccountInfoRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get account STX balance
     */
    async getAccountStxBalanceRaw(requestParameters: GetAccountStxBalanceRequest): Promise<runtime.ApiResponse<AddressStxBalanceResponse>> {
        if (requestParameters.principal === null || requestParameters.principal === undefined) {
            throw new runtime.RequiredError('principal','Required parameter requestParameters.principal was null or undefined when calling getAccountStxBalance.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/extended/v1/address/{principal}/stx`.replace(`{${"principal"}}`, encodeURIComponent(String(requestParameters.principal))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => AddressStxBalanceResponseFromJSON(jsonValue));
    }

    /**
     * Get account STX balance
     */
    async getAccountStxBalance(requestParameters: GetAccountStxBalanceRequest): Promise<AddressStxBalanceResponse> {
        const response = await this.getAccountStxBalanceRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get account transactions
     */
    async getAccountTransactionsRaw(requestParameters: GetAccountTransactionsRequest): Promise<runtime.ApiResponse<AddressTransactionsListResponse>> {
        if (requestParameters.principal === null || requestParameters.principal === undefined) {
            throw new runtime.RequiredError('principal','Required parameter requestParameters.principal was null or undefined when calling getAccountTransactions.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        if (requestParameters.limit !== undefined) {
            queryParameters['limit'] = requestParameters.limit;
        }

        if (requestParameters.offset !== undefined) {
            queryParameters['offset'] = requestParameters.offset;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/extended/v1/address/{principal}/transactions`.replace(`{${"principal"}}`, encodeURIComponent(String(requestParameters.principal))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => AddressTransactionsListResponseFromJSON(jsonValue));
    }

    /**
     * Get account transactions
     */
    async getAccountTransactions(requestParameters: GetAccountTransactionsRequest): Promise<AddressTransactionsListResponse> {
        const response = await this.getAccountTransactionsRaw(requestParameters);
        return await response.value();
    }

}
