CREATE TABLE IF NOT EXISTS kcg.vessel_analysis_results (
  id BIGSERIAL PRIMARY KEY,
  mmsi VARCHAR(15) NOT NULL,
  timestamp TIMESTAMPTZ NOT NULL,
  vessel_type VARCHAR(20),
  confidence DOUBLE PRECISION,
  fishing_pct DOUBLE PRECISION,
  cluster_id INTEGER,
  season VARCHAR(10),
  zone VARCHAR(20),
  dist_to_baseline_nm DOUBLE PRECISION,
  activity_state VARCHAR(20),
  ucaf_score DOUBLE PRECISION,
  ucft_score DOUBLE PRECISION,
  is_dark BOOLEAN DEFAULT FALSE,
  gap_duration_min INTEGER,
  spoofing_score DOUBLE PRECISION,
  bd09_offset_m DOUBLE PRECISION,
  speed_jump_count INTEGER,
  cluster_size INTEGER,
  is_leader BOOLEAN DEFAULT FALSE,
  fleet_role VARCHAR(20),
  risk_score INTEGER,
  risk_level VARCHAR(20),
  features JSONB,
  analyzed_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_vessel_analysis_mmsi ON kcg.vessel_analysis_results(mmsi);
CREATE INDEX IF NOT EXISTS idx_vessel_analysis_timestamp ON kcg.vessel_analysis_results(timestamp DESC);
