import type { Outputs, TerminalOutput } from '@lifi/compose-spec';

/**
 * The entries of `outputs` the caller actually receives: every port no later
 * node spends, keyed `<nodeId>.<portName>` as on the wire, and every resource
 * input no node spends, keyed `input.<name>`. Consumed ports (intermediate
 * amounts a later op takes as input) are dropped.
 */
export const terminalOutputs = (
  outputs: Outputs,
): Record<string, TerminalOutput> =>
  Object.fromEntries(
    Object.entries(outputs).filter(
      (entry): entry is [string, TerminalOutput] =>
        entry[1].role === 'terminal',
    ),
  );
