/* 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 {
    ContractInterfaceResponse,
    ContractInterfaceResponseFromJSON,
    ContractInterfaceResponseToJSON,
    ContractSourceResponse,
    ContractSourceResponseFromJSON,
    ContractSourceResponseToJSON,
    MapEntryResponse,
    MapEntryResponseFromJSON,
    MapEntryResponseToJSON,
    ReadOnlyFunctionArgs,
    ReadOnlyFunctionArgsFromJSON,
    ReadOnlyFunctionArgsToJSON,
    ReadOnlyFunctionSuccessResponse,
    ReadOnlyFunctionSuccessResponseFromJSON,
    ReadOnlyFunctionSuccessResponseToJSON,
} from '../models';

export interface CallReadOnlyFunctionRequest {
    contractAddress: string;
    contractName: string;
    functionName: string;
    readOnlyFunctionArgs: ReadOnlyFunctionArgs;
    tip?: string;
}

export interface GetContractByIdRequest {
    contractId: string;
}

export interface GetContractDataMapEntryRequest {
    contractAddress: string;
    contractName: string;
    mapName: string;
    key: string;
    proof?: number;
    tip?: string;
}

export interface GetContractEventsByIdRequest {
    contractId: string;
    limit?: number;
    offset?: number;
}

export interface GetContractInterfaceRequest {
    contractAddress: string;
    contractName: string;
    tip?: string;
}

export interface GetContractSourceRequest {
    contractAddress: string;
    contractName: string;
    proof?: number;
    tip?: string;
}

/**
 * SmartContractsApi - interface
 * 
 * @export
 * @interface SmartContractsApiInterface
 */
export interface SmartContractsApiInterface {
    /**
     * Call a read-only public function on a given smart contract.  The smart contract and function are specified using the URL path. The arguments and the simulated tx-sender are supplied via the POST body in the following JSON format: 
     * @summary Call read-only function
     * @param {string} contractAddress Stacks address
     * @param {string} contractName Contract name
     * @param {string} functionName Function name
     * @param {ReadOnlyFunctionArgs} readOnlyFunctionArgs 
     * @param {string} [tip] The Stacks chain tip to query from
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof SmartContractsApiInterface
     */
    callReadOnlyFunctionRaw(requestParameters: CallReadOnlyFunctionRequest): Promise<runtime.ApiResponse<ReadOnlyFunctionSuccessResponse>>;

    /**
     * Call a read-only public function on a given smart contract.  The smart contract and function are specified using the URL path. The arguments and the simulated tx-sender are supplied via the POST body in the following JSON format: 
     * Call read-only function
     */
    callReadOnlyFunction(requestParameters: CallReadOnlyFunctionRequest): Promise<ReadOnlyFunctionSuccessResponse>;

    /**
     * Get contract info using the contract ID
     * @summary Get contract info
     * @param {string} contractId Contract identifier formatted as &#x60;&lt;contract_address&gt;.&lt;contract_name&gt;&#x60;
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof SmartContractsApiInterface
     */
    getContractByIdRaw(requestParameters: GetContractByIdRequest): Promise<runtime.ApiResponse<object>>;

    /**
     * Get contract info using the contract ID
     * Get contract info
     */
    getContractById(requestParameters: GetContractByIdRequest): Promise<object>;

    /**
     * Attempt to fetch data from a contract data map. The contract is identified with [Stacks Address] and [Contract Name] in the URL path. The map is identified with [Map Name].  The key to lookup in the map is supplied via the POST body. This should be supplied as the hex string serialization of the key (which should be a Clarity value). Note, this is a JSON string atom.  In the response, `data` is the hex serialization of the map response. Note that map responses are Clarity option types, for non-existent values, this is a serialized none, and for all other responses, it is a serialized (some ...) object. 
     * @summary Get specific data-map inside a contract
     * @param {string} contractAddress Stacks address
     * @param {string} contractName Contract name
     * @param {string} mapName Map name
     * @param {string} key Hex string serialization of the lookup key (which should be a Clarity value)
     * @param {number} [proof] Returns object without the proof field when set to 0
     * @param {string} [tip] The Stacks chain tip to query from
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof SmartContractsApiInterface
     */
    getContractDataMapEntryRaw(requestParameters: GetContractDataMapEntryRequest): Promise<runtime.ApiResponse<MapEntryResponse>>;

