export enum ProductionStatusEnum {
  PENDING = "pending",
  IN_PROGRESS = "in_progress",
  COMPLETED = "completed",
  CANCELLED = "cancelled",
  ON_HOLD = "on_hold",
  QUALITY_CHECK = "quality_check",
  FAILED = "failed"
}

export enum ProductionPriorityEnum {
  LOW = "low",
  MEDIUM = "medium",
  HIGH = "high",
  URGENT = "urgent"
}

export enum ProductionBatchStatus {
  PLANNED = "planned",
  IN_PROGRESS = "in_progress",
  COMPLETED = "completed",
  CANCELLED = "cancelled",
  ON_HOLD = "on_hold"
}

export enum QualityCheckStatus {
  PENDING = "pending",
  IN_PROGRESS = "in_progress",
  PASSED = "passed",
  FAILED = "failed",
  REQUIRES_ATTENTION = "requires_attention"
}

export interface ProductionBatchBase {
  product_id: string;
  product_name: string;
  recipe_id?: string | null;
  planned_start_time: string;
  planned_end_time: string;
  planned_quantity: number;
  planned_duration_minutes: number;
  priority: ProductionPriorityEnum;
  is_rush_order: boolean;
  is_special_recipe: boolean;
  production_notes?: string | null;
}

export interface ProductionBatchCreate extends ProductionBatchBase {
  batch_number?: string | null;
  order_id?: string | null;
  forecast_id?: string | null;
  equipment_used?: string[] | null;
  staff_assigned?: string[] | null;
  station_id?: string | null;
}

export interface ProductionBatchUpdate {
  product_name?: string | null;
  planned_start_time?: string | null;
  planned_end_time?: string | null;
  planned_quantity?: number | null;
  planned_duration_minutes?: number | null;
  actual_quantity?: number | null;
  priority?: ProductionPriorityEnum | null;
  equipment_used?: string[] | null;
  staff_assigned?: string[] | null;
  station_id?: string | null;
  production_notes?: string | null;
}

export interface ProductionBatchStatusUpdate {
  status: ProductionStatusEnum;
  actual_quantity?: number | null;
  notes?: string | null;
}

export interface ProductionBatchResponse {
  id: string;
  tenant_id: string;
  batch_number: string;
  product_id: string;
  product_name: string;
  recipe_id?: string | null;
  planned_start_time: string;
  planned_end_time: string;
  planned_quantity: number;
  planned_duration_minutes: number;
  actual_start_time?: string | null;
  actual_end_time?: string | null;
  actual_quantity?: number | null;
  actual_duration_minutes?: number | null;
  status: ProductionStatusEnum;
  priority: ProductionPriorityEnum;
  estimated_cost?: number | null;
  actual_cost?: number | null;
  yield_percentage?: number | null;
  quality_score?: number | null;
  equipment_used?: string[] | null;
  staff_assigned?: string[] | null;
  station_id?: string | null;
  order_id?: string | null;
  forecast_id?: string | null;
  is_rush_order: boolean;
  is_special_recipe: boolean;
  production_notes?: string | null;
  quality_notes?: string | null;
  delay_reason?: string | null;
  cancellation_reason?: string | null;
  created_at: string;
  updated_at: string;
  completed_at?: string | null;
}

export interface ProductionScheduleBase {
  schedule_date: string;
  shift_start: string;
  shift_end: string;
  total_capacity_hours: number;
  planned_capacity_hours: number;
  staff_count: number;
  equipment_capacity?: Record<string, any> | null;
  station_assignments?: Record<string, any> | null;
  schedule_notes?: string | null;
}

export interface ProductionScheduleCreate extends ProductionScheduleBase {}

export interface ProductionScheduleUpdate {
  shift_start?: string | null;
  shift_end?: string | null;
  total_capacity_hours?: number | null;
  planned_capacity_hours?: number | null;
  staff_count?: number | null;
  overtime_hours?: number | null;
  equipment_capacity?: Record<string, any> | null;
  station_assignments?: Record<string, any> | null;
  schedule_notes?: string | null;
}

