/**
 * Provider-specific types
 */

import type React from 'react';
import type { VideoSourceUnion, UrlSource, YouTubeSource, VimeoSource, HLSSource, DASHSource, StreamSource, BlobSource, DataUrlSource } from './sources';
import type { CommonPlayerSettings, CommonPlayerEvents, ErrorFallbackProps } from './player';

// =============================================================================
// Provider Props
// =============================================================================

/** Props passed to Vidstack provider */
export interface VidstackProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
  source: UrlSource | YouTubeSource | VimeoSource | HLSSource | DASHSource;
  theme?: 'default' | 'minimal' | 'modern';
  showInfo?: boolean;
  className?: string;
  errorFallback?: React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode);
}

/** Props passed to Native provider */
export interface NativeProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
  source: UrlSource | DataUrlSource;
  className?: string;
  videoClassName?: string;
  disableContextMenu?: boolean;
  showPreloader?: boolean;
  preloaderTimeout?: number;
}

/** Props passed to Stream provider */
export interface StreamProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
  source: StreamSource | BlobSource | DataUrlSource;
  className?: string;
  videoClassName?: string;
  disableContextMenu?: boolean;
  showPreloader?: boolean;
  preloaderTimeout?: number;
  errorFallback?: React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode);
}

// =============================================================================
// File Source Helper Types
// =============================================================================

/** Options for resolving file source */
export interface ResolveFileSourceOptions {
  /** File content - can be data URL string or binary ArrayBuffer */
  content: string | ArrayBuffer | null | undefined;
  /** File path for streaming */
  path: string;
  /** MIME type of the file */
  mimeType?: string;
  /** Session ID for authenticated streaming */
  sessionId?: string | null;
  /** Load method hint - 'http_stream' enables streaming mode */
  loadMethod?: 'http_stream' | 'rpc' | 'unspecified' | 'skip' | string;
  /** Function to generate stream URL (required for streaming) */
  getStreamUrl?: (sessionId: string, path: string) => string;
  /** Optional title */
  title?: string;
  /** Optional poster */
  poster?: string;
}

// =============================================================================
// Context Types
// =============================================================================

export interface VideoPlayerContextValue {
  /** Function to generate stream URL (for HTTP Range streaming) */
  getStreamUrl?: (sessionId: string, path: string) => string;
  /** Current session ID */
  sessionId?: string | null;
}

export interface VideoPlayerProviderProps extends VideoPlayerContextValue {
  children: React.ReactNode;
}

/** Simplified stream source (uses context for getStreamUrl) */
export interface SimpleStreamSource {
  type: 'stream';
  /** File path on server */
  path: string;
  /** Session ID (optional, uses context if not provided) */
  sessionId?: string;
  /** MIME type for the video */
  mimeType?: string;
  title?: string;
  poster?: string;
}
