export const glancesDomain = 'glances';
export const glancesDefaultHost = 'localhost';
export const glancesDefaultPort = 61208;
export const glancesDefaultTimeoutMs = 10000;
export const glancesDefaultScanIntervalMs = 60000;

export type TGlancesApiVersion = 3 | 4;
export type TGlancesSnapshotSource = 'http' | 'manual' | 'snapshot' | 'runtime';
export type TGlancesSensorCategory =
  | 'cpu'
  | 'memory'
  | 'disk'
  | 'network'
  | 'load'
  | 'temperature'
  | 'process'
  | 'container'
  | 'gpu'
  | 'raid'
  | 'system'
  | 'other';

export type TGlancesSensorValue = string | number | boolean | null;

export interface IGlancesConfig {
  host?: string;
  port?: number;
  ssl?: boolean;
  verifySsl?: boolean;
  username?: string;
  password?: string;
  timeoutMs?: number;
  name?: string;
  uniqueId?: string;
  apiVersion?: TGlancesApiVersion;
  version?: TGlancesApiVersion;
  snapshot?: IGlancesSnapshot;
  rawData?: IGlancesRawData;
  allData?: IGlancesRawData;
  haSensorData?: IGlancesHaSensorData;
  sensorData?: IGlancesHaSensorData;
  online?: boolean;
}

export interface IHomeAssistantGlancesConfig extends IGlancesConfig {}

export interface IGlancesHostInfo {
  id?: string;
  name?: string;
  host?: string;
  port?: number;
  ssl?: boolean;
  apiVersion?: TGlancesApiVersion;
  hostname?: string;
  osName?: string;
  platform?: string;
  version?: string;
}

export interface IGlancesSensorState {
  key: string;
  name: string;
  category: TGlancesSensorCategory;
  value: TGlancesSensorValue;
  unit?: string;
  label?: string;
  deviceClass?: string;
  stateClass?: string;
  entityCategory?: string;
  available: boolean;
  attributes?: Record<string, unknown>;
}

export interface IGlancesSnapshot {
  host: IGlancesHostInfo;
  sensorData: IGlancesHaSensorData;
  sensors: IGlancesSensorState[];
  rawData?: IGlancesRawData;
  online: boolean;
  updatedAt?: string;
  source?: TGlancesSnapshotSource;
  apiVersion?: TGlancesApiVersion;
  error?: string;
}

export interface IGlancesRefreshResult {
  success: boolean;
  snapshot?: IGlancesSnapshot;
  error?: string;
  data?: Record<string, unknown>;
}

export interface IGlancesHaSensorData {
  fs?: Record<string, IGlancesDiskSensorData>;
  diskio?: Record<string, IGlancesDiskIoSensorData>;
  mem?: IGlancesMemorySensorData;
  memswap?: IGlancesSwapSensorData;
  load?: IGlancesLoadSensorData;
  processcount?: IGlancesProcessSensorData;
  cpu?: IGlancesCpuSensorData;
  percpu?: Record<string, IGlancesCpuSensorData>;
  sensors?: Record<string, IGlancesEnvironmentSensorData>;
  network?: Record<string, IGlancesNetworkSensorData>;
  docker?: IGlancesDockerSensorData;
  containers?: Record<string, IGlancesContainerSensorData>;
  raid?: Record<string, Record<string, unknown>>;
  uptime?: unknown;
  gpu?: Record<string, IGlancesGpuSensorData>;
  computed?: Record<string, unknown>;
  [key: string]: unknown;
}

export interface IGlancesDiskSensorData {
  disk_use?: number;
  disk_use_percent?: number;
  disk_size?: number;
  disk_free?: number;
  [key: string]: unknown;
}

export interface IGlancesDiskIoSensorData {
  read?: number;
  write?: number;
  [key: string]: unknown;
}

export interface IGlancesMemorySensorData {
  memory_use_percent?: number;
  memory_use?: number;
  memory_free?: number;
  [key: string]: unknown;
}

export interface IGlancesSwapSensorData {
  swap_use_percent?: number;
  swap_use?: number;
  swap_free?: number;
  [key: string]: unknown;
}

export interface IGlancesLoadSensorData {
  processor_load?: number;
  processor_load_1m?: number;
  processor_load_5m?: number;
  [key: string]: unknown;
}

export interface IGlancesProcessSensorData {
  process_running?: number;
  process_total?: number;
  process_thread?: number;
  process_sleeping?: number;
  [key: string]: unknown;
}

export interface IGlancesCpuSensorData {
  cpu_use_percent?: number;
  [key: string]: unknown;
}

export interface IGlancesEnvironmentSensorData {
  temperature_core?: number;
  temperature_hdd?: number;
  fan_speed?: number;
  battery?: number;
  [key: string]: unknown;
}

export interface IGlancesNetworkSensorData {
  is_up?: boolean;
  rx?: number;
  tx?: number;
  speed?: number;
  [key: string]: unknown;
}

export interface IGlancesDockerSensorData {
  docker_active?: number;
  docker_cpu_use?: number;
  docker_memory_use?: number;
  [key: string]: unknown;
}

export interface IGlancesContainerSensorData {
  container_cpu_use?: number;
  container_memory_use?: number;
  [key: string]: unknown;
}

export interface IGlancesGpuSensorData {
  temperature?: number;
  mem?: number;
  proc?: number;
  fan_speed?: number;
  [key: string]: unknown;
}

export interface IGlancesRawData {
  system?: Record<string, unknown>;
  fs?: Array<Record<string, unknown>>;
  diskio?: Array<Record<string, unknown>>;
  sensors?: Array<Record<string, unknown>>;
  mem?: Record<string, unknown>;
  memswap?: Record<string, unknown>;
  load?: Record<string, unknown>;
  processcount?: Record<string, unknown>;
  quicklook?: Record<string, unknown>;
  percpu?: Array<Record<string, unknown>>;
  network?: Array<Record<string, unknown>>;
  dockers?: Record<string, unknown>;
  containers?: unknown;
  raid?: Record<string, Record<string, unknown>>;
  uptime?: unknown;
  gpu?: Array<Record<string, unknown>>;
  [key: string]: unknown;
}

export interface IGlancesManualEntry {
  host?: string;
  port?: number;
  url?: string;
  ssl?: boolean;
  verifySsl?: boolean;
  username?: string;
  password?: string;
  apiVersion?: TGlancesApiVersion;
  version?: TGlancesApiVersion;
  id?: string;
  name?: string;
  manufacturer?: string;
  model?: string;
  snapshot?: IGlancesSnapshot;
  rawData?: IGlancesRawData;
  allData?: IGlancesRawData;
  haSensorData?: IGlancesHaSensorData;
  sensorData?: IGlancesHaSensorData;
  metadata?: Record<string, unknown>;
}

export interface IGlancesHttpCandidateRecord {
  url?: string;
  location?: string;
  host?: string;
  port?: number;
  ssl?: boolean;
  name?: string;
  manufacturer?: string;
  model?: string;
  headers?: Record<string, string | undefined>;
  metadata?: Record<string, unknown>;
}
