/**
 * Forecasting API Types
 * Mirror of backend forecasting service schemas
 */

// ================================================================
// ENUMS
// ================================================================

export enum BusinessType {
  INDIVIDUAL = "individual",
  CENTRAL_WORKSHOP = "central_workshop",
}

// ================================================================
// REQUEST TYPES
// ================================================================

export interface ForecastRequest {
  inventory_product_id: string;
  forecast_date: string; // ISO date string
  forecast_days?: number; // Default: 1, Min: 1, Max: 30
  location: string;
  confidence_level?: number; // Default: 0.8, Min: 0.5, Max: 0.95
}

export interface BatchForecastRequest {
  tenant_id: string;
  batch_name: string;
  inventory_product_ids: string[];
  forecast_days?: number; // Default: 7, Min: 1, Max: 30
}

// ================================================================
// RESPONSE TYPES
// ================================================================

export interface ForecastResponse {
  id: string;
  tenant_id: string;
  inventory_product_id: string;
  location: string;
  forecast_date: string; // ISO datetime string
  
  // Predictions
  predicted_demand: number;
  confidence_lower: number;
  confidence_upper: number;
  confidence_level: number;
  
  // Model info
  model_id: string;
  model_version: string;
  algorithm: string;
  
  // Context
  business_type: string;
  is_holiday: boolean;
  is_weekend: boolean;
  day_of_week: number;
  
  // External factors
  weather_temperature?: number;
  weather_precipitation?: number;
  weather_description?: string;
  traffic_volume?: number;
  
  // Metadata
  created_at: string; // ISO datetime string
  processing_time_ms?: number;
  features_used?: Record<string, any>;
}

export interface BatchForecastResponse {
  id: string;
  tenant_id: string;
  batch_name: string;
  status: string;
  total_products: number;
  completed_products: number;
  failed_products: number;
  
  // Timing
  requested_at: string; // ISO datetime string
  completed_at?: string; // ISO datetime string
  processing_time_ms?: number;
  
  // Results
  forecasts?: ForecastResponse[];
  error_message?: string;
}

export interface ForecastStatistics {
  tenant_id: string;
  total_forecasts: number;
  recent_forecasts: number;
  accuracy_metrics: {
    average_accuracy: number;
    accuracy_trend: number;
  };
  model_performance: {
    most_used_algorithm: string;
    average_processing_time: number;
  };
  enhanced_features: boolean;
  repository_integration: boolean;
}

export interface ForecastListResponse {
  tenant_id: string;
  forecasts: ForecastResponse[];
  total_returned: number;
  filters: {
    inventory_product_id?: string;
    start_date?: string; // ISO date string
    end_date?: string; // ISO date string
  };
  pagination: {
    skip: number;
    limit: number;
  };
  enhanced_features: boolean;
  repository_integration: boolean;
}

export interface ForecastByIdResponse extends ForecastResponse {
  enhanced_features: boolean;
  repository_integration: boolean;
}

export interface DeleteForecastResponse {
  message: string;
  forecast_id: string;
  enhanced_features: boolean;
  repository_integration: boolean;
}

// ================================================================
// QUERY PARAMETERS
// ================================================================

export interface GetForecastsParams {
  inventory_product_id?: string;
  start_date?: string; // ISO date string
  end_date?: string; // ISO date string
  skip?: number; // Default: 0
  limit?: number; // Default: 100
}

// ================================================================
// HEALTH CHECK
// ================================================================

export interface ForecastingHealthResponse {
  status: string;
  service: string;
  version: string;
  features: string[];
  timestamp: string;
}

export interface MultiDayForecastResponse {
  tenant_id: string;
  inventory_product_id: string;
  forecast_start_date: string; // ISO date string
  forecast_days: number;
  forecasts: ForecastResponse[];
  total_predicted_demand: number;
  average_confidence_level: number;
  processing_time_ms: number;
}