// Study types
export interface Study {
  id: string;
  name: string;
  topic: string | null;  // Topic folder name for grouping (e.g., 'M1_Mirror', 'Simple_Bracket')
  status: 'not_started' | 'running' | 'paused' | 'completed';
  progress: {
    current: number;
    total: number;
  };
  best_value: number | null;
  target: number | null;
  path: string;
  created_at?: string;
  last_modified?: string;
}

export interface StudyListResponse {
  studies: Study[];
}

// Trial types
export interface DesignVariables {
  [key: string]: number;
}

export interface Results {
  first_frequency?: number;
  [key: string]: number | undefined;
}

export interface Trial {
  trial_number: number;
  objective: number;
  design_variables: DesignVariables;
  results: Results;
  timestamp?: string;
  user_attrs?: {
    [key: string]: any;
  };
  start_time?: string;
  end_time?: string;
  objectives?: number[];
  source?: 'FEA' | 'NN' | 'V10_FEA';  // Trial source for FEA vs NN differentiation
}

export interface HistoryResponse {
  trials: Trial[];
  study_id: string;
}

// Pruning types
export interface PrunedTrial {
  trial_number: number;
  pruning_cause: string;
  design_variables: DesignVariables;
  timestamp?: string;
  diagnostics?: {
    [key: string]: any;
  };
}

export interface PruningResponse {
  pruned_trials: PrunedTrial[];
  study_id: string;
  count?: number;
}

// WebSocket message types
export type WebSocketMessageType =
  | 'connected'
  | 'trial_completed'
  | 'new_best'
  | 'progress'
  | 'trial_pruned';

export interface WebSocketMessage {
  type: WebSocketMessageType;
  data: any;
}

export interface ConnectedMessage {
  study_id: string;
  current_trials: number;
  message: string;
}

export interface TrialCompletedMessage extends Trial {}

export interface NewBestMessage extends Trial {}

export interface ProgressMessage {
  current: number;
  total: number;
  percentage: number;
}

export interface TrialPrunedMessage extends PrunedTrial {}

// Objective type
export interface Objective {
  name: string;
  direction?: 'minimize' | 'maximize';
  unit?: string;
  weight?: number;
}

// Chart data types
export interface ConvergenceDataPoint {
  trial_number: number;
  objective: number;
  best_so_far: number;
}

export interface ParameterSpaceDataPoint {
  trial_number: number;
  x: number;
  y: number;
  objective: number;
  isBest: boolean;
}

// Study status types
export interface StudyStatus {
  study_id: string;
  status: 'not_started' | 'running' | 'paused' | 'completed';
  progress: {
    current: number;
    total: number;
  };
  best_trial: Trial | null;
  pruned_count: number;
  config: {
    [key: string]: any;
  };
}
