/**
 * TypeScript types for Synor Explorer API.
 * These types match the backend API response structures (camelCase).
 */

export interface NetworkStats {
  networkId: string;
  isSynced: boolean;
  blockCount: number;
  headerCount: number;
  tipCount: number;
  virtualDaaScore: number;
  difficulty: number;
  hashrate: number;
  hashrateHuman: string;
  blockRate: number;
  mempoolSize: number;
  peerCount: number;
  circulatingSupply: number;
  circulatingSupplyHuman: string;
  maxSupply: number;
}

export interface ExplorerBlock {
  hash: string;
  version: number;
  parentHashes: string[];
  timestamp: number;
  timestampHuman: string;
  bits: number;
  nonce: number;
  daaScore: number;
  blueScore: number;
  blueWork: string;
  difficulty: number;
  transactionCount: number;
  isChainBlock: boolean;
  transactions?: ExplorerTransaction[];
  childrenHashes: string[];
  mergeSetBlues: string[];
  mergeSetReds: string[];
}

export interface ExplorerTransaction {
  id: string;
  hash: string;
  version: number;
  inputs: ExplorerInput[];
  outputs: ExplorerOutput[];
  lockTime: number;
  mass: number;
  isCoinbase: boolean;
  totalInput: number;
  totalOutput: number;
  fee: number;
  blockHash?: string;
  blockTime?: number;
}

export interface ExplorerInput {
  previousTxId: string;
  previousIndex: number;
  address?: string;
  value?: number;
}

export interface ExplorerOutput {
  value: number;
  valueHuman: string;
  scriptType: string;
  address?: string;
}

export interface AddressInfo {
  address: string;
  balance: number;
  balanceHuman: string;
  utxoCount: number;
  totalReceived: number;
  totalSent: number;
  transactionCount: number;
}

export interface UTXO {
  outpoint: {
    transactionId: string;
    index: number;
  };
  utxoEntry: {
    amount: number;
    scriptPublicKey: {
      version: number;
      script: string;
    };
    blockDaaScore: number;
    isCoinbase: boolean;
  };
}

export interface DagVisualization {
  blocks: DagBlock[];
  edges: DagEdge[];
}

export interface DagBlock {
  hash: string;
  shortHash: string;
  blueScore: number;
  isBlue: boolean;
  isChainBlock: boolean;
  timestamp: number;
  txCount: number;
}

export interface DagEdge {
  from: string;
  to: string;
  isSelectedParent: boolean;
}

export interface PaginatedResponse<T> {
  data: T[];
  page: number;
  limit: number;
  total: number;
  totalPages: number;
  hasNext: boolean;
  hasPrev: boolean;
}

export interface SearchResult {
  resultType: 'block' | 'transaction' | 'address';
  value: string;
  redirectUrl: string;
}

export interface ApiError {
  error: string;
  code: number;
}

export interface HealthStatus {
  healthy: boolean;
  rpcConnected: boolean;
}

// Gas Estimation Types
export interface GasEstimateRequest {
  /** Contract address to call */
  to: string;
  /** Sender address (optional) */
  from?: string;
  /** Call data (hex encoded) */
  data?: string;
  /** Value to send in sompi */
  value?: number;
}

export interface GasEstimateResponse {
  /** Estimated gas usage */
  gasUsed: number;
  /** Recommended gas limit (with 20% buffer) */
  gasLimitRecommended: number;
  /** Estimated fee in sompi */
  estimatedFee: number;
  /** Human-readable fee */
  estimatedFeeHuman: string;
}

export interface GasCosts {
  /** Transfer between addresses */
  transfer: number;
  /** Contract deployment base cost */
  contractDeployBase: number;
  /** Contract call base cost */
  contractCallBase: number;
  /** Storage operations */
  storage: {
    sstore: number;
    sload: number;
  };
  /** Memory operations */
  memory: {
    perWord: number;
  };
  /** Signature verification */
  signature: {
    ed25519: number;
    dilithium: number;
  };
}