    /**
     * Attempt to fetch data from a contract data map. The contract is identified with [Stacks Address] and [Contract Name] in the URL path. The map is identified with [Map Name].  The key to lookup in the map is supplied via the POST body. This should be supplied as the hex string serialization of the key (which should be a Clarity value). Note, this is a JSON string atom.  In the response, `data` is the hex serialization of the map response. Note that map responses are Clarity option types, for non-existent values, this is a serialized none, and for all other responses, it is a serialized (some ...) object. 
     * Get specific data-map inside a contract
     */
    getContractDataMapEntry(requestParameters: GetContractDataMapEntryRequest): Promise<MapEntryResponse>;

    /**
     * Get contract events using a contract ID
     * @summary Get contract events
     * @param {string} contractId Contract identifier formatted as &#x60;&lt;contract_address&gt;.&lt;contract_name&gt;&#x60;
     * @param {number} [limit] max number of contract events to fetch
     * @param {number} [offset] index of first contract event to fetch
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof SmartContractsApiInterface
     */
    getContractEventsByIdRaw(requestParameters: GetContractEventsByIdRequest): Promise<runtime.ApiResponse<object>>;

    /**
     * Get contract events using a contract ID
     * Get contract events
     */
    getContractEventsById(requestParameters: GetContractEventsByIdRequest): Promise<object>;

    /**
     * Get contract interface using a `contract_address` and `contract name`
     * @summary Get contract interface
     * @param {string} contractAddress Stacks address
     * @param {string} contractName Contract name
     * @param {string} [tip] The Stacks chain tip to query from
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof SmartContractsApiInterface
     */
    getContractInterfaceRaw(requestParameters: GetContractInterfaceRequest): Promise<runtime.ApiResponse<ContractInterfaceResponse>>;

    /**
     * Get contract interface using a `contract_address` and `contract name`
     * Get contract interface
     */
    getContractInterface(requestParameters: GetContractInterfaceRequest): Promise<ContractInterfaceResponse>;

    /**
     * Returns the Clarity source code of a given contract, along with the block height it was published in, and the MARF proof for the data
     * @summary Get contract source
     * @param {string} contractAddress Stacks address
     * @param {string} contractName Contract name
     * @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 SmartContractsApiInterface
     */
    getContractSourceRaw(requestParameters: GetContractSourceRequest): Promise<runtime.ApiResponse<ContractSourceResponse>>;

    /**
     * Returns the Clarity source code of a given contract, along with the block height it was published in, and the MARF proof for the data
     * Get contract source
     */
    getContractSource(requestParameters: GetContractSourceRequest): Promise<ContractSourceResponse>;

}

/**
 * 
 */
export class SmartContractsApi extends runtime.BaseAPI implements SmartContractsApiInterface {

