export const volumioDefaultPort = 3000;

export interface IVolumioConfig {
  host?: string;
  port?: number;
  timeoutMs?: number;
  name?: string;
  uniqueId?: string;
  connected?: boolean;
  ssl?: boolean;
  deviceInfo?: IVolumioDeviceInfo;
  systemInfo?: IVolumioSystemInfo;
  systemVersion?: IVolumioSystemVersion;
  state?: IVolumioState;
  playlists?: IVolumioPlaylistCollection;
  queue?: IVolumioQueue;
  snapshot?: IVolumioSnapshot;
}

export interface IHomeAssistantVolumioConfig extends IVolumioConfig {}

export interface IVolumioDeviceInfo {
  id?: string;
  uuid?: string;
  name?: string;
  host?: string;
  port?: number;
  manufacturer?: string;
  model?: string;
  hardware?: string;
  systemVersion?: string;
  softwareVersion?: string;
}

export interface IVolumioSystemInfo {
  id?: string;
  uuid?: string;
  name?: string;
  hardware?: string;
  systemversion?: string;
  systemVersion?: string;
  version?: string;
  volumioVersion?: string;
  [key: string]: unknown;
}

export interface IVolumioSystemVersion {
  hardware?: string;
  systemversion?: string;
  systemVersion?: string;
  version?: string;
  volumioVersion?: string;
  [key: string]: unknown;
}

export interface IVolumioState {
  status?: 'play' | 'pause' | 'stop' | string;
  position?: number | string;
  title?: string;
  artist?: string;
  album?: string;
  albumart?: string;
  uri?: string;
  trackType?: string;
  seek?: number | string;
  duration?: number | string;
  samplerate?: number | string;
  bitdepth?: number | string;
  channels?: number | string;
  bitrate?: number | string;
  random?: boolean | string;
  repeat?: boolean | string;
  repeatSingle?: boolean | string;
  consume?: boolean | string;
  volume?: number | string;
  dbVolume?: number | string;
  mute?: boolean | string;
  disableVolumeControl?: boolean | string;
  stream?: boolean | string;
  volatile?: boolean | string;
  service?: string;
  updatedb?: boolean | string;
  [key: string]: unknown;
}

export interface IVolumioPlaylist {
  name?: string;
  title?: string;
  uri?: string;
  [key: string]: unknown;
}

export type IVolumioPlaylistCollection =
  | string[]
  | IVolumioPlaylist[]
  | {
      playlists?: Array<string | IVolumioPlaylist>;
      lists?: Array<{ items?: IVolumioPlaylist[]; title?: string; [key: string]: unknown }>;
      navigation?: {
        lists?: Array<{ items?: IVolumioPlaylist[]; title?: string; [key: string]: unknown }>;
      };
      [key: string]: unknown;
    };

export interface IVolumioQueue {
  queue?: IVolumioPlaylist[];
  [key: string]: unknown;
}

export interface IVolumioSnapshot {
  deviceInfo: IVolumioDeviceInfo;
  systemInfo?: IVolumioSystemInfo;
  systemVersion?: IVolumioSystemVersion;
  state: IVolumioState;
  playlists?: IVolumioPlaylistCollection;
  queue?: IVolumioQueue;
  online: boolean;
  updatedAt?: string;
}

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

export interface IVolumioManualEntry {
  host?: string;
  port?: number;
  id?: string;
  uuid?: string;
  name?: string;
  model?: string;
  hardware?: string;
  manufacturer?: string;
  metadata?: Record<string, unknown>;
}

export type TVolumioCommand =
  | 'play'
  | 'pause'
  | 'stop'
  | 'next'
  | 'prev'
  | 'volume'
  | 'playplaylist'
  | 'seek'
  | 'repeat'
  | 'random'
  | 'clearQueue'
  | string;
