export type TBrotherPrinterType = 'laser' | 'ink';
export type TBrotherSnapshotSource = 'snmp' | 'client' | 'manual' | 'snapshot' | 'runtime';

export interface IBrotherConfig {
  host?: string;
  port?: number;
  community?: string;
  printerType?: TBrotherPrinterType;
  type?: TBrotherPrinterType;
  timeoutMs?: number;
  name?: string;
  manufacturer?: string;
  model?: string;
  serial?: string;
  serialNumber?: string;
  macAddress?: string;
  firmware?: string;
  uniqueId?: string;
  snapshot?: IBrotherSnapshot;
  sensors?: IBrotherSensors;
  rawData?: IBrotherRawData;
  client?: IBrotherClientLike;
  online?: boolean;
}

export interface IBrotherClientLike {
  getSnapshot?: () => Promise<IBrotherSnapshot | IBrotherClientSnapshotData>;
  asyncUpdate?: () => Promise<IBrotherSensors>;
  getSensors?: () => Promise<IBrotherSensors>;
  getRawData?: () => Promise<IBrotherRawData>;
}

export interface IBrotherClientSnapshotData {
  printer?: Partial<IBrotherPrinterInfo>;
  sensors?: IBrotherSensors;
  rawData?: IBrotherRawData;
  online?: boolean;
  updatedAt?: string;
  source?: TBrotherSnapshotSource;
  error?: string;
}

export interface IBrotherRawData {
  [key: string]: unknown;
}

export interface IBrotherPrinterInfo {
  id?: string;
  name?: string;
  manufacturer?: string;
  model?: string;
  serial?: string;
  serialNumber?: string;
  macAddress?: string;
  firmware?: string;
  host?: string;
  port?: number;
  printerType?: TBrotherPrinterType;
  configurationUrl?: string;
}

export interface IBrotherSensors {
  status?: string | null;
  uptime?: string | Date | null;
  belt_unit_remaining_life?: number | null;
  belt_unit_remaining_pages?: number | null;
  black_counter?: number | null;
  black_drum_counter?: number | null;
  black_drum_remaining_life?: number | null;
  black_drum_remaining_pages?: number | null;
  black_ink?: number | null;
  black_ink_remaining?: number | null;
  black_ink_status?: number | null;
  black_toner?: number | null;
  black_toner_remaining?: number | null;
  black_toner_status?: number | null;
  bw_counter?: number | null;
  color_counter?: number | null;
  cyan_counter?: number | null;
  cyan_drum_counter?: number | null;
  cyan_drum_remaining_life?: number | null;
  cyan_drum_remaining_pages?: number | null;
  cyan_ink?: number | null;
  cyan_ink_remaining?: number | null;
  cyan_ink_status?: number | null;
  cyan_toner?: number | null;
  cyan_toner_remaining?: number | null;
  cyan_toner_status?: number | null;
  drum_counter?: number | null;
  drum_remaining_life?: number | null;
  drum_remaining_pages?: number | null;
  drum_status?: number | null;
  duplex_unit_pages_counter?: number | null;
  fuser_remaining_life?: number | null;
  fuser_unit_remaining_pages?: number | null;
  image_counter?: number | null;
  laser_remaining_life?: number | null;
  laser_unit_remaining_pages?: number | null;
  magenta_counter?: number | null;
  magenta_drum_counter?: number | null;
  magenta_drum_remaining_life?: number | null;
  magenta_drum_remaining_pages?: number | null;
  magenta_ink?: number | null;
  magenta_ink_remaining?: number | null;
  magenta_ink_status?: number | null;
  magenta_toner?: number | null;
  magenta_toner_remaining?: number | null;
  magenta_toner_status?: number | null;
  page_counter?: number | null;
  pf_kit_1_remaining_life?: number | null;
  pf_kit_1_remaining_pages?: number | null;
  pf_kit_mp_remaining_life?: number | null;
  pf_kit_mp_remaining_pages?: number | null;
  yellow_counter?: number | null;
  yellow_drum_counter?: number | null;
  yellow_drum_remaining_life?: number | null;
  yellow_drum_remaining_pages?: number | null;
  yellow_ink?: number | null;
  yellow_ink_remaining?: number | null;
  yellow_ink_status?: number | null;
  yellow_toner?: number | null;
  yellow_toner_remaining?: number | null;
  yellow_toner_status?: number | null;
  [key: string]: unknown;
}

export interface IBrotherSnapshot {
  printer: IBrotherPrinterInfo;
  sensors: IBrotherSensors;
  rawData?: IBrotherRawData;
  online: boolean;
  updatedAt?: string;
  source?: TBrotherSnapshotSource;
  error?: string;
}

export interface IBrotherSensorDefinition {
  key: keyof IBrotherSensors & string;
  name: string;
  unit?: string;
  deviceClass?: string;
  stateClass?: string;
  entityCategory?: string;
  enabledDefault?: boolean;
}

export interface IBrotherMdnsRecord {
  type?: string;
  name?: string;
  host?: string;
  port?: number;
  addresses?: string[];
  hostname?: string;
  txt?: Record<string, unknown>;
  properties?: Record<string, unknown>;
  metadata?: Record<string, unknown>;
}

export interface IBrotherManualEntry extends Partial<IBrotherConfig> {
  id?: string;
  url?: string;
  metadata?: Record<string, unknown>;
}

export interface IBrotherRefreshResult {
  success: boolean;
  snapshot: IBrotherSnapshot;
  error?: string;
}

export type IHomeAssistantBrotherConfig = IBrotherConfig;
