import { CHECK_TRAIT_ACTION_REQUIRED, CHECK_TRAIT_MANUAL, CHECK_TRAIT_WARNING, } from "@getpaseo/protocol/check-traits"; export interface PresentableCheck { status: string; traits?: readonly string[]; } export const COUNTED_CHECK_PRESENTATIONS = [ "success", "failure", "warning", "actionRequired", "manual", "pending", ] as const; export type CountedCheckPresentation = (typeof COUNTED_CHECK_PRESENTATIONS)[number]; export type CheckPresentation = CountedCheckPresentation | "ignored"; export const ATTENTION_CHECK_PRESENTATIONS = [ "failure", "warning", "actionRequired", ] as const satisfies readonly CountedCheckPresentation[]; export type CheckPresentationCounts = Record; export function classifyCheck(check: PresentableCheck): CheckPresentation { const traits = check.traits ?? []; if (traits.includes(CHECK_TRAIT_ACTION_REQUIRED)) return "actionRequired"; if (traits.includes(CHECK_TRAIT_WARNING)) return "warning"; if (traits.includes(CHECK_TRAIT_MANUAL)) return "manual"; if (check.status === "success") return "success"; if (check.status === "failure") return "failure"; if (check.status === "skipped" || check.status === "cancelled") return "ignored"; return "pending"; } export function countCheckPresentations( checks: readonly PresentableCheck[], ): CheckPresentationCounts { const counts: CheckPresentationCounts = { success: 0, failure: 0, warning: 0, actionRequired: 0, manual: 0, pending: 0, }; for (const check of checks) { const presentation = classifyCheck(check); if (presentation !== "ignored") counts[presentation] += 1; } return counts; }