-- VERIFICATION_STAMP
-- Story: 1.01 (Track A — AIVA RLM Nexus)
-- Verified By: parallel-builder
-- Tests: 5/5 PASS

-- data/migrations/001_royal_conversations.sql
-- AIVA RLM Nexus — Story 1.01: Royal Conversations Schema
-- Idempotent: safe to re-run

CREATE EXTENSION IF NOT EXISTS "pgcrypto";

CREATE TABLE IF NOT EXISTS royal_conversations (
  conversation_id    UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  started_at         TIMESTAMP NOT NULL,
  ended_at           TIMESTAMP,
  participants       JSONB NOT NULL DEFAULT '{"kinan": false, "aiva": false}',
  transcript_raw     TEXT,
  transcript_chunks  JSONB DEFAULT '[]',
  enriched_entities  JSONB DEFAULT '[]',
  decisions_made     JSONB DEFAULT '[]',
  action_items       JSONB DEFAULT '[]',
  emotional_signal   VARCHAR(20) CHECK (emotional_signal IN ('positive','neutral','frustrated','excited','urgent')),
  key_facts          JSONB DEFAULT '[]',
  kinan_directives   JSONB DEFAULT '[]',
  memory_vector_id   UUID,
  created_at         TIMESTAMP DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_royal_conv_started ON royal_conversations(started_at DESC);
CREATE INDEX IF NOT EXISTS idx_royal_conv_participants ON royal_conversations USING GIN(participants);
