type Status = "running" | "stopped" | "error" | "unknown" const flags = ["running", "stopped", "error", "failed", "extracting", "downloading", "starting", "stopping"] as const /** RouterOS REST can expose active flags instead of the legacy status field. */ export function containerRuntimeStatus(row: Record): Status { const active = new Set() for (const flag of flags) { const value = row[flag] if (value === undefined) continue if (value === true || value === "true" || value === "yes") active.add(flag) else if (value !== false && value !== "false" && value !== "no") return "unknown" } if (["extracting", "downloading", "starting", "stopping"].some(flag => active.has(flag))) return "unknown" const states: Status[] = [] if (active.has("running")) states.push("running") if (active.has("stopped")) states.push("stopped") if (active.has("error") || active.has("failed")) states.push("error") if (states.length > 1) return "unknown" if (row.status !== undefined) { if (typeof row.status !== "string") return "unknown" const value = row.status.toLowerCase() const legacy = value === "running" || value === "stopped" ? value : value === "error" || value === "failed" ? "error" : "unknown" if (legacy === "unknown" || (states.length && states[0] !== legacy)) return "unknown" return legacy } return states[0] ?? "unknown" }