/**
 * Generated by orval v7.6.0 🍺
 * Do not edit manually.
 * Coinbase Developer Platform APIs
 * The Coinbase Developer Platform APIs - leading the world's transition onchain.
 * OpenAPI spec version: 2.0.0
 */
import type {
  AccountTokenAddressesResponse,
  ListDataTokenBalances200,
  ListDataTokenBalancesParams,
  ListEvmTokenBalancesNetwork,
  OnchainDataQuery,
  OnchainDataResult,
} from "../coinbaseDeveloperPlatformAPIs.schemas.js";

import { cdpApiClient } from "../../cdpApiClient.js";

type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];

/**
 * Run a read-only SQL query against indexed blockchain data including transactions, events, and decoded logs.

This endpoint provides direct SQL access to comprehensive blockchain data across supported networks.
Queries are executed against optimized data structures for high-performance analytics.

### Allowed Queries

  - Standard SQL syntax (ClickHouse dialect)
  - Read-only queries (SELECT statements)
  - No DDL or DML operations
  - No cartesian products

### Supported Tables

  - `base.events` - Base mainnet decoded event logs with parameters, event signature, topics, and more.
  - `base.transactions` - Base mainnet transaction data including hash, block number, gas usage.
  - `base.blocks` - Base mainnet block information.
  - `base.encoded_logs` - Encoded log data of event logs that aren't able to be decoded by our event decoder (ex: log0 opcode).
  - `base.transfers` - All event logs with event signature `Transfer(address,address,uint256)`. ERC-20, ERC-721, and ERC-1155 transfers are all included.

### Query Limits

  - Maximum result set: 10,000 rows
  - Query timeout: 30 seconds
  - Maximum JOINs: 5

 * @summary Run SQL Query
 */
export const runSQLQuery = (
  onchainDataQuery: OnchainDataQuery,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<OnchainDataResult>(
    {
      url: `/v2/data/query/run`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: onchainDataQuery,
    },
    options,
  );
};
/**
 * Retrieve all ERC-20 token contract addresses that an account has ever received tokens from. 
Analyzes transaction history to discover token interactions.

 * @summary List token addresses for account
 */
export const listTokensForAccount = (
  network: "base" | "base-sepolia",
  address: string,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<AccountTokenAddressesResponse>(
    { url: `/v2/data/evm/token-ownership/${network}/${address}`, method: "GET" },
    options,
  );
};
/**
 * Lists the token balances of an EVM address on a given network. The balances include ERC-20 tokens and the native gas token (usually ETH). The response is paginated, and by default, returns 20 balances per page.

**Note:** This endpoint provides <1 second freshness from chain tip, <500ms response latency for wallets with reasonable token history, and 99.9% uptime for production use.
 * @summary List EVM token balances
 */
export const listDataTokenBalances = (
  network: ListEvmTokenBalancesNetwork,
  address: string,
  params?: ListDataTokenBalancesParams,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<ListDataTokenBalances200>(
    { url: `/v2/data/evm/token-balances/${network}/${address}`, method: "GET", params },
    options,
  );
};
export type RunSQLQueryResult = NonNullable<Awaited<ReturnType<typeof runSQLQuery>>>;
export type ListTokensForAccountResult = NonNullable<
  Awaited<ReturnType<typeof listTokensForAccount>>
>;
export type ListDataTokenBalancesResult = NonNullable<
  Awaited<ReturnType<typeof listDataTokenBalances>>
>;
