export const ippDefaultPort = 631;
export const ippDefaultBasePath = '/ipp/print';
export const ippDefaultTimeoutMs = 10000;

export type TIppSnapshotSource = 'ipp' | 'client' | 'snapshot' | 'manual' | 'runtime';
export type TIppPrinterState = 'idle' | 'printing' | 'stopped' | 'unknown' | string;
export type TIppMarkerKind = 'marker' | 'ink' | 'toner' | 'drum' | 'waste' | string;

export interface IIppConfig {
  host?: string;
  port?: number;
  basePath?: string;
  tls?: boolean;
  ssl?: boolean;
  verifySsl?: boolean;
  timeoutMs?: number;
  name?: string;
  manufacturer?: string;
  model?: string;
  uniqueId?: string;
  uuid?: string;
  serial?: string;
  snapshot?: IIppSnapshot;
  attributes?: IIppAttributeRecord;
  client?: IIppClientLike;
  online?: boolean;
}

export interface IHomeAssistantIppConfig extends IIppConfig {}

export interface IIppClientLike {
  printer?: () => Promise<IIppSnapshot | IIppAttributeRecord>;
  getSnapshot?: () => Promise<IIppSnapshot | IIppAttributeRecord>;
}

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

export interface IIppPrinterInfo {
  id?: string;
  name?: string;
  manufacturer?: string;
  model?: string;
  serialNumber?: string;
  uuid?: string;
  version?: string;
  location?: string;
  info?: string;
  moreInfo?: string;
  makeAndModel?: string;
  deviceId?: string;
  commandSet?: string[];
  uriSupported?: string[];
  host?: string;
  port?: number;
  basePath?: string;
  tls?: boolean;
}

export interface IIppStatusInfo {
  printerState: TIppPrinterState;
  stateMessage?: string;
  stateReasons: string[];
  acceptingJobs?: boolean;
  queuedJobCount?: number;
  uptimeSeconds?: number;
  bootedAt?: string;
  currentTime?: string;
}

export interface IIppMarkerInfo {
  id?: string;
  index: number;
  name: string;
  kind: TIppMarkerKind;
  type?: string;
  color?: string;
  level?: number | null;
  lowLevel?: number;
  highLevel?: number;
}

export interface IIppJobInfo {
  id: string;
  name?: string;
  state?: string;
  owner?: string;
  impressionsCompleted?: number;
  createdAt?: string;
  processingAt?: string;
  completedAt?: string;
  attributes?: Record<string, unknown>;
}

export interface IIppSnapshot {
  printer: IIppPrinterInfo;
  status: IIppStatusInfo;
  markers: IIppMarkerInfo[];
  jobs: IIppJobInfo[];
  attributes?: IIppAttributeRecord;
  online: boolean;
  updatedAt?: string;
  source?: TIppSnapshotSource;
  error?: string;
  rawStatusCode?: number;
}

export interface IIppParsedResponse {
  version: string;
  statusCode: number;
  requestId: number;
  attributes: IIppAttributeRecord;
}

export interface IIppMdnsRecord {
  type?: string;
  name?: string;
  host?: string;
  port?: number;
  addresses?: string[];
  hostname?: string;
  txt?: Record<string, string | undefined>;
  properties?: Record<string, string | undefined>;
}

export interface IIppManualEntry {
  host?: string;
  port?: number;
  basePath?: string;
  tls?: boolean;
  ssl?: boolean;
  verifySsl?: boolean;
  id?: string;
  name?: string;
  manufacturer?: string;
  model?: string;
  serialNumber?: string;
  uuid?: string;
  snapshot?: IIppSnapshot;
  attributes?: IIppAttributeRecord;
  metadata?: Record<string, unknown>;
}
