// What the UI shows. WORKING / SLOW / NOT_WORKING come from the latest health
// check; the other two are derived and never stored.
export type HealthStatus = "WORKING" | "SLOW" | "NOT_WORKING";
export type DisplayStatus = HealthStatus | "DISABLED" | "PENDING";

export const STATUS_LABELS: Record<DisplayStatus, string> = {
  WORKING: "Working",
  SLOW: "Slow Response",
  NOT_WORKING: "Not Working",
  DISABLED: "Monitoring Disabled",
  PENDING: "Not checked yet",
};

/** Short hint shown next to the label where there is room. */
export const STATUS_HINTS: Partial<Record<DisplayStatus, string>> = {
  SLOW: "Responded, but slower than the slow-response threshold",
};

// Filter tabs / URL params, in display order. Problems first.
export const DISPLAY_STATUSES: DisplayStatus[] = ["NOT_WORKING", "SLOW", "PENDING", "WORKING", "DISABLED"];

export function displayStatus(project: { monitoringEnabled: boolean; currentStatus: HealthStatus | null }): DisplayStatus {
  // Disabled wins: a switched-off app is never shown as failed, whatever its last result was.
  if (!project.monitoringEnabled) return "DISABLED";
  return project.currentStatus ?? "PENDING";
}

/** True when the app answered (Working or Slow) — the opposite of an outage. */
export function isUp(status: HealthStatus): boolean {
  return status !== "NOT_WORKING";
}
