export const LATENCY_PROFILES = [
  'low',
  'balanced',
  'high'
] as const;

export type LatencyProfile = typeof LATENCY_PROFILES[number];

export const DEFAULT_LATENCY_PROFILE: LatencyProfile = 'balanced';

export const SCREEN_SHARE_QUALITIES = [
  'performance',
  'balanced',
  'high-fps',
  'quality'
] as const;

export type ScreenShareQuality = typeof SCREEN_SHARE_QUALITIES[number];

export const DEFAULT_SCREEN_SHARE_QUALITY: ScreenShareQuality = 'balanced';

export interface ScreenShareStartOptions {
  includeSystemAudio: boolean;
  quality: ScreenShareQuality;
}

export interface ScreenShareQualityPreset {
  label: string;
  description: string;
  width: number;
  height: number;
  frameRate: number;
  maxBitrateBps: number;
  contentHint: 'motion' | 'detail';
  degradationPreference: 'maintain-framerate' | 'maintain-resolution';
  scaleResolutionDownBy?: number;
}

export const DEFAULT_SCREEN_SHARE_START_OPTIONS: ScreenShareStartOptions = {
  includeSystemAudio: false,
  quality: DEFAULT_SCREEN_SHARE_QUALITY
};

export const SCREEN_SHARE_QUALITY_PRESETS: Record<ScreenShareQuality, ScreenShareQualityPreset> = {
  performance: {
    label: 'Performance saver',
    description: '720p / 30 FPS with lower CPU and bandwidth usage.',
    width: 1280,
    height: 720,
    frameRate: 30,
    maxBitrateBps: 2_000_000,
    contentHint: 'motion',
    degradationPreference: 'maintain-framerate',
    scaleResolutionDownBy: 1
  },
  balanced: {
    label: 'Balanced',
    description: '1080p / 30 FPS for stable quality in most cases.',
    width: 1920,
    height: 1080,
    frameRate: 30,
    maxBitrateBps: 4_000_000,
    contentHint: 'detail',
    degradationPreference: 'maintain-resolution',
    scaleResolutionDownBy: 1
  },
  'high-fps': {
    label: 'High FPS',
    description: '1080p / 60 FPS for games and fast motion.',
    width: 1920,
    height: 1080,
    frameRate: 60,
    maxBitrateBps: 6_000_000,
    contentHint: 'motion',
    degradationPreference: 'maintain-framerate',
    scaleResolutionDownBy: 1
  },
  quality: {
    label: 'Sharp text',
    description: '1440p / 30 FPS for detailed UI and text clarity.',
    width: 2560,
    height: 1440,
    frameRate: 30,
    maxBitrateBps: 8_000_000,
    contentHint: 'detail',
    degradationPreference: 'maintain-resolution',
    scaleResolutionDownBy: 1
  }
};

export const SCREEN_SHARE_QUALITY_OPTIONS = (
  Object.entries(SCREEN_SHARE_QUALITY_PRESETS) as [ScreenShareQuality, ScreenShareQualityPreset][]
).map(([id, preset]) => ({
  id,
  ...preset
}));

export const ELECTRON_ENTIRE_SCREEN_SOURCE_NAME = 'Entire Screen';
