/**
 * Shared types for Synor Hardhat Plugin
 */

export * from "./type-extensions";

/**
 * Contract compilation result
 */
export interface CompilationResult {
  contractName: string;
  bytecode: string;
  deployedBytecode: string;
  abi: any[];
  metadata: {
    compiler: {
      version: string;
    };
    language: string;
    output: {
      abi: any[];
      devdoc: any;
      userdoc: any;
    };
    settings: {
      optimizer: {
        enabled: boolean;
        runs: number;
      };
    };
  };
}

/**
 * Contract verification status
 */
export interface VerificationStatus {
  verified: boolean;
  contractName?: string;
  compilerVersion?: string;
  optimizationUsed?: boolean;
  runs?: number;
  constructorArguments?: string;
  sourceCode?: string;
}

/**
 * Synor account information
 */
export interface AccountInfo {
  address: string;
  balance: bigint;
  nonce: number;
  codeHash?: string;
  storageRoot?: string;
}

/**
 * Block information
 */
export interface BlockInfo {
  number: number;
  hash: string;
  parentHash: string;
  timestamp: number;
  miner: string;
  difficulty: bigint;
  gasLimit: bigint;
  gasUsed: bigint;
  baseFeePerGas?: bigint;
  transactions: string[];
  transactionsRoot: string;
  stateRoot: string;
  receiptsRoot: string;
}

/**
 * DAG block information (Synor-specific)
 */
export interface DagBlockInfo extends BlockInfo {
  blueScore: number;
  parents: string[];
  children: string[];
  isBlue: boolean;
  mergeSetBlues: string[];
  mergeSetReds: string[];
}

/**
 * Shard information (Synor-specific)
 */
export interface ShardInfo {
  shardId: number;
  totalShards: number;
  stateRoot: string;
  blockHeight: number;
  validators: string[];
}

/**
 * Cross-shard message
 */
export interface CrossShardMessage {
  id: string;
  fromShard: number;
  toShard: number;
  sender: string;
  recipient: string;
  value: bigint;
  data: string;
  status: "pending" | "delivered" | "confirmed" | "failed";
  timestamp: number;
}

/**
 * Quantum signature information
 */
export interface QuantumSignature {
  algorithm: "dilithium3" | "sphincs+" | "falcon512" | "ed25519+dilithium3";
  publicKey: string;
  signature: string;
}

/**
 * Gas estimation result
 */
export interface GasEstimate {
  gasLimit: bigint;
  gasPrice: bigint;
  maxFeePerGas?: bigint;
  maxPriorityFeePerGas?: bigint;
  estimatedCost: bigint;
}

/**
 * Contract event filter
 */
export interface EventFilter {
  address?: string | string[];
  topics?: (string | string[] | null)[];
  fromBlock?: number | string;
  toBlock?: number | string;
}

/**
 * Parsed contract event
 */
export interface ParsedEvent {
  blockNumber: number;
  blockHash: string;
  transactionHash: string;
  transactionIndex: number;
  logIndex: number;
  address: string;
  event: string;
  args: { [key: string]: any };
  raw: {
    topics: string[];
    data: string;
  };
}

/**
 * Contract call options
 */
export interface CallOptions {
  from?: string;
  gasLimit?: number;
  gasPrice?: bigint;
  value?: bigint;
  blockTag?: number | string;
}

/**
 * Send options
 */
export interface SendOptions extends CallOptions {
  nonce?: number;
  confirmations?: number;
}

/**
 * Contract interaction result
 */
export interface ContractInteractionResult<T = any> {
  transactionHash?: string;
  blockNumber?: number;
  gasUsed?: bigint;
  events?: ParsedEvent[];
  returnValue?: T;
}

/**
 * Deployment configuration
 */
export interface DeploymentConfig {
  contractName: string;
  constructorArgs: any[];
  libraries?: { [name: string]: string };
  proxy?: {
    type: "transparent" | "uups" | "beacon";
    owner?: string;
  };
  deterministicDeployment?: {
    salt: string;
    factory?: string;
  };
}

/**
 * Network fork configuration
 */
export interface ForkConfig {
  jsonRpcUrl: string;
  blockNumber?: number;
  accounts?: {
    mnemonic?: string;
    path?: string;
    count?: number;
  };
}

/**
 * Test fixture
 */
export interface TestFixture<T> {
  (): Promise<T>;
}

/**
 * Deployment result with full metadata
 */
export interface FullDeploymentResult {
  address: string;
  transactionHash: string;
  blockNumber: number;
  gasUsed: bigint;
  deployer: string;
  timestamp: number;
  constructorArgs: any[];
  verified: boolean;
}
