import { CHAINS, type ChainId } from "./chains.ts";
import { isLiquidityPayload, type LiquidityPayload } from "./liquidity.ts";
export type SnapshotSet = Record<ChainId, LiquidityPayload>;
export function isSnapshotSet(value: unknown): value is SnapshotSet {
  if (!value || typeof value !== "object") return false;
  return CHAINS.every(chain => {
    const data = (value as SnapshotSet)[chain.id];
    return isLiquidityPayload(data) && data.chainId === chain.id && data.nodes.every(node => node.id.startsWith(`${chain.network}_`));
  });
}
export function mergeSnapshots(current: SnapshotSet, incoming: Partial<SnapshotSet>): SnapshotSet {
  return Object.fromEntries(CHAINS.map(({ id }) => [id, incoming[id] && Date.parse(incoming[id]!.updatedAt) >= Date.parse(current[id].updatedAt) ? incoming[id] : current[id]])) as SnapshotSet;
}
