export const hddtempDomain = 'hddtemp';
export const hddtempDisplayName = 'hddtemp';
export const hddtempDefaultName = 'HD Temperature';
export const hddtempDefaultHost = 'localhost';
export const hddtempDefaultPort = 7634;
export const hddtempDefaultTimeoutMs = 5000;

export type THddtempTransport = 'tcp' | 'snapshot';
export type THddtempSnapshotSource = 'tcp' | 'manual' | 'snapshot' | 'client' | 'runtime';
export type THddtempRawData = string | IHddtempRawDiskInput[];

export interface IHddtempRawDiskInput {
  device: string;
  model?: string;
  temperature?: string | number | null;
  unit?: string;
  raw?: string;
}

export interface IHddtempDiskSnapshot {
  id: string;
  device: string;
  name: string;
  model?: string;
  temperature?: number;
  rawTemperature?: string;
  unit: 'C' | 'F';
  available: boolean;
  raw?: string;
}

export interface IHddtempDaemonSnapshotInfo {
  id: string;
  name: string;
  host?: string;
  port?: number;
  manufacturer: string;
  model: string;
  configuredDisks?: string[];
}

export interface IHddtempSnapshot {
  daemon: IHddtempDaemonSnapshotInfo;
  disks: IHddtempDiskSnapshot[];
  online: boolean;
  updatedAt: string;
  source: THddtempSnapshotSource;
  raw?: string;
  error?: string;
}

export interface IHddtempClientLike {
  getSnapshot?: () => Promise<IHddtempSnapshot | THddtempRawData>;
  getRawData?: () => Promise<THddtempRawData>;
  destroy?: () => Promise<void>;
}

export interface IHddtempConfig {
  host?: string;
  port?: number;
  timeoutMs?: number;
  name?: string;
  uniqueId?: string;
  transport?: THddtempTransport;
  disks?: string[];
  snapshot?: IHddtempSnapshot;
  rawData?: THddtempRawData;
  rawText?: string;
  rawDisks?: IHddtempRawDiskInput[];
  client?: IHddtempClientLike;
  online?: boolean;
  manufacturer?: string;
  model?: string;
}

export interface IHomeAssistantHddtempConfig extends IHddtempConfig {}

export interface IHddtempManualEntry extends IHddtempConfig {
  id?: string;
  url?: string;
  raw?: string;
  metadata?: Record<string, unknown>;
}

export interface IHddtempTcpDiscoveryRecord {
  host?: string;
  port?: number;
  id?: string;
  name?: string;
  manufacturer?: string;
  model?: string;
  banner?: string;
  rawData?: THddtempRawData;
  metadata?: Record<string, unknown>;
}

export interface IHddtempRefreshResult {
  success: boolean;
  snapshot?: IHddtempSnapshot;
  error?: string;
  data?: unknown;
}
