// @searchx402/sdk v0.1.0 - TypeScript Definitions
// Usage: /// <reference types="https://searchx402.com/sdk/index.d.ts" />

import { Context, Hono } from 'hono';

type PaymentNetwork = 'base' | 'base-sepolia' | 'ethereum' | 'polygon';
type PaymentCurrency = 'USDC' | 'ETH';

interface PaymentReceipt {
  txHash: string;
  network: PaymentNetwork;
  amount: string;
  currency: PaymentCurrency;
  payer: string;
  payee: string;
  timestamp: number;
  signature?: string;
}

interface PaymentRequirement {
  price: number;
  wallet: string;
  networks: PaymentNetwork[];
  currency: PaymentCurrency;
  description?: string;
  resource?: string;
}

interface X402ToolConfig<E extends Record<string, unknown> = Record<string, unknown>> {
  name: string;
  description?: string;
  price: number;
  wallet: string;
  networks?: PaymentNetwork[];
  currency?: PaymentCurrency;
  handler: (request: Request, env: E, ctx: ExecutionContext) => Promise<unknown | Response>;
  verifyPayment?: (receipt: PaymentReceipt, expected: PaymentRequirement) => Promise<boolean>;
  onPayment?: (receipt: PaymentReceipt, request: Request, env: E) => Promise<void>;
  rateLimit?: { limit: number; window: number };
  cors?: boolean;
  routes?: Array<{ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; path: string; handler: (c: Context<{ Bindings: E }>) => Promise<Response> | Response }>;
}

interface VerificationResult { valid: boolean; error?: string; receipt?: PaymentReceipt; }
interface X402ResponseOptions { payment: PaymentRequirement; headers?: Record<string, string>; body?: string | object; }

declare function createX402Tool<E extends Record<string, unknown> = Record<string, unknown>>(config: X402ToolConfig<E>): Hono<{ Bindings: E }>;
declare class X402Response extends Response {
  constructor(options: X402ResponseOptions);
  static fromRequirement(requirement: PaymentRequirement): X402Response;
  static forPrice(price: number, wallet: string, description?: string): X402Response;
}
declare function jsonResponse(data: unknown, status?: number): Response;
declare function errorResponse(message: string, status?: number, details?: Record<string, unknown>): Response;
declare function parsePaymentReceipt(header: string | null): PaymentReceipt | null;
declare function encodePaymentReceipt(receipt: PaymentReceipt): string;
declare function toUsdcUnits(amount: number): string;
declare function fromUsdcUnits(amount: string): number;
declare function verifyPayment(receipt: PaymentReceipt, expected: PaymentRequirement): Promise<VerificationResult>;
declare function createBlockchainVerifier(rpcUrl: string): (receipt: PaymentReceipt, expected: PaymentRequirement) => Promise<boolean>;
declare function generateRequestId(): string;

export { PaymentCurrency, PaymentNetwork, PaymentReceipt, PaymentRequirement, VerificationResult, X402Response, X402ResponseOptions, X402ToolConfig, createBlockchainVerifier, createX402Tool, encodePaymentReceipt, errorResponse, fromUsdcUnits, generateRequestId, jsonResponse, parsePaymentReceipt, toUsdcUnits, verifyPayment };
