-- Phase F: After-Action / Nachbereitung (Incident Report)
-- Depends on migrations/001_init.sql (tables: incident, app_user, etc.)

CREATE TABLE IF NOT EXISTS incident_report (
  incident_id uuid PRIMARY KEY
    REFERENCES incident(id) ON DELETE CASCADE,

  author_user_id bigint
    REFERENCES app_user(id) ON DELETE SET NULL,

  summary text,
  outcome text,
  lessons text,

  timeline_json jsonb NOT NULL DEFAULT '[]'::jsonb,
  attachments_json jsonb NOT NULL DEFAULT '[]'::jsonb,
  meta_json jsonb NOT NULL DEFAULT '{}'::jsonb,

  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_incident_report_updated_at
  ON incident_report(updated_at DESC);
