/*
 * File: aiPrediction.ts
 * Description: Type definitions for AI Prediction module
 * Design & Developed by Tech4Biz Solutions
 * Copyright (c) Spurrin Innovations. All rights reserved.
 */

// ============================================================================
// AI PREDICTION INTERFACES
// ============================================================================

/**
 * AI Prediction Interface
 * 
 * Purpose: Define the structure of AI prediction data from the API
 * 
 * Based on API response structure:
 * - label: Type of medical finding
 * - finding_type: Category of the finding
 * - clinical_urgency: Urgency level for medical response
 * - confidence_score: AI confidence in the prediction (0-1)
 * - finding_category: General category of the finding
 * - primary_severity: Severity level of the condition
 * - anatomical_location: Where the finding is located
 */
export interface AIPrediction {
  label: string;
  finding_type: 'no_pathology' | 'pathology' | 'abnormal' | 'normal' | 'unknown';
  clinical_urgency: 'urgent' | 'moderate' | 'low' | 'routine' | 'emergency';
  confidence_score: number; // 0.0 to 1.0
  finding_category: 'normal' | 'abnormal' | 'critical' | 'warning' | 'unknown';
  primary_severity: 'high' | 'medium' | 'low' | 'none';
  anatomical_location: string; // 'not_applicable' | specific location
}

/**
 * AI Prediction Case Interface
 * 
 * Purpose: Complete AI prediction case data structure
 * 
 * Features:
 * - Patient identification
 * - Hospital association
 * - AI prediction results
 * - Metadata for tracking and display
 */
export interface AIPredictionCase {
  patid: string; // Patient ID
  hospital_id: string; // Hospital UUID
  prediction: AIPrediction;
  
  // Additional metadata (will be added for UI purposes)
  created_at?: string;
  updated_at?: string;
  reviewed_by?: string;
  review_status?: 'pending' | 'reviewed' | 'confirmed' | 'disputed';
  priority?: 'critical' | 'high' | 'medium' | 'low';
  processed_at?: string;
}

/**
 * AI Prediction API Response Interface
 * 
 * Purpose: Define the structure of API response
 */
export interface AIPredictionAPIResponse {
  success: boolean;
  data: AIPredictionCase[];
  message?: string;
  total?: number;
  page?: number;
  limit?: number;
}

/**
 * AI Prediction State Interface
 * 
 * Purpose: Define Redux state structure for AI predictions
 * 
 * Features:
 * - Prediction cases management
 * - Current selected case
 * - Loading states for async operations
 * - Error handling and messages
 * - Search and filtering
 * - Pagination support
 * - Cache management
 */
export interface AIPredictionState {
  // Prediction data
  predictionCases: AIPredictionCase[];
  currentCase: AIPredictionCase | null;
  
  // Loading states
  isLoading: boolean;
  isRefreshing: boolean;
  isLoadingCaseDetails: boolean;
  
  // Error handling
  error: string | null;
  
  // Search and filtering
  searchQuery: string;
  selectedUrgencyFilter: 'all' | 'urgent' | 'moderate' | 'low' | 'routine' | 'emergency';
  selectedSeverityFilter: 'all' | 'high' | 'medium' | 'low' | 'none';
  selectedCategoryFilter: 'all' | 'normal' | 'abnormal' | 'critical' | 'warning' | 'unknown';
  sortBy: 'date' | 'urgency' | 'confidence' | 'severity';
  sortOrder: 'asc' | 'desc';
  
  // Pagination
  currentPage: number;
  itemsPerPage: number;
  totalItems: number;
  
  // Cache management
  lastUpdated: String | null;
  cacheExpiry: String | null;
  
  // UI state
  showFilters: boolean;
  selectedCaseIds: string[];
}

/**
 * AI Prediction Filter Options
 * 
 * Purpose: Define available filter options for the UI
 */
export interface AIPredictionFilters {
  urgency: Array<{
    label: string;
    value: AIPredictionState['selectedUrgencyFilter'];
    count?: number;
  }>;
  severity: Array<{
    label: string;
    value: AIPredictionState['selectedSeverityFilter'];
    count?: number;
  }>;
  category: Array<{
    label: string;
    value: AIPredictionState['selectedCategoryFilter'];
    count?: number;
  }>;
}

/**
 * AI Prediction Statistics Interface
 * 
 * Purpose: Define statistics data for dashboard display
 */
export interface AIPredictionStats {
  totalCases: number;
  criticalCases: number;
  urgentCases: number;
  reviewedCases: number;
  pendingCases: number;
  averageConfidence: number;
  todaysCases: number;
  weeklyTrend: number; // percentage change from last week
}

/**
 * AI Prediction Navigation Props
 * 
 * Purpose: Type safety for navigation between AI prediction screens
 */
export type AIPredictionNavigationProps = {
  AIPredictionList: undefined;
  AIPredictionDetails: { caseId: string };
  AIPredictionFilters: undefined;
  AIPredictionStats: undefined;
};

// ============================================================================
// UTILITY TYPES
// ============================================================================

/**
 * Prediction Urgency Colors
 * 
 * Purpose: Map urgency levels to UI colors
 */
export const URGENCY_COLORS = {
  emergency: '#F44336', // Red
  urgent: '#FF5722',     // Deep Orange
  moderate: '#FF9800',   // Orange
  low: '#FFC107',        // Amber
  routine: '#4CAF50',    // Green
} as const;

/**
 * Prediction Severity Colors
 * 
 * Purpose: Map severity levels to UI colors
 */
export const SEVERITY_COLORS = {
  high: '#F44336',    // Red
  medium: '#FF9800',  // Orange
  low: '#FFC107',     // Amber
  none: '#4CAF50',    // Green
} as const;

/**
 * Finding Category Colors
 * 
 * Purpose: Map finding categories to UI colors
 */
export const CATEGORY_COLORS = {
  critical: '#F44336',  // Red
  abnormal: '#FF9800',  // Orange
  warning: '#FFC107',   // Amber
  normal: '#4CAF50',    // Green
  unknown: '#9E9E9E',   // Gray
} as const;

/*
 * End of File: aiPrediction.ts
 * Design & Developed by Tech4Biz Solutions
 * Copyright (c) Spurrin Innovations. All rights reserved.
 */
