/**
 * Synor RPC SDK Types
 */

/** RPC SDK configuration */
export interface RpcConfig {
  /** API key for authentication */
  apiKey: string;
  /** HTTP API endpoint */
  endpoint?: string;
  /** WebSocket endpoint for subscriptions */
  wsEndpoint?: string;
  /** Network type */
  network?: 'mainnet' | 'testnet';
  /** Request timeout in milliseconds */
  timeout?: number;
  /** Enable debug logging */
  debug?: boolean;
}

/** Transaction status */
export type TransactionStatus = 'pending' | 'confirmed' | 'failed' | 'replaced';

/** Transaction priority */
export type Priority = 'low' | 'medium' | 'high' | 'urgent';

/** Subscription type */
export type SubscriptionType = 'blocks' | 'transactions' | 'address' | 'mempool';

/** Block header */
export interface BlockHeader {
  /** Block hash */
  hash: string;
  /** Block height */
  height: number;
  /** Block version */
  version: number;
  /** Previous block hash */
  previousHash: string;
  /** Merkle root */
  merkleRoot: string;
  /** Block timestamp */
  timestamp: number;
  /** Difficulty target */
  difficulty: string;
  /** Nonce */
  nonce: number;
}

/** Full block */
export interface Block extends BlockHeader {
  /** Transaction hashes */
  transactions: string[];
  /** Block size in bytes */
  size: number;
  /** Block weight */
  weight: number;
  /** Transaction count */
  txCount: number;
}

/** Transaction input */
export interface TxInput {
  /** Previous transaction hash */
  txid: string;
  /** Output index */
  vout: number;
  /** Script signature */
  scriptSig: string;
  /** Sequence number */
  sequence: number;
}

/** Transaction output */
export interface TxOutput {
  /** Amount */
  value: string;
  /** Output index */
  n: number;
  /** Script pubkey */
  scriptPubKey: {
    asm: string;
    hex: string;
    type: string;
    addresses?: string[];
  };
}

/** Transaction */
export interface Transaction {
  /** Transaction hash */
  txid: string;
  /** Block hash (if confirmed) */
  blockHash?: string;
  /** Block height (if confirmed) */
  blockHeight?: number;
  /** Number of confirmations */
  confirmations: number;
  /** Block timestamp */
  timestamp?: number;
  /** Transaction status */
  status: TransactionStatus;
  /** Raw transaction hex */
  raw?: string;
  /** Transaction size */
  size: number;
  /** Transaction fee */
  fee: string;
  /** Inputs */
  inputs: TxInput[];
  /** Outputs */
  outputs: TxOutput[];
}

/** Fee estimate */
export interface FeeEstimate {
  /** Priority level */
  priority: Priority;
  /** Fee rate (satoshis per byte) */
  feeRate: string;
  /** Estimated blocks until confirmation */
  estimatedBlocks: number;
}

/** Chain information */
export interface ChainInfo {
  /** Chain name */
  chain: string;
  /** Network name */
  network: string;
  /** Current block height */
  height: number;
  /** Best block hash */
  bestBlockHash: string;
  /** Current difficulty */
  difficulty: string;
  /** Median time */
  medianTime: number;
  /** Chain work */
  chainWork: string;
  /** Syncing status */
  syncing: boolean;
  /** Sync progress (0-1) */
  syncProgress: number;
}

/** Mempool information */
export interface MempoolInfo {
  /** Number of transactions */
  size: number;
  /** Total size in bytes */
  bytes: number;
  /** Memory usage */
  usage: number;
  /** Maximum mempool size */
  maxMempool: number;
  /** Minimum fee for relay */
  minFee: string;
}

/** UTXO */
export interface UTXO {
  /** Transaction hash */
  txid: string;
  /** Output index */
  vout: number;
  /** Amount */
  amount: string;
  /** Address */
  address: string;
  /** Confirmations */
  confirmations: number;
  /** Script pubkey */
  scriptPubKey: string;
}

/** Subscription */
export interface Subscription {
  /** Subscription ID */
  id: string;
  /** Subscription type */
  type: SubscriptionType;
  /** Creation timestamp */
  createdAt: number;
  /** Unsubscribe function */
  unsubscribe: () => void;
}

/** Block notification */
export interface BlockNotification {
  type: 'block';
  block: Block;
}

/** Transaction notification */
export interface TransactionNotification {
  type: 'transaction';
  transaction: Transaction;
  address?: string;
}

/** Notification types */
export type Notification = BlockNotification | TransactionNotification;
