export interface BurstDetectionRow {
  Day: number;
  Score: number;
  Prediction: number;
  IsBurst: boolean;
  Timestamp?: string;
  Role?: "reference" | "target";
}

export interface BurstDetectionSensorRanking {
  sensor_node: string;
  latest_high_frequency_value: number;
  historical_mean?: number;
  historical_std?: number;
  standardized_deviation?: number;
}

export interface BurstDetectionSummary {
  burst_detected: boolean;
  latest_day: BurstDetectionRow;
  most_anomalous_day: number;
  anomaly_days: number[];
  anomaly_day_count: number;
  latest_sensor_rankings: BurstDetectionSensorRanking[];
  target_score?: number;
  score_threshold?: number;
  target_rank?: number;
  target_time?: string;
  reference_day_count?: number;
}

export interface BurstDetectionAlgorithmParams {
  mu?: number;
  points_per_day?: number;
  iforest_params?: {
    n_estimators?: number;
    contamination?: number | "auto";
    random_state?: number;
  };
  score_threshold?: number;
}

export interface BurstDetectionResult {
  network: string;
  sensor_nodes: string[];
  observed_source: string;
  sample_count: number;
  points_per_day: number;
  day_count: number;
  rows: BurstDetectionRow[];
  summary: BurstDetectionSummary;
  scada_window?: {
    start?: string;
    end?: string;
  };
  scheme_name?: string;
  username?: string;
  create_time?: string;
  data_source?: "monitoring" | "simulation";
  simulation_scheme?: {
    name?: string;
    type?: string;
  };
  algorithm_params?: BurstDetectionAlgorithmParams;
  requested_target_time?: string | null;
  target_time?: string;
  reference_window?: {
    start: string;
    end: string;
    day_count: number;
  };
  sampling_interval_minutes?: number;
  daily_scores?: Array<{
    timestamp: string;
    role: "reference" | "target";
    score: number;
    raw_prediction: number;
  }>;
  data_quality?: {
    included_sensors: string[];
    excluded_sensors: Array<{ sensor_node: string; reason: string }>;
    minimum_required_sensors: number;
  };
}

export interface BurstDetectionSchemeDetail {
  network?: string;
  sensor_nodes?: string[];
  observed_source?: string;
  scada_window?: {
    start?: string;
    end?: string;
  };
  algorithm_params?: BurstDetectionAlgorithmParams;
  result_summary?: BurstDetectionSummary;
  result_payload?: BurstDetectionResult;
}

export interface BurstDetectionSchemeRecord {
  scheme_id: number;
  scheme_name: string;
  scheme_type?: string;
  create_time: string;
  scheme_start_time?: string;
  username?: string;
  scheme_detail?: BurstDetectionSchemeDetail;
}
