/**
 * TypeScript types for daemon settings and status.
 * Mirrors the Rust types from record-daemon/src/config/ and record-daemon/src/ipc/protocol.rs.
 */

// ---------------------------------------------------------------------------
// Encoder presets
// ---------------------------------------------------------------------------

export interface NvencPreset {
  type: "nvenc";
  bitrate: number;
  cq_level: number;
  two_pass: boolean;
}

export interface AmfPreset {
  type: "amf";
  bitrate: number;
  quality: "speed" | "balanced" | "quality";
}

export interface X264Preset {
  type: "x264";
  preset: string;
  bitrate: number;
  crf: number | null;
}

export type EncoderPreset = NvencPreset | AmfPreset | X264Preset;

// ---------------------------------------------------------------------------
// Quality level
// ---------------------------------------------------------------------------

export type QualityLevel = "low" | "medium" | "high" | "ultra";

// ---------------------------------------------------------------------------
// Settings structures
// ---------------------------------------------------------------------------

export interface VideoSettings {
  encoder_preset: EncoderPreset;
  quality: QualityLevel;
  frame_rate: number;
  hardware_acceleration: boolean;
}

export interface OutputSettings {
  path: string;
  naming_pattern: string;
  container: string;
  split_size_mb: number;
  split_time_minutes: number;
}

export interface AudioSettings {
  enabled: boolean;
  bitrate: number;
  sample_rate: number;
  channels: number;
  capture_game: boolean;
  capture_mic: boolean;
  mic_device: string | null;
}

export interface DaemonSettings {
  auto_record: boolean;
  monitor_client: boolean;
  poll_interval_ms: number;
  socket_path: string | null;
  log_level: string;
  save_timeline: boolean;
}

export interface Settings {
  video: VideoSettings;
  output: OutputSettings;
  audio: AudioSettings;
  daemon: DaemonSettings;
}

/** Response wrapper from daemon_get_settings (daemon wraps in { settings: {...} }). */
export interface GetSettingsResponse {
  settings: Settings;
}

// ---------------------------------------------------------------------------
// Daemon status
// ---------------------------------------------------------------------------

export type DaemonStatus = "idle" | "monitoring" | "recording" | "error" | "shutting_down";

export interface DaemonStatusResponse {
  status: DaemonStatus;
  is_recording: boolean;
  current_game_id: number | null;
  client_connected: boolean;
}

// ---------------------------------------------------------------------------
// Encoder info
// ---------------------------------------------------------------------------

export interface EncoderInfo {
  id: string;
  name: string;
  is_hardware: boolean;
  available: boolean;
}

export interface EncodersResponse {
  available: EncoderInfo[];
  current: string;
}

// ---------------------------------------------------------------------------
// Quality level metadata
// ---------------------------------------------------------------------------

export const QUALITY_LEVELS: { value: QualityLevel; label: string; description: string }[] = [
  { value: "low", label: "Low", description: "720p @ 30fps" },
  { value: "medium", label: "Medium", description: "1080p @ 30fps" },
  { value: "high", label: "High", description: "1080p @ 60fps" },
  { value: "ultra", label: "Ultra", description: "1440p @ 60fps" },
];

export const CONTAINER_FORMATS = ["mp4", "mkv", "mov", "flv"] as const;

export const LOG_LEVELS = ["trace", "debug", "info", "warn", "error"] as const;

export const X264_PRESETS = [
  "ultrafast",
  "superfast",
  "veryfast",
  "faster",
  "fast",
  "medium",
  "slow",
  "slower",
  "veryslow",
] as const;

export const AMF_QUALITIES: { value: "speed" | "balanced" | "quality"; label: string }[] = [
  { value: "speed", label: "Speed" },
  { value: "balanced", label: "Balanced" },
  { value: "quality", label: "Quality" },
];
