import {
  buildMerkleRoot,
  merkleProofs as coreProofs,
  merkleVerifyValueWei,
  paymentLeafV1Hash,
} from '@dbis/checkpoint-core';

export type LeafInput = {
  txHash: string;
  from: string;
  to: string;
  value: string | bigint;
  nativeValueWei?: string | bigint;
  onChainValueWei?: string | bigint;
  tokenValue?: string | bigint;
  blockNumber: number | string;
  blockTimestamp: number | string;
  gasUsed: string | bigint;
  success: boolean;
};

export function paymentLeafHash(chainId: number, leaf: LeafInput): string {
  return paymentLeafV1Hash(chainId, {
    txHash: String(leaf.txHash),
    from: String(leaf.from),
    to: String(leaf.to),
    value: merkleVerifyValueWei(leaf as Record<string, unknown>),
    blockNumber: leaf.blockNumber,
    blockTimestamp: leaf.blockTimestamp,
    gasUsed: leaf.gasUsed,
    success: leaf.success,
  });
}

export { buildMerkleRoot };

export function merkleProofs(hashes: string[]): { root: string; proofs: string[][] } {
  return coreProofs(hashes);
}
