/**
 * Preload Configuration
 *
 * Centralized configuration for asset preloading, priority weights, and queue settings.
 */

export const PRELOAD_CONFIG = {
  // Queue settings
  maxConcurrentDownloads: 3,
  maxRetries: 3,
  retryDelayMs: 1000,

  // Size thresholds
  largeFileThreshold: 5 * 1024 * 1024, // 5MB -> use IndexedDB
  videoChunkSize: 5 * 1024 * 1024, // 5MB chunks
  initialVideoBufferSeconds: 5,

  // Priority weights (higher = load first)
  priority: {
    currentPage: 1000,
    neighborBase: 500,
    assetType: {
      transition: 150, // Highest - needed immediately on navigation click
      image: 100, // Backgrounds load during transition playback
      audio: 50,
      video: 30,
    } as Record<string, number>,
    variant: {
      thumbnail: 50,
      preview: 40,
      webp: 35,
      mp4_low: 20,
      mp4_high: 10,
      original: 5,
    } as Record<string, number>,
    linkCountMultiplier: 10,
    maxLinkBonus: 50,
  },

  // Storage
  storage: {
    warningPercent: 80,
    criticalPercent: 95,
    minFreeBuffer: 50 * 1024 * 1024, // 50MB
  },

  // Auto-cleanup timeouts (from hoboken pattern)
  autoRemove: {
    completedMs: 3000,
    errorMs: 10000,
  },

  // Neighbor graph traversal
  neighborGraph: {
    maxDepth: 1, // Only preload immediate neighbors (depth 2 was causing too many requests)
    constructorMaxDepth: 1, // Same as maxDepth for constructor preview
  },

  // Asset URL field names in element content_json (camelCase)
  assetFields: {
    // All asset URL fields for preloading extraction
    all: [
      'iconUrl',
      'imageUrl',
      'mediaUrl',
      'videoUrl',
      'audioUrl',
      'transitionVideoUrl',
      'backgroundImageUrl',
      'reverseVideoUrl',
      'carouselPrevIconUrl',
      'carouselNextIconUrl',
      'src',
      'url',
      'poster',
      'thumbnail',
    ] as const,
    // Image-only fields for decode before page switch
    images: [
      'iconUrl',
      'imageUrl',
      'backgroundImageUrl',
      'carouselPrevIconUrl',
      'carouselNextIconUrl',
      'src',
    ] as const,
    // Nested array fields containing assets
    nested: ['galleryCards', 'carouselSlides'] as const,
    // Fields within nested items that contain URLs
    nestedUrlFields: ['imageUrl', 'videoUrl'] as const,
  },
} as const;

export type PreloadConfig = typeof PRELOAD_CONFIG;