export interface ProductionScheduleResponse {
  id: string;
  tenant_id: string;
  schedule_date: string;
  shift_start: string;
  shift_end: string;
  total_capacity_hours: number;
  planned_capacity_hours: number;
  actual_capacity_hours?: number | null;
  overtime_hours?: number | null;
  staff_count: number;
  equipment_capacity?: Record<string, any> | null;
  station_assignments?: Record<string, any> | null;
  total_batches_planned: number;
  total_batches_completed?: number | null;
  total_quantity_planned: number;
  total_quantity_produced?: number | null;
  is_finalized: boolean;
  is_active: boolean;
  efficiency_percentage?: number | null;
  utilization_percentage?: number | null;
  on_time_completion_rate?: number | null;
  schedule_notes?: string | null;
  schedule_adjustments?: Record<string, any> | null;
  created_at: string;
  updated_at: string;
  finalized_at?: string | null;
}

export interface QualityCheckBase {
  batch_id: string;
  check_type: string;
  check_time: string;
  quality_score: number;
  pass_fail: boolean;
  defect_count: number;
  defect_types?: string[] | null;
  check_notes?: string | null;
}

export interface QualityCheckCreate extends QualityCheckBase {
  checker_id?: string | null;
  measured_weight?: number | null;
  measured_temperature?: number | null;
  measured_moisture?: number | null;
  measured_dimensions?: Record<string, number> | null;
  target_weight?: number | null;
  target_temperature?: number | null;
  target_moisture?: number | null;
  tolerance_percentage?: number | null;
  corrective_actions?: string[] | null;
}

export interface QualityCheckResponse {
  id: string;
  tenant_id: string;
  batch_id: string;
  check_type: string;
  check_time: string;
  checker_id?: string | null;
  quality_score: number;
  pass_fail: boolean;
  defect_count: number;
  defect_types?: string[] | null;
  measured_weight?: number | null;
  measured_temperature?: number | null;
  measured_moisture?: number | null;
  measured_dimensions?: Record<string, number> | null;
  target_weight?: number | null;
  target_temperature?: number | null;
  target_moisture?: number | null;
  tolerance_percentage?: number | null;
  within_tolerance?: boolean | null;
  corrective_action_needed: boolean;
  corrective_actions?: string[] | null;
  check_notes?: string | null;
  photos_urls?: string[] | null;
  certificate_url?: string | null;
  created_at: string;
  updated_at: string;
}

export interface ProductionDashboardSummary {
  active_batches: number;
  todays_production_plan: Record<string, any>[];
  capacity_utilization: number;
  on_time_completion_rate: number;
  average_quality_score: number;
  total_output_today: number;
  efficiency_percentage: number;
}

export interface DailyProductionRequirements {
  date: string;
  production_plan: Record<string, any>[];
  total_capacity_needed: number;
  available_capacity: number;
  capacity_gap: number;
  urgent_items: number;
  recommended_schedule?: Record<string, any> | null;
}

export interface ProductionMetrics {
  period_start: string;
  period_end: string;
  total_batches: number;
  completed_batches: number;
  completion_rate: number;
  average_yield_percentage: number;
  on_time_completion_rate: number;
  total_production_cost: number;
  average_quality_score: number;
  efficiency_trends: Record<string, any>[];
}

export interface ProductionBatchListResponse {
  batches: ProductionBatchResponse[];
  total_count: number;
  page: number;
  page_size: number;
}

export interface ProductionScheduleListResponse {
  schedules: ProductionScheduleResponse[];
  total_count: number;
  page: number;
  page_size: number;
}

export interface QualityCheckListResponse {
  quality_checks: QualityCheckResponse[];
  total_count: number;
  page: number;
  page_size: number;
}

export interface ProductionScheduleData {
  start_date: string;
  end_date: string;
  schedules: {
    id: string;
    date: string;
    shift_start: string;
    shift_end: string;
    capacity_utilization: number;
    batches_planned: number;
    is_finalized: boolean;
  }[];
  total_schedules: number;
}

export interface ProductionCapacityStatus {
  [key: string]: any;
}

export interface ProductionRequirements {
  [key: string]: any;
}

export interface ProductionYieldMetrics {
  [key: string]: any;
}