// Getrennt von logFeed.ts, damit Client-Komponenten (LogFilters, LogList)
// diese Konstanten/Typen importieren können, ohne Mongoose in den Browser-
// Bundle zu ziehen — gleiches Muster wie permissions.ts vs. models/Client.ts.

export const LOG_CATEGORIES = ["error", "warn", "info", "team", "orders", "todos", "notifications", "qm"] as const;
export type LogCategory = (typeof LOG_CATEGORIES)[number];

export const LOG_CATEGORY_LABELS: Record<LogCategory, string> = {
  error: "Fehler",
  warn: "Warnungen",
  info: "System-Info",
  team: "Team",
  orders: "Aufträge",
  todos: "ToDos",
  notifications: "Benachrichtigungen",
  qm: "QM & Personal",
};

export const LOG_CATEGORY_COLORS: Record<LogCategory, string> = {
  error: "#f87171",
  warn: "#fbbf24",
  info: "#38bdf8",
  team: "#c98a4b",
  orders: "#a78bfa",
  todos: "#34d399",
  notifications: "#94a3b8",
  qm: "#f472b6",
};

export const LOG_RANGES = ["24h", "7d", "30d", "90d"] as const;
export type LogRange = (typeof LOG_RANGES)[number];

export const LOG_RANGE_LABELS: Record<LogRange, string> = {
  "24h": "24 Stunden",
  "7d": "7 Tage",
  "30d": "30 Tage",
  "90d": "90 Tage",
};

export function normalizeRange(raw: unknown): LogRange {
  return (LOG_RANGES as readonly string[]).includes(raw as string) ? (raw as LogRange) : "7d";
}

export function normalizeCategory(raw: unknown): LogCategory | "all" {
  return (LOG_CATEGORIES as readonly string[]).includes(raw as string) ? (raw as LogCategory) : "all";
}

export type LogRow = {
  id: string;
  ts: string;
  category: LogCategory;
  actor: string;
  title: string;
  detail: string;
  route: string;
  stack: string;
  meta: Record<string, string>;
};
