// Visualization System Types

export type ElementState =
  | "default"
  | "active"
  | "comparing"
  | "found"
  | "visited"
  | "swapping";

// Array Data Structure
export interface ArrayElement {
  value: unknown;
  state: ElementState;
  annotations?: string[];
}

export interface ArrayState {
  type: "array";
  values: ArrayElement[];
  pointers?: Record<string, number>;
}

// Linked List Data Structure
export interface LinkedListNode {
  value: unknown;
  state: ElementState;
  annotations?: string[];
}

export interface LinkedListState {
  type: "linkedlist";
  nodes: LinkedListNode[];
  pointers?: Record<string, number>;
}

// Stack Data Structure
export interface StackState {
  type: "stack";
  values: Array<{
    value: unknown;
    state: ElementState;
    annotations?: string[];
  }>;
}

// Tree Data Structure
export interface TreeNode {
  value: unknown;
  state: ElementState;
  annotations?: string[];
  left?: TreeNode | null;
  right?: TreeNode | null;
}

export interface TreeState {
  type: "tree";
  root: TreeNode | null;
  pointers?: Record<string, string>;
}

// Graph Data Structure
export interface GraphNode {
  id: string;
  value: unknown;
  state: ElementState;
  annotations?: string[];
}

export interface GraphEdge {
  from: string;
  to: string;
  weight?: number;
  state: ElementState;
}

export interface GraphState {
  type: "graph";
  nodes: GraphNode[];
  edges: GraphEdge[];
  directed?: boolean;
}

// Matrix Data Structure
export interface MatrixCell {
  value: unknown;
  state: ElementState;
  annotations?: string[];
}

export interface MatrixState {
  type: "matrix";
  rows: MatrixCell[][];
  pointers?: Record<string, { row: number; col: number }>;
}

// Union type for all data structures
export type DataStructureState =
  | ArrayState
  | LinkedListState
  | StackState
  | TreeState
  | GraphState
  | MatrixState;

// Code highlighting range
export interface CodeHighlight {
  startLine: number;
  endLine: number;
}

// Transition configuration
export interface TransitionConfig {
  duration?: number;
  emphasis?: string;
}

// Core visualization step
export interface VisualizationStep {
  id: string;
  description: string;
  structures: Record<string, DataStructureState>;
  variables?: Record<string, unknown>;
  codeHighlight?: CodeHighlight;
  transition?: TransitionConfig;
}

// Complete visualization data
export interface VisualizationData {
  id: string;
  title: string;
  code: string;
  steps: VisualizationStep[];
  totalSteps: number;
}

// Visualization example from API (stored in pattern YAML)
export interface VisualizationExample {
  id: string;
  title: string;
  input?: Record<string, unknown>;
  code: string;
  steps: VisualizationStep[];
}

// Playback state for context
export interface PlaybackState {
  currentStep: number;
  isPlaying: boolean;
  speed: number;
}

// Speed presets (ms per step)
export const SPEED_PRESETS = {
  slow: 2000,
  normal: 1000,
  fast: 500,
} as const;

export type SpeedPreset = keyof typeof SPEED_PRESETS;