    /**
     * Call a read-only public function on a given smart contract.  The smart contract and function are specified using the URL path. The arguments and the simulated tx-sender are supplied via the POST body in the following JSON format: 
     * Call read-only function
     */
    async callReadOnlyFunctionRaw(requestParameters: CallReadOnlyFunctionRequest): Promise<runtime.ApiResponse<ReadOnlyFunctionSuccessResponse>> {
        if (requestParameters.contractAddress === null || requestParameters.contractAddress === undefined) {
            throw new runtime.RequiredError('contractAddress','Required parameter requestParameters.contractAddress was null or undefined when calling callReadOnlyFunction.');
        }

        if (requestParameters.contractName === null || requestParameters.contractName === undefined) {
            throw new runtime.RequiredError('contractName','Required parameter requestParameters.contractName was null or undefined when calling callReadOnlyFunction.');
        }

        if (requestParameters.functionName === null || requestParameters.functionName === undefined) {
            throw new runtime.RequiredError('functionName','Required parameter requestParameters.functionName was null or undefined when calling callReadOnlyFunction.');
        }

        if (requestParameters.readOnlyFunctionArgs === null || requestParameters.readOnlyFunctionArgs === undefined) {
            throw new runtime.RequiredError('readOnlyFunctionArgs','Required parameter requestParameters.readOnlyFunctionArgs was null or undefined when calling callReadOnlyFunction.');
        }

        const queryParameters: runtime.HTTPQuery = {};

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

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        const response = await this.request({
            path: `/v2/contracts/call-read/{contract_address}/{contract_name}/{function_name}`.replace(`{${"contract_address"}}`, encodeURIComponent(String(requestParameters.contractAddress))).replace(`{${"contract_name"}}`, encodeURIComponent(String(requestParameters.contractName))).replace(`{${"function_name"}}`, encodeURIComponent(String(requestParameters.functionName))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: ReadOnlyFunctionArgsToJSON(requestParameters.readOnlyFunctionArgs),
        });

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

    /**
     * Call a read-only public function on a given smart contract.  The smart contract and function are specified using the URL path. The arguments and the simulated tx-sender are supplied via the POST body in the following JSON format: 
     * Call read-only function
     */
    async callReadOnlyFunction(requestParameters: CallReadOnlyFunctionRequest): Promise<ReadOnlyFunctionSuccessResponse> {
        const response = await this.callReadOnlyFunctionRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get contract info using the contract ID
     * Get contract info
     */
    async getContractByIdRaw(requestParameters: GetContractByIdRequest): Promise<runtime.ApiResponse<object>> {
        if (requestParameters.contractId === null || requestParameters.contractId === undefined) {
            throw new runtime.RequiredError('contractId','Required parameter requestParameters.contractId was null or undefined when calling getContractById.');
        }

        const queryParameters: runtime.HTTPQuery = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        return new runtime.JSONApiResponse<any>(response);
    }

    /**
     * Get contract info using the contract ID
     * Get contract info
     */
    async getContractById(requestParameters: GetContractByIdRequest): Promise<object> {
        const response = await this.getContractByIdRaw(requestParameters);
        return await response.value();
    }

    /**
     * Attempt to fetch data from a contract data map. The contract is identified with [Stacks Address] and [Contract Name] in the URL path. The map is identified with [Map Name].  The key to lookup in the map is supplied via the POST body. This should be supplied as the hex string serialization of the key (which should be a Clarity value). Note, this is a JSON string atom.  In the response, `data` is the hex serialization of the map response. Note that map responses are Clarity option types, for non-existent values, this is a serialized none, and for all other responses, it is a serialized (some ...) object. 
     * Get specific data-map inside a contract
     */
    async getContractDataMapEntryRaw(requestParameters: GetContractDataMapEntryRequest): Promise<runtime.ApiResponse<MapEntryResponse>> {
        if (requestParameters.contractAddress === null || requestParameters.contractAddress === undefined) {
            throw new runtime.RequiredError('contractAddress','Required parameter requestParameters.contractAddress was null or undefined when calling getContractDataMapEntry.');
        }

        if (requestParameters.contractName === null || requestParameters.contractName === undefined) {
            throw new runtime.RequiredError('contractName','Required parameter requestParameters.contractName was null or undefined when calling getContractDataMapEntry.');
        }

        if (requestParameters.mapName === null || requestParameters.mapName === undefined) {
            throw new runtime.RequiredError('mapName','Required parameter requestParameters.mapName was null or undefined when calling getContractDataMapEntry.');
        }

        if (requestParameters.key === null || requestParameters.key === undefined) {
            throw new runtime.RequiredError('key','Required parameter requestParameters.key was null or undefined when calling getContractDataMapEntry.');
        }

        const queryParameters: runtime.HTTPQuery = {};

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

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

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        const response = await this.request({
            path: `/v2/map_entry/{contract_address}/{contract_name}/{map_name}`.replace(`{${"contract_address"}}`, encodeURIComponent(String(requestParameters.contractAddress))).replace(`{${"contract_name"}}`, encodeURIComponent(String(requestParameters.contractName))).replace(`{${"map_name"}}`, encodeURIComponent(String(requestParameters.mapName))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: requestParameters.key as any,
        });

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

    /**
     * Attempt to fetch data from a contract data map. The contract is identified with [Stacks Address] and [Contract Name] in the URL path. The map is identified with [Map Name].  The key to lookup in the map is supplied via the POST body. This should be supplied as the hex string serialization of the key (which should be a Clarity value). Note, this is a JSON string atom.  In the response, `data` is the hex serialization of the map response. Note that map responses are Clarity option types, for non-existent values, this is a serialized none, and for all other responses, it is a serialized (some ...) object. 
     * Get specific data-map inside a contract
     */
    async getContractDataMapEntry(requestParameters: GetContractDataMapEntryRequest): Promise<MapEntryResponse> {
        const response = await this.getContractDataMapEntryRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get contract events using a contract ID
     * Get contract events
     */
    async getContractEventsByIdRaw(requestParameters: GetContractEventsByIdRequest): Promise<runtime.ApiResponse<object>> {
        if (requestParameters.contractId === null || requestParameters.contractId === undefined) {
            throw new runtime.RequiredError('contractId','Required parameter requestParameters.contractId was null or undefined when calling getContractEventsById.');
        }

        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/contract/{contract_id}/events`.replace(`{${"contract_id"}}`, encodeURIComponent(String(requestParameters.contractId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse<any>(response);
    }

    /**
     * Get contract events using a contract ID
     * Get contract events
     */
    async getContractEventsById(requestParameters: GetContractEventsByIdRequest): Promise<object> {
        const response = await this.getContractEventsByIdRaw(requestParameters);
        return await response.value();
    }

    /**
     * Get contract interface using a `contract_address` and `contract name`
     * Get contract interface
     */
    async getContractInterfaceRaw(requestParameters: GetContractInterfaceRequest): Promise<runtime.ApiResponse<ContractInterfaceResponse>> {
        if (requestParameters.contractAddress === null || requestParameters.contractAddress === undefined) {
            throw new runtime.RequiredError('contractAddress','Required parameter requestParameters.contractAddress was null or undefined when calling getContractInterface.');
        }

        if (requestParameters.contractName === null || requestParameters.contractName === undefined) {
            throw new runtime.RequiredError('contractName','Required parameter requestParameters.contractName was null or undefined when calling getContractInterface.');
        }

        const queryParameters: runtime.HTTPQuery = {};

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

        const headerParameters: runtime.HTTPHeaders = {};

        const response = await this.request({
            path: `/v2/contracts/interface/{contract_address}/{contract_name}`.replace(`{${"contract_address"}}`, encodeURIComponent(String(requestParameters.contractAddress))).replace(`{${"contract_name"}}`, encodeURIComponent(String(requestParameters.contractName))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

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

    /**
     * Get contract interface using a `contract_address` and `contract name`
     * Get contract interface
     */
    async getContractInterface(requestParameters: GetContractInterfaceRequest): Promise<ContractInterfaceResponse> {
        const response = await this.getContractInterfaceRaw(requestParameters);
        return await response.value();
    }

    /**
     * Returns the Clarity source code of a given contract, along with the block height it was published in, and the MARF proof for the data
     * Get contract source
     */
    async getContractSourceRaw(requestParameters: GetContractSourceRequest): Promise<runtime.ApiResponse<ContractSourceResponse>> {
        if (requestParameters.contractAddress === null || requestParameters.contractAddress === undefined) {
            throw new runtime.RequiredError('contractAddress','Required parameter requestParameters.contractAddress was null or undefined when calling getContractSource.');
        }

        if (requestParameters.contractName === null || requestParameters.contractName === undefined) {
            throw new runtime.RequiredError('contractName','Required parameter requestParameters.contractName was null or undefined when calling getContractSource.');
        }

        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/contracts/source/{contract_address}/{contract_name}`.replace(`{${"contract_address"}}`, encodeURIComponent(String(requestParameters.contractAddress))).replace(`{${"contract_name"}}`, encodeURIComponent(String(requestParameters.contractName))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        });

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

    /**
     * Returns the Clarity source code of a given contract, along with the block height it was published in, and the MARF proof for the data
     * Get contract source
     */
    async getContractSource(requestParameters: GetContractSourceRequest): Promise<ContractSourceResponse> {
        const response = await this.getContractSourceRaw(requestParameters);
        return await response.value();
    }

}
