export interface GeoEvent {
  id: string;
  timestamp: number; // unix ms
  lat: number;
  lng: number;
  type: 'airstrike' | 'explosion' | 'missile_launch' | 'intercept' | 'alert' | 'impact' | 'osint';
  source?: 'US' | 'IL' | 'IR' | 'proxy'; // 공격 주체: 미국, 이스라엘, 이란, 대리세력
  label: string;
  description?: string;
  intensity?: number; // 0-100
  imageUrl?: string;  // 뉴스/위성 사진 URL
  imageCaption?: string; // 사진 설명
}

export interface SensorLog {
  timestamp: number;
  seismic: number;       // seismic activity level 0-100
  airPressure: number;   // hPa
  noiseLevel: number;    // dB
  radiationLevel: number; // uSv/h
}

export interface ReplayState {
  isPlaying: boolean;
  currentTime: number;   // unix ms
  startTime: number;     // unix ms
  endTime: number;       // unix ms
  speed: number;         // 1x, 2x, 4x, 8x
}

export interface ApiConfig {
  eventsEndpoint: string;
  sensorEndpoint: string;
  pollIntervalMs: number;
}

// Aircraft tracking
export type AircraftCategory = 'military' | 'tanker' | 'surveillance' | 'fighter' | 'cargo' | 'civilian' | 'unknown';

export interface Aircraft {
  icao24: string;        // ICAO 24-bit hex address
  callsign: string;
  lat: number;
  lng: number;
  altitude: number;      // meters
  velocity: number;      // m/s
  heading: number;       // degrees
  verticalRate: number;  // m/s
  onGround: boolean;
  category: AircraftCategory;
  typecode?: string;     // e.g. "KC135", "RC135", "RQ4"
  typeDesc?: string;     // e.g. "AIRBUS A-350-1000"
  registration?: string; // e.g. "A6-XWC"
  operator?: string;     // e.g. "United Arab Emirates"
  squawk?: string;       // transponder code
  trail?: [number, number][]; // recent positions [lat, lng]
  lastSeen: number;      // unix ms
  activeStart?: number;  // unix ms - when aircraft enters area
  activeEnd?: number;    // unix ms - when aircraft leaves area
}

// Satellite tracking
export interface Satellite {
  noradId: number;
  name: string;
  tle1: string;
  tle2: string;
  category: 'reconnaissance' | 'communications' | 'navigation' | 'weather' | 'other';
}

export interface SatellitePosition {
  noradId: number;
  name: string;
  lat: number;
  lng: number;
  altitude: number;      // km
  category: Satellite['category'];
  groundTrack?: [number, number][]; // predicted ground track
}

// Ship tracking (AIS)
export type ShipCategory = 'warship' | 'carrier' | 'destroyer' | 'submarine' | 'cargo' | 'tanker' | 'patrol' | 'fishing' | 'civilian' | 'unknown';

export interface Ship {
  mmsi: string;          // Maritime Mobile Service Identity
  name: string;
  lat: number;
  lng: number;
  heading: number;       // degrees
  speed: number;         // knots
  course: number;        // course over ground
  category: ShipCategory;
  flag?: string;         // country code
  typecode?: string;
  typeDesc?: string;     // e.g. "Cargo ship"
  imo?: string;          // IMO number
  callSign?: string;
  status?: string;       // "Under way using engine", "Anchored", etc.
  destination?: string;
  eta?: string;          // ISO date
  draught?: number;      // meters
  length?: number;       // meters
  width?: number;        // meters
  trail?: [number, number][];
  lastSeen: number;      // unix ms
  activeStart?: number;  // unix ms - when ship enters area
  activeEnd?: number;    // unix ms - when ship leaves area
  shipImagePath?: string | null;  // signal-batch image path
  shipImageCount?: number;        // number of available images
}

// Iran oil/gas facility
export type OilFacilityType = 'refinery' | 'oilfield' | 'gasfield' | 'terminal' | 'petrochemical' | 'desalination';

export interface OilFacility {
  id: string;
  name: string;
  nameKo: string;
  lat: number;
  lng: number;
  type: OilFacilityType;
  capacityBpd?: number;    // barrels per day (oil)
  capacityMcfd?: number;   // million cubic feet per day (gas)
  capacityMgd?: number;    // million gallons per day (desalination)
  reservesBbl?: number;    // billion barrels (oil reserves)
  reservesTcf?: number;    // trillion cubic feet (gas reserves)
  operator?: string;
  description?: string;
  damaged?: boolean;       // hit during strikes
  damagedAt?: number;      // unix ms — time when facility was struck
  planned?: boolean;       // planned US strike target
  plannedLabel?: string;   // planned strike description
}

// Layer visibility
export interface LayerVisibility {
  events: boolean;
  aircraft: boolean;
  satellites: boolean;
  ships: boolean;
  koreanShips: boolean;
  airports: boolean;
  sensorCharts: boolean;
  oilFacilities: boolean;
  meFacilities: boolean;
  militaryOnly: boolean;
}

export type AppMode = 'replay' | 'live';

// Vessel analysis (Python prediction 결과)
export type VesselType = 'TRAWL' | 'PURSE' | 'LONGLINE' | 'TRAP' | 'UNKNOWN';
export type RiskLevel = 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW';
export type ActivityState = 'STATIONARY' | 'FISHING' | 'SAILING' | 'UNKNOWN';
export type FleetRole = 'LEADER' | 'MEMBER' | 'NOISE';

export interface VesselAnalysisDto {
  mmsi: string;
  timestamp: string;
  classification: {
    vesselType: VesselType;
    confidence: number;
    fishingPct: number;
    clusterId: number;
    season: string;
  };
  algorithms: {
    location: { zone: string; distToBaselineNm: number };
    activity: { state: ActivityState; ucafScore: number; ucftScore: number };
    darkVessel: { isDark: boolean; gapDurationMin: number };
    gpsSpoofing: { spoofingScore: number; bd09OffsetM: number; speedJumpCount: number };
    cluster: { clusterId: number; clusterSize: number };
    fleetRole: { isLeader: boolean; role: FleetRole };
    riskScore: { score: number; level: RiskLevel };
  };
  features: Record<string, number>;
}
