export type WidgetType =
  | "cpu"
  | "memory"
  | "disk"
  | "network"
  | "uptime"
  | "processes"
  | "system"
  | "login_stats"
  | "ports"
  | "firewall"
  | "temperature";

export interface ListeningPort {
  protocol: "tcp" | "udp";
  localAddress: string;
  localPort: number;
  state?: string;
  pid?: number;
  process?: string;
}

export interface PortsMetrics {
  source: "ss" | "netstat" | "none";
  ports: ListeningPort[];
}

export interface FirewallRule {
  chain: string;
  target: string;
  protocol: string;
  source: string;
  destination: string;
  dport?: string;
  sport?: string;
  state?: string;
  interface?: string;
  extra?: string;
}

export interface FirewallChain {
  name: string;
  policy: string;
  rules: FirewallRule[];
}

export interface FirewallMetrics {
  type: "iptables" | "nftables" | "none";
  status: "active" | "inactive" | "unknown";
  chains: FirewallChain[];
}

export interface TemperatureSensor {
  label: string;
  celsius: number;
}

export interface TemperatureMetrics {
  source: "sysfs" | "sensors" | "none";
  highestCelsius: number | null;
  sensors: TemperatureSensor[];
}

export interface StatsConfig {
  enabledWidgets: WidgetType[];
  statusCheckEnabled: boolean;
  statusCheckInterval: number;
  useGlobalStatusInterval?: boolean;
  metricsEnabled: boolean;
  metricsInterval: number;
  useGlobalMetricsInterval?: boolean;
  disableTcpPing?: boolean;
  /** Filesystem mount points to leave out of the disk widget. */
  excludedMounts?: string[];
  /** Extra paths to monitor, including paths inside bind-mounted containers. */
  monitoredMounts?: Array<{ path: string; label?: string }>;
}

export const DEFAULT_STATS_CONFIG: StatsConfig = {
  enabledWidgets: [
    "cpu",
    "memory",
    "disk",
    "network",
    "uptime",
    "system",
    "login_stats",
    "processes",
    "ports",
    "firewall",
    "temperature",
  ],
  statusCheckEnabled: true,
  statusCheckInterval: 30,
  useGlobalStatusInterval: true,
  metricsEnabled: true,
  metricsInterval: 30,
  useGlobalMetricsInterval: true,
  disableTcpPing: false,
};
