import type { ConversionQualityPreset, VideoOutputFormat } from "@/types/media-processing";

export interface VideoFormatDefinition {
  format: VideoOutputFormat;
  label: string;
  description: string;
  extension: string;
  mimeType: string;
}

export interface ConversionPresetDefinition {
  preset: ConversionQualityPreset;
  label: string;
  description: string;
  h264Crf: string;
  webmCrf: string;
  aviQualityScale: string;
}

export const videoFormatDefinitions: Record<VideoOutputFormat, VideoFormatDefinition> = {
  mp4: {
    format: "mp4",
    label: "MP4",
    description: "Universal delivery format with broad compatibility.",
    extension: "mp4",
    mimeType: "video/mp4"
  },
  mov: {
    format: "mov",
    label: "MOV",
    description: "High-quality editing interchange format.",
    extension: "mov",
    mimeType: "video/quicktime"
  },
  webm: {
    format: "webm",
    label: "WebM",
    description: "Web-optimized VP9/Opus container.",
    extension: "webm",
    mimeType: "video/webm"
  },
  mkv: {
    format: "mkv",
    label: "MKV",
    description: "Flexible container for modern media workflows.",
    extension: "mkv",
    mimeType: "video/x-matroska"
  },
  avi: {
    format: "avi",
    label: "AVI",
    description: "Legacy container for older systems and workflows.",
    extension: "avi",
    mimeType: "video/x-msvideo"
  }
};

export const conversionPresetDefinitions: Record<ConversionQualityPreset, ConversionPresetDefinition> = {
  high: {
    preset: "high",
    label: "High",
    description: "Best visual quality with larger file size.",
    h264Crf: "18",
    webmCrf: "28",
    aviQualityScale: "2"
  },
  standard: {
    preset: "standard",
    label: "Standard",
    description: "Balanced quality and file size for most use cases.",
    h264Crf: "23",
    webmCrf: "34",
    aviQualityScale: "5"
  },
  small: {
    preset: "small",
    label: "Small file",
    description: "Smaller output size with more compression.",
    h264Crf: "29",
    webmCrf: "40",
    aviQualityScale: "9"
  }
};

export const videoFormatOptions = Object.values(videoFormatDefinitions);
export const conversionPresetOptions = Object.values(conversionPresetDefinitions);

export function isVideoOutputFormat(value: string): value is VideoOutputFormat {
  return value in videoFormatDefinitions;
}

export function isConversionQualityPreset(value: string): value is ConversionQualityPreset {
  return value in conversionPresetDefinitions;
}

export function getVideoFormatDefinition(format: VideoOutputFormat) {
  return videoFormatDefinitions[format];
}

export function getConversionPresetDefinition(preset: ConversionQualityPreset) {
  return conversionPresetDefinitions[preset];
}
