// System types
export interface SystemInfo {
  name: string
  version: string
  environment: string
  api_version: string
  features: {
    recipe_management: boolean
    process_control: boolean
    hardware_monitoring: boolean
    safety_monitoring: boolean
    user_management: boolean
    real_time_monitoring: boolean
  }
  endpoints: {
    recipes: string
    process: string
    hardware: string
    users: string
    system: string
    health: string
  }
}

export interface SystemStatus {
  system_status: 'healthy' | 'warning' | 'critical'
  process_status: 'idle' | 'running' | 'paused' | 'error'
  hardware_status: 'connected' | 'disconnected' | 'error'
  safety_status: 'safe' | 'warning' | 'alarm'
  active_alarms: number
  uptime_seconds: number
  last_updated: string
}

// Recipe types
export interface Recipe {
  id: number
  name: string
  description?: string
  chocolate_type: 'dark' | 'milk' | 'white'
  target_temperature_c: number
  heating_duration_min: number
  cooling_duration_min: number
  stirring_speed_rpm: number
  total_time_min: number
  is_active: boolean
  created_at: string
  updated_at: string
  created_by?: string
}

export interface RecipeCreate {
  name: string
  description?: string
  chocolate_type: 'dark' | 'milk' | 'white'
  target_temperature_c: number
  heating_duration_min: number
  cooling_duration_min: number
  stirring_speed_rpm: number
  total_time_min: number
}

export interface RecipeUpdate extends Partial<RecipeCreate> {
  is_active?: boolean
}

export interface RecipeList {
  recipes: Recipe[]
  total: number
  skip: number
  limit: number
}

// Process types
export interface ProcessStatus {
  session_id: string | null
  recipe_id: number | null
  recipe_name: string | null
  status: 'idle' | 'running' | 'paused' | 'completed' | 'error'
  current_phase: 'heating' | 'cooling' | 'stirring' | 'pouring' | 'idle' | null
  started_at: string | null
  duration_seconds: number | null
  started_by: string | null
  current_temperature: number | null
  target_temperature: number | null
  temperature_error: number | null
  error_count: number
  warning_count: number
  is_running: boolean
}

export interface ProcessStartRequest {
  recipe_id: number
  user_id?: string
}

export interface ProcessActionResponse {
  success: boolean
  message: string
  session_id?: string
}

// Hardware types
export interface HardwareStatus {
  connection_status: 'connected' | 'disconnected' | 'error'
  modbus_status: 'online' | 'offline' | 'error'
  temperature_sensors: TemperatureSensor[]
  motors: Motor[]
  last_communication: string
}

export interface TemperatureSensor {
  id: string
  name: string
  current_temp_c: number
  status: 'normal' | 'warning' | 'error'
  last_reading: string
}

export interface Motor {
  id: string
  name: string
  is_running: boolean
  current_speed_rpm: number
  target_speed_rpm: number
  current_amps: number
  status: 'normal' | 'warning' | 'error'
}

// Safety types
export interface SafetyStatus {
  overall_status: 'safe' | 'warning' | 'alarm'
  emergency_stop_active: boolean
  temperature_alarms: AlarmInfo[]
  motor_alarms: AlarmInfo[]
  system_alarms: AlarmInfo[]
  active_alarm_count: number
}

export interface AlarmInfo {
  id: string
  type: 'temperature' | 'motor' | 'system'
  severity: 'low' | 'medium' | 'high' | 'critical'
  message: string
  timestamp: string
  acknowledged: boolean
}

// User types
export interface User {
  id: string
  username: string
  email: string
  full_name: string
  role: 'operator' | 'supervisor' | 'admin'
  is_active: boolean
  created_at: string
  last_login?: string
}

export interface UserCreate {
  username: string
  email: string
  full_name: string
  password: string
  role: 'operator' | 'supervisor' | 'admin'
}

export interface UserUpdate extends Partial<Omit<UserCreate, 'password'>> {
  is_active?: boolean
  password?: string
}

// WebSocket types
export interface WebSocketMessage {
  type: 'process_update' | 'hardware_update' | 'safety_alert' | 'system_status'
  data: any
  timestamp: string
}

// API Response types
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  error?: string
  message?: string
}

// Chart data types
export interface TemperatureDataPoint {
  timestamp: string
  temperature: number
  target: number
  phase: string
}

export interface ProcessMetrics {
  total_sessions: number
  successful_sessions: number
  failed_sessions: number
  average_duration_min: number
  temperature_efficiency: number
  last_updated: string
}

// Error types
export interface ApiError {
  message: string
  status?: number
  code?: string
}

export interface SystemError {
  id: string
  type: 'hardware' | 'process' | 'safety' | 'system'
  severity: 'low' | 'medium' | 'high' | 'critical'
  message: string
  details?: string
  timestamp: string
  resolved: boolean
}
