// Types aligned with the actual API response from /api/stats/overview
export interface OverviewStats {
  containers: {
    total: number;
    running?: number;
    endpoints?: Record<string, { total: number; running: number; error?: boolean }>;
    by_endpoint?: Record<string, { total: number; running: number; error?: boolean }>;
  };
  gpu: {
    available: boolean;
    name?: string;
    temp_c?: number;
    // API may use either naming convention
    power_w?: number;
    power_draw_w?: number;
    power_limit_w?: number;
    vram_used_mb?: number;
    vram_total_mb?: number;
    memory_used_mb?: number;
    memory_total_mb?: number;
    utilization_pct?: number;
  };
  // API returns either a number or {gmail, dvish, proton, total}
  emails_today?: number | Record<string, number>;
  email_today?: number | Record<string, number>;
  alerts?: number;
  unhealthy_count?: number;
  // API returns either an object or a boolean
  ollama?: { available: boolean; url: string };
  ollama_available?: boolean;
  hosts_online?: number;
}

export interface ActivityEvent {
  type: string;
  timestamp: string;
  source: string;
  raw: string;
  [key: string]: unknown;
}

export interface Container {
  id: string;
  name: string;
  image: string;
  state: string;
  status: string;
  endpoint: string;
  error?: string;
}

export interface JellyfinStatus {
  version: string;
  server_name: string;
  libraries: { name: string; type: string; paths: string[] }[];
  active_sessions: {
    user: string;
    device: string;
    client: string;
    title: string;
    type: string;
  }[];
  idle_sessions: number;
}

export interface EmailStats {
  accounts: {
    account: string;
    today: number;
    categories: Record<string, number>;
  }[];
  sender_cache: Record<string, number>;
}

export interface ExpenseSummary {
  month: string;
  total: number;
  count: number;
  top_vendors: { vendor: string; amount: number }[];
}

export interface HealthScore {
  score: number;
  grade: string;
  details: { name: string; score: number; max: number; status: string }[];
}

export interface KumaMonitor {
  id: number;
  name: string;
  url?: string;
  type: string;
  active: boolean;
  status: boolean; // true = up
  parent?: number;
}

export interface KumaStats {
  monitors: KumaMonitor[];
  total: number;
  up: number;
  down: number;
}

export interface JellyfinLatestItem {
  name: string;
  type: string;
  series?: string;
  date: string;
  year?: number;
}

export interface ArrHistoryItem {
  title: string;
  event: string;
  date: string;
  quality: string;
}

export interface CloudflareStats {
  total: number;
  proxied: number;
  dns_only: number;
  types: Record<string, number>;
}

export interface AuthentikStats {
  active_sessions: number;
  users?: { username: string; last_login: string; active: boolean }[];
  sessions?: { user: string; last_used?: string }[];
  recent_events?: { action: string; user?: string; created?: string; timestamp?: string }[];
}

export interface GiteaActivity {
  commits: { sha: string; message: string; author: string; date: string }[];
  open_prs: { title: string; number: number; author: string }[];
}

export interface AutomationTimelineEntry {
  name: string;
  last_run: string;
  exists: boolean;
}

export interface DiskUsageEntry {
  host: string;
  mount: string;
  total_gb: number;
  avail_gb: number;
  used_pct: number;
}
