// Shared TypeScript types matching the Go server's API contracts.

export interface RouterEvent {
  id: string
  router_id: string
  hostname?: string
  event_type: string
  timestamp: string
  payload: Record<string, unknown>
  received_at: string
  connection: string
}

export interface RouterInfo {
  id: string
  last_seen: string
  online: boolean
  queued_commands: number
}

export interface CommandRecord {
  id: string
  router_id: string
  command: string
  args: Record<string, string> | null
  issued_by: string
  status: 'pending' | 'queued' | 'delivered' | 'completed' | 'timeout' | 'publish_failed'
  result?: { success: boolean; output: string; error: string }
  ts: string
}

export interface Alert {
  id: number
  router_id: string
  kind: string
  message: string
  created_at: string
  acknowledged_at?: string
}

export interface MetricsBucket {
  ts: string
  events_total: number
  commands_total: number
  commands_ok: number
  commands_fail: number
  events_by_type: Record<string, number>
}

export interface MetricsResponse {
  summary: {
    events_last_5min: number
    events_this_min: number
    commands_this_min: number
  }
  buckets: MetricsBucket[]
  since: string
}

export interface HealthResponse {
  status: string
  routers: number
  routers_online: number
  redpanda: string[]
  version: string
}

export interface LoginResponse {
  token: string
  role: string
  expires: string
}

export interface MeResponse {
  user_id: number
  username: string
  role: 'system_admin' | 'project_admin' | 'user'
  expires: number
}
