// TypeScript definitions for minia2a SDK

export interface CaptchaOptions {
  sitekey: string;
  url: string;
  type?: 'v2' | 'v3' | 'enterprise' | 'hcaptcha' | 'turnstile';
}
export interface CaptchaResult { ok: boolean; token: string; taskId?: number; solvedIn?: string; type?: string; }

export interface GasPriceResult {
  base: { gwei: number; usd: number };
  ethereum: { gwei: number; usd: number };
  arbitrum: { gwei: number; usd: number };
  optimism: { gwei: number; usd: number };
  polygon: { gwei: number; usd: number };
}
export function gasPrice(): Promise<GasPriceResult>;

export interface DexPriceOptions { chain?: string; address: string; }
export interface DexPriceResult { price: number; volume24h: number; pools: Array<{ dex: string; price: number; liquidity: number }>; }
export function dexPrice(opts: DexPriceOptions): Promise<DexPriceResult>;

export function tokenSearch(q: string): Promise<Array<{ id: string; name: string; symbol: string; market_cap_rank: number; thumb: string }>>;

export interface WalletIntelOptions { address: string; chain?: string; }
export interface WalletIntelResult { balance: string; usdc: string; nonce: number; isContract: boolean; riskFlags: string[]; }
export function walletIntel(opts: WalletIntelOptions): Promise<WalletIntelResult>;

export function polymarket(opts?: { event?: string }): Promise<any>;

export interface FeeHistoryOptions { blocks?: number; }
export function feeHistory(opts?: FeeHistoryOptions): Promise<any>;

export function chainInfo(): Promise<any>;

export interface FetchPageOptions { url: string; solveCaptcha?: boolean; }
export function fetchPage(opts: FetchPageOptions): Promise<{ url: string; title: string; text: string; hasCaptcha: boolean; captchaSolved: boolean }>;

export interface WebRetrieveOptions { url: string; question: string; }
export function webRetrieve(opts: WebRetrieveOptions): Promise<{ answer: string; steps: string[] }>;

export function summarize(opts: { text: string }): Promise<{ summary: string }>;

export function uuid(opts?: { count?: number }): Promise<{ uuids: string[] }>;
export function base64(opts: { text: string; action?: 'encode' | 'decode' }): Promise<{ result: string }>;
export function hash(opts: { text: string; algo?: 'sha256' | 'md5' }): Promise<{ hash: string; algo: string }>;
export function time(): Promise<{ iso: string; unix: number; unixMs: number; utc: string }>;
export function ipLookup(opts?: { ip?: string }): Promise<{ ip: string; country: string; city: string; isp: string; timezone: string }>;
export function dnsLookup(opts: { domain: string; type?: string }): Promise<any>;
export function jsonValidate(json: string): Promise<{ valid: boolean; type: string; keyCount: number; formatted?: string }>;
export function csvJson(opts: { data: string; direction?: 'csv-to-json' | 'json-to-csv' }): Promise<{ result: string }>;
export function qrCode(opts: { text: string; size?: number }): Promise<{ url: string }>;
export function urlCodec(opts: { text: string; action?: 'encode' | 'decode' }): Promise<{ result: string }>;
export function colorConvert(opts: { color: string }): Promise<{ hex: string; rgb: string; hsl: string }>;
export function markdown(opts: { text: string; format?: 'text' | 'html' }): Promise<{ result: string }>;
export function ensResolve(opts: { name?: string; address?: string }): Promise<{ name?: string; address?: string }>;
export function dateMath(opts: { date?: string; operation?: string; value?: number; unit?: string; timezone?: string }): Promise<{ result: string }>;

export function bounties(): Promise<any>;
export function erc8004Agent(opts: { agentId: number; chain?: string }): Promise<any>;
export function search(opts: { q: string; category?: string }): Promise<any>;
export function recall(opts: { q: string }): Promise<any>;
export function find(opts: { q: string }): Promise<any>;
export function store(opts: { content: string }): Promise<{ ok: boolean; stored: boolean; id: number | null }>;

export function emailCreate(): Promise<{ email: string; password: string }>;
export function emailVerify(opts?: { timeout?: number }): Promise<{ verified: boolean; link?: string }>;

// Catalog (dynamic — never drifts)
export interface ServiceInfo {
  id: string; name: string; category: string; priceCents: number;
  price?: string; endpoint: string; description?: string;
}
export function getCatalog(opts?: { refresh?: boolean }): Promise<Map<string, ServiceInfo>>;
/** Enable the 5-free-call signed trial. `signer` needs signMessage(string) -> hex signature. */
export function useTrial(opts: { wallet?: string; signer?: { signMessage(m: string): Promise<string>; address?: string; getAddress?(): Promise<string> }; privateKey?: string }): Promise<{ wallet: string }>;
/** Disable the trial path; subsequent calls go out unpaid (402). */
export function clearTrial(): void;

export function resolveService(serviceId: string): Promise<ServiceInfo>;
export function call(serviceId: string, opts?: { query?: Record<string, any>; body?: any; method?: string }): Promise<any>;
export function discover(query?: string): Promise<ServiceInfo[]>;

export function listServices(): Promise<Array<{ id: string; name: string; category: string; priceCents: number; endpoint: string }>>;
export function stats(): Promise<any>;

export function captchaSolve(opts: CaptchaOptions): Promise<CaptchaResult>;

export interface RegisterResult {
  ok: boolean;
  name: string;
  wallet: string;
  credits: number;
  privateKey?: string;
  message?: string;
}
export function registerSimple(opts: { name: string; signer?: any }): Promise<RegisterResult>;

export interface PublishOptions {
  name: string;
  endpoint: string;
  priceCents?: number;
  description: string;
  category?: string;
  wallet?: string;
  signer: any;
}
export function publishWithSignature(opts: PublishOptions): Promise<any>;
