import type { CheckpointHeaderStruct } from '../eip712';
import type { CanonicalPaymentMessage } from '@dbis/checkpoint-core';

export type PaymentLeaf = {
  txHash: string;
  from: string;
  to: string;
  value: bigint;
  blockNumber: number;
  blockTimestamp: number;
  gasUsed: bigint;
  success: boolean;
  token?: string;
  tokenSymbol?: string;
  tokenDecimals?: number;
  tokenValue?: bigint;
  tokenLogIndex?: number;
  /** Off-chain USD metadata (not in Merkle leaf). */
  valueUsd?: string;
  nativeValueUsd?: string;
  tokenValueUsd?: string;
  nativePriceUsd?: number;
  tokenPriceUsd?: number;
  priceSource?: string;
  priceEffectiveTimestamp?: string;
  totalTransfersUsd?: string;
  transfers?: Array<Record<string, unknown>>;
  usdEnrichedAt?: string;
  logCount?: number;
  receiptHash?: string;
  /** MT-103 / pacs.008 equivalent (canonical); attached before batch publish. */
  iso20022?: CanonicalPaymentMessage;
};

/** Production default: hashes + IPFS (official submitCheckpoint). */
export type SubmitMode = 'hashes' | 'commitment' | 'leaves' | 'leaves-v2';

export type FlushContext = {
  header: CheckpointHeaderStruct;
  leaves: PaymentLeaf[];
  txHashes: string[];
  extensionData: string;
  contentURI: string;
  validatorSignatures?: string;
};

export interface CheckpointIngress {
  readonly mode: SubmitMode;
  submit(ctx: FlushContext): Promise<{ hash: string }>;
}
