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 {
  width: number;
  height: number;
  frameRate: number;
  maxBitrateBps: number;
  contentHint: 'motion' | 'detail';
  degradationPreference: 'maintain-framerate' | 'maintain-resolution';
  scaleResolutionDownBy?: number;
}

export function screenShareQualityI18nKey(
  quality: ScreenShareQuality,
  field: 'label' | 'description'
): string {
  return `screenShare.quality.${quality}.${field}`;
}

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: {
    width: 1280,
    height: 720,
    frameRate: 30,
    maxBitrateBps: 2_000_000,
    contentHint: 'motion',
    degradationPreference: 'maintain-framerate',
    scaleResolutionDownBy: 1
  },
  balanced: {
    width: 1920,
    height: 1080,
    frameRate: 30,
    maxBitrateBps: 4_000_000,
    contentHint: 'detail',
    degradationPreference: 'maintain-resolution',
    scaleResolutionDownBy: 1
  },
  'high-fps': {
    width: 1920,
    height: 1080,
    frameRate: 60,
    maxBitrateBps: 6_000_000,
    contentHint: 'motion',
    degradationPreference: 'maintain-framerate',
    scaleResolutionDownBy: 1
  },
  quality: {
    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';
