/**
 * Performance Analytics Types
 * Comprehensive types for performance monitoring across all departments
 */

// ============================================================================
// Overview Metrics
// ============================================================================

export interface PerformanceOverview {
  overall_efficiency: number;
  average_production_time: number;
  quality_score: number;
  employee_productivity: number;
  customer_satisfaction: number;
  resource_utilization: number;
}

// ============================================================================
// Department Performance
// ============================================================================

export interface DepartmentPerformance {
  department_id: string;
  department_name: string;
  efficiency: number;
  trend: 'up' | 'down' | 'stable';
  metrics: DepartmentMetrics;
}

export interface DepartmentMetrics {
  primary_metric: MetricValue;
  secondary_metric: MetricValue;
  tertiary_metric: MetricValue;
}

export interface MetricValue {
  label: string;
  value: number;
  unit: string;
  trend?: number;
}

// Production Department
export interface ProductionPerformance {
  efficiency: number;
  average_batch_time: number;
  quality_rate: number;
  waste_percentage: number;
  capacity_utilization: number;
  equipment_efficiency: number;
  on_time_completion_rate: number;
  yield_rate: number;
}

// Inventory Department
export interface InventoryPerformance {
  stock_accuracy: number;
  turnover_rate: number;
  waste_rate: number;
  low_stock_count: number;
  compliance_rate: number;
  expiring_items_count: number;
  stock_value: number;
}

// Sales Department
export interface SalesPerformance {
  total_revenue: number;
  total_transactions: number;
  average_transaction_value: number;
  growth_rate: number;
  channel_performance: ChannelPerformance[];
  top_products: ProductPerformance[];
}

export interface ChannelPerformance {
  channel: string;
  revenue: number;
  transactions: number;
  percentage: number;
}

export interface ProductPerformance {
  product_id: string;
  product_name: string;
  sales: number;
  revenue: number;
}

// Procurement/Administration Department
export interface ProcurementPerformance {
  fulfillment_rate: number;
  on_time_delivery_rate: number;
  cost_accuracy: number;
  supplier_performance_score: number;
  active_plans: number;
  critical_requirements: number;
}

// ============================================================================
// KPI Tracking
// ============================================================================

export interface KPIMetric {
  id: string;
  name: string;
  current_value: number;
  target_value: number;
  previous_value: number;
  unit: string;
  trend: 'up' | 'down' | 'stable';
  status: 'good' | 'warning' | 'critical';
}

// ============================================================================
// Performance Alerts
// ============================================================================

export interface PerformanceAlert {
  id: string;
  type: 'warning' | 'critical' | 'info';
  department: string;
  message: string;
  timestamp: string;
  metric_affected: string;
  current_value?: number;
  threshold_value?: number;
}

// ============================================================================
// Time-Series Data
// ============================================================================

export interface TimeSeriesData {
  timestamp: string;
  value: number;
  label?: string;
}

export interface HourlyProductivity {
  hour: string;
  efficiency: number;
  production_count: number;
  sales_count: number;
}

// ============================================================================
// Aggregated Dashboard Data
// ============================================================================

export interface PerformanceDashboard {
  overview: PerformanceOverview;
  departments: DepartmentPerformance[];
  kpis: KPIMetric[];
  alerts: PerformanceAlert[];
  hourly_data: HourlyProductivity[];
  last_updated: string;
}

// ============================================================================
// Filter and Query Parameters
// ============================================================================

export type TimePeriod = 'day' | 'week' | 'month' | 'quarter' | 'year';
export type MetricType = 'efficiency' | 'productivity' | 'quality' | 'satisfaction';

export interface PerformanceFilters {
  period: TimePeriod;
  metric_type?: MetricType;
  start_date?: string;
  end_date?: string;
  departments?: string[];
}

// ============================================================================
// Trend Analysis
// ============================================================================

export interface TrendData {
  date: string;
  value: number;
  comparison_value?: number;
}

export interface PerformanceTrend {
  metric_name: string;
  current_period: TrendData[];
  previous_period: TrendData[];
  change_percentage: number;
  trend_direction: 'up' | 'down' | 'stable';
}
