/**
 * Soft warnings (issue #253)
 *
 * Cross-cutting helper for non-blocking, advisory messages surfaced in the
 * UI. The first use case is the "out-of-order" warning shown above the
 * Instruct-measure form when a deal already has technical-approved
 * measures: instructing a new measure at that point is unusual and the
 * approver should pause before doing it.
 *
 * Kept deliberately small and stateless so later slices (e.g. PIBI flow,
 * lodgement guards) can reuse it. The shape is `(deal) => string | null`
 * so callers can render the warning verbatim or fold it into a list.
 */
import { parseMeasures } from "@/app/lib/parseMeasures";

export interface OutOfOrderInstructionDealLike {
  technicalApprovedMeasuresForInstall?: string | null;
}

/**
 * Soft warning shown above the Instruct-measure form when the deal has
 * already moved into the technical-approved phase. Returns `null` when
 * there are no technical-approved measures (i.e. the instruction is in
 * order).
 */
export function outOfOrderInstructionWarning(
  deal: OutOfOrderInstructionDealLike,
): string | null {
  const measures = parseMeasures(deal.technicalApprovedMeasuresForInstall);
  if (measures.length === 0) return null;
  return (
    "This deal already has technical-approved measures for install. " +
    "Instructing a new measure now is out of the usual order — confirm " +
    "with the coordinator before proceeding."
  );
}
