/**
 * PitchScript Types
 *
 * Schema for generating pitch presentation videos that transition
 * from slides to live app demos, synchronized with per-block MP3 audio.
 */

export type PitchScript = {
  id: string;

  metadata: {
    title: string;
    aspectRatio: '16:9' | '9:16' | '1:1';
    fps: number;
  };

  blocks: PitchBlock[];

  music?: MusicConfig;
};

export type PitchBlock = {
  id: string;
  type: 'slide' | 'problem' | 'feature' | 'app-demo' | 'stat' | 'closing';
  audio: AudioBlock;
  content: SlideContent | ProblemContent | FeatureContent | AppDemoContent | StatContent | ClosingContent;
};

export type AudioBlock = {
  src: string;           // Path to MP3 file
  durationMs: number;    // Duration in milliseconds
};

// Scene-specific content types

export type SlideContent = {
  type: 'slide';
  headline: string;
  subheadline?: string;
  visual?: 'fade-in' | 'zoom' | 'typewriter';
};

export type ProblemContent = {
  type: 'problem';
  statement: string;
  icon?: 'alert' | 'warning' | 'database' | 'lock' | 'clock';
  emphasis?: string[];   // Words to highlight
};

export type FeatureContent = {
  type: 'feature';
  title: string;
  description: string;
  icon: 'shield' | 'clock' | 'graph' | 'search' | 'check' | 'layers' | 'audit';
  highlight?: boolean;
};

export type AppDemoContent = {
  type: 'app-demo';
  screenshot?: string;           // Static image path
  video?: string;                // Screen recording path
  callouts?: Callout[];          // Animated highlights
  caption?: string;
  page?: string;                 // Page name for context (e.g., "Skeptic Query")
};

export type Callout = {
  x: number;            // Percentage from left (0-100)
  y: number;            // Percentage from top (0-100)
  label: string;
  startMs: number;      // When to show (relative to block start)
  durationMs: number;   // How long to show
  style?: 'pulse' | 'arrow' | 'highlight';
};

export type StatContent = {
  type: 'stat';
  value: string;         // e.g., "79%"
  label: string;         // e.g., "of FDA Warning Letters cited data integrity failures"
  source?: string;       // Attribution
  animation?: 'count-up' | 'reveal' | 'fade';
};

export type ClosingContent = {
  type: 'closing';
  headline: string;
  cta?: string;
  subtext?: string;
  animation?: 'pulse' | 'glow' | 'fade';
};

export type MusicConfig = {
  src: string;
  volume: number;      // 0-1
  fadeInMs: number;
  fadeOutMs: number;
};

// Helper to calculate total duration from blocks
export function calculateTotalDuration(blocks: PitchBlock[]): number {
  return blocks.reduce((sum, block) => sum + block.audio.durationMs, 0);
}

// Helper to get block start time
export function getBlockStartMs(blocks: PitchBlock[], blockIndex: number): number {
  return blocks.slice(0, blockIndex).reduce((sum, block) => sum + block.audio.durationMs, 0);
}
