export const channelsDefaultPort = 57000;

export interface IChannelsConfig {
  host?: string;
  port?: number;
  timeoutMs?: number;
  name?: string;
  uniqueId?: string;
  connected?: boolean;
  deviceInfo?: IChannelsDeviceInfo;
  status?: IChannelsStatus;
  favoriteChannels?: IChannelsFavoriteChannel[];
  snapshot?: IChannelsSnapshot;
  commandExecutor?: TChannelsCommandExecutor;
}

export interface IHomeAssistantChannelsConfig extends IChannelsConfig {}

export interface IChannelsDeviceInfo {
  id?: string;
  name?: string;
  host?: string;
  port?: number;
  manufacturer?: string;
  model?: string;
  softwareVersion?: string;
}

export interface IChannelsStatus {
  status?: 'stopped' | 'paused' | 'playing' | 'offline' | 'error' | string;
  muted?: boolean;
  channel?: IChannelsStatusChannel;
  now_playing?: IChannelsNowPlaying;
  nowPlaying?: IChannelsNowPlaying;
  [key: string]: unknown;
}

export interface IChannelsStatusChannel {
  number?: string | number;
  name?: string;
  image_url?: string;
  channel_number?: string | number;
  channel_name?: string;
  channel_image_url?: string;
  call_sign?: string;
  hd?: boolean;
  [key: string]: unknown;
}

export interface IChannelsNowPlaying {
  title?: string;
  episode_title?: string;
  episodeTitle?: string;
  season_number?: number | string;
  seasonNumber?: number | string;
  episode_number?: number | string;
  episodeNumber?: number | string;
  summary?: string;
  image_url?: string;
  imageUrl?: string;
  [key: string]: unknown;
}

export interface IChannelsFavoriteChannel extends IChannelsStatusChannel {}

export interface IChannelsSnapshot {
  deviceInfo: IChannelsDeviceInfo;
  status: IChannelsStatus;
  favoriteChannels: IChannelsFavoriteChannel[];
  online: boolean;
  updatedAt?: string;
}

export interface IChannelsManualEntry {
  host?: string;
  port?: number;
  url?: string;
  id?: string;
  name?: string;
  manufacturer?: string;
  model?: string;
  metadata?: Record<string, unknown>;
  status?: IChannelsStatus;
  favoriteChannels?: IChannelsFavoriteChannel[];
  snapshot?: IChannelsSnapshot;
}

export interface IChannelsHttpApiEntry {
  host?: string;
  port?: number;
  url?: string;
  path?: string;
  name?: string;
  id?: string;
  status?: IChannelsStatus;
  response?: IChannelsStatus;
  favoriteChannels?: IChannelsFavoriteChannel[];
  metadata?: Record<string, unknown>;
}

export interface IChannelsCommand {
  type: TChannelsCommandType;
  method: 'POST';
  path: string;
  body?: unknown;
  seconds?: number;
  mediaId?: string;
  mediaType?: string;
  source?: string;
}

export interface IChannelsCommandResult {
  success: boolean;
  transmitted?: boolean;
  status?: IChannelsStatus;
  snapshot?: IChannelsSnapshot;
  data?: unknown;
  error?: string;
}

export type TChannelsCommandExecutor = (commandArg: IChannelsCommand) => Promise<IChannelsCommandResult>;

export type TChannelsCommandType =
  | 'toggle_mute'
  | 'toggle_cc'
  | 'toggle_record'
  | 'channel_up'
  | 'channel_down'
  | 'previous_channel'
  | 'toggle_pause'
  | 'pause'
  | 'resume'
  | 'stop'
  | 'seek'
  | 'seek_forward'
  | 'seek_backward'
  | 'skip_forward'
  | 'skip_backward'
  | 'play_channel'
  | 'play_recording'
  | 'navigate'
  | 'notify'
  | string;
