import type { ValveIsolationResult } from "./types";

export const isAllowedAccidentPipe = (
  pipeId: string,
  allowedPipeIds: string[] | undefined,
) => allowedPipeIds === undefined || allowedPipeIds.includes(pipeId);

export const getAffectedNodeCount = (result: ValveIsolationResult) =>
  result.affected_node_count ?? result.affected_nodes?.length ?? 0;

export const normalizeValveIsolationResult = (
  result: ValveIsolationResult,
): ValveIsolationResult => ({
  ...result,
  affected_nodes: result.isolatable ? result.affected_nodes ?? [] : [],
  affected_node_count: getAffectedNodeCount(result),
});
