// Shared formatting for checklist incident-event messages (sc-33251). // The client owns the checklist item fields (name, neris_benchmark) preserved // on the incident at create time and sent in the event opts; every service // that renders a checklist event message should build it with these helpers. export interface ChecklistItemEvent { name?: unknown; neris_benchmark?: unknown; } function eventString(value: unknown): string { return typeof value === "string" ? value : ""; } export function nerisBenchmarkLabel(nerisKey: string): string { return nerisKey .split(/[_\s]+/) .filter((word) => word !== "") .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(" "); } // checklistItemChange: "Checked"/"Unchecked", with the item name and an // optional NERIS suffix when the event carries them. export function buildChecklistMessage(checked: boolean, checklistItemEvent?: ChecklistItemEvent | null): string { const prefix = checked ? "Checked" : "Unchecked"; const name = eventString(checklistItemEvent?.name); const nerisKey = eventString(checklistItemEvent?.neris_benchmark); if (name === "") { return prefix; } if (nerisKey !== "") { return `${prefix}: ${name} (NERIS: ${nerisBenchmarkLabel(nerisKey)})`; } return `${prefix}: ${name}`; } // incidentChecklistAddRemoved: "Added checklist"/"Removed checklist", with // the checklist name when the event carries it. export function buildIncidentChecklistMessage(addToIncident: boolean, checklistItemEvent?: ChecklistItemEvent | null): string { const prefix = addToIncident ? "Added checklist" : "Removed checklist"; const name = eventString(checklistItemEvent?.name); if (name === "") { return prefix; } return `${prefix}: ${name}`; }