export interface SimulationResult {
  success: boolean;
  gas_estimate?: string;
  revert_reason?: string;
}

export interface DecodedParam {
  name: string;
  sol_type: string;
  value: string;
}

export interface CalldataWarningUnlimitedApproval {
  type: "unlimited_approval";
  spender: string;
}

export interface CalldataWarningApprovalForAll {
  type: "approval_for_all";
  operator: string;
}

export type CalldataWarning =
  | CalldataWarningUnlimitedApproval
  | CalldataWarningApprovalForAll;

export interface TokenMeta {
  symbol: string;
  decimals: number;
}

export interface DecodedCalldata {
  selector: string;
  signature: string;
  function_name: string;
  params: DecodedParam[];
  warnings?: CalldataWarning[];
  abi_verified?: boolean;
  token_meta?: TokenMeta;
}

export interface SigningRequest {
  id: string;
  type: "signing_request";
  method: string;
  params: unknown;
  simulation?: SimulationResult;
  decoded_calldata?: DecodedCalldata;
}

export interface SigningResponseSuccess {
  id: string;
  type: "signing_response";
  result: string;
}

export interface SigningResponseError {
  id: string;
  type: "signing_response";
  error: { code: number; message: string };
}

export type SigningResponse = SigningResponseSuccess | SigningResponseError;

export interface AccountConnected {
  type: "account_connected";
  address: string;
}

export interface AccountDisconnected {
  type: "account_disconnected";
}

export type OutboundMessage =
  | SigningResponse
  | AccountConnected
  | AccountDisconnected;

export type PendingRequest = SigningRequest & {
  receivedAt: number;
};

// Decoded transaction params for display
export interface TransactionParams {
  from?: string;
  to?: string;
  value?: string;
  data?: string;
  input?: string; // geth/forge use `input` instead of `data`
  gas?: string;
  gasPrice?: string;
  maxFeePerGas?: string;
  maxPriorityFeePerGas?: string;
  nonce?: string;
  chainId?: string;
  type?: string;
  [key: string]: string | undefined;
}
