import type { PresetRequirements } from '../commands/command-plan';

export type MetadataPolicy = 'copy' | 'edit' | 'remove';
export type ChapterPolicy = 'keep' | 'remove' | 'replace';
export type SubtitlePolicy = 'none' | 'copy-compatible' | 'convert' | 'burn-in';
export type PresetKind = 'video' | 'audio' | 'derivative' | 'remux';
export type QualityMode =
  'compatibility' | 'balanced' | 'smaller-file' | 'higher-quality' | 'custom';

export type VideoCodec =
  'libx264' | 'libvpx-vp9' | 'libvpx' | 'libwebp_anim' | 'gif';

export type AudioCodec =
  'aac' | 'libmp3lame' | 'libvorbis' | 'libopus' | 'pcm_s16le' | 'flac';

export interface VideoEncodingSettings {
  readonly codec: VideoCodec;
  readonly qualityMode: QualityMode;
  readonly crf?: number;
  readonly bitrateKbps?: number;
  readonly width?: number;
  readonly height?: number;
  readonly frameRate?: number;
  readonly pixelFormat?: 'yuv420p' | 'yuv422p' | 'yuv444p' | 'rgba';
  readonly encoderPreset?:
    'ultrafast' | 'veryfast' | 'fast' | 'medium' | 'slow' | 'veryslow';
}

export interface AudioEncodingSettings {
  readonly codec: AudioCodec;
  readonly bitrateKbps?: number;
  readonly sampleRate?: 22_050 | 32_000 | 44_100 | 48_000 | 96_000;
  readonly channels?: 1 | 2 | 6;
}

export interface ExportPresetBase {
  readonly id: string;
  readonly name: string;
  readonly description: string;
  readonly kind: PresetKind;
  readonly container: string;
  readonly fileExtension: string;
  readonly requirements: PresetRequirements;
  readonly video?: VideoEncodingSettings;
  readonly audio?: AudioEncodingSettings;
  readonly metadataPolicy: MetadataPolicy;
  readonly chapterPolicy: ChapterPolicy;
  readonly subtitlePolicy: SubtitlePolicy;
  readonly fastStart?: boolean;
  /** Concise documentation of the fixed encoding decisions in the preset. */
  readonly settingsSummary: readonly string[];
}

export interface BuiltInExportPreset extends ExportPresetBase {
  readonly builtIn: true;
}

export interface UserExportPreset {
  readonly schemaVersion: 1;
  readonly id: string;
  readonly name: string;
  readonly description?: string;
  readonly kind: Exclude<PresetKind, 'remux'>;
  readonly container: string;
  readonly fileExtension: string;
  readonly video?: VideoEncodingSettings;
  readonly audio?: AudioEncodingSettings;
  readonly metadataPolicy: MetadataPolicy;
  readonly chapterPolicy: ChapterPolicy;
  readonly subtitlePolicy: SubtitlePolicy;
  readonly fastStart?: boolean;
}

export interface FFmpegCapabilitySnapshot {
  readonly muxers: ReadonlySet<string>;
  readonly encoders: ReadonlySet<string>;
  readonly decoders: ReadonlySet<string>;
  readonly filters: ReadonlySet<string>;
}

export interface PresetAvailability {
  readonly status: 'available' | 'degraded' | 'unavailable';
  readonly reasons: readonly string[];
}
