-- 003_add_ai_labels.sql
-- 为 episodes 表添加 AI 打标字段（看板升级 L2→L3 桥梁）
-- 前置：执行前先 pg_dump 备份
-- 全部 nullable，不影响现有数据

ALTER TABLE episodes
  ADD COLUMN IF NOT EXISTS program_format        VARCHAR(20),
  ADD COLUMN IF NOT EXISTS equipment_domain      JSONB,
  ADD COLUMN IF NOT EXISTS scene_tags            JSONB,
  ADD COLUMN IF NOT EXISTS tech_tags             JSONB,
  ADD COLUMN IF NOT EXISTS narrative_structure   VARCHAR(20),
  ADD COLUMN IF NOT EXISTS opening_hook          VARCHAR(10),
  ADD COLUMN IF NOT EXISTS ai_label_confidence   VARCHAR(10);

-- 分析引擎常用分组查询索引
CREATE INDEX IF NOT EXISTS idx_episodes_program_format      ON episodes (program_format);
CREATE INDEX IF NOT EXISTS idx_episodes_narrative_structure  ON episodes (narrative_structure);
CREATE INDEX IF NOT EXISTS idx_episodes_ai_label_confidence  ON episodes (ai_label_confidence);

COMMENT ON COLUMN episodes.program_format       IS '主题材(单选): 装备深解/横切类比/历史纵深/前沿科技/事件战例/人物牵引';
COMMENT ON COLUMN episodes.equipment_domain     IS '装备域(多选JSONB数组): 陆战装备/海军舰船/航空航天/导弹与反导/信息化/后勤保障/轻武器/跨域/其他';
COMMENT ON COLUMN episodes.scene_tags           IS '场景标签(多选JSONB数组): 节点策划/热点跟进/装备首发/展会';
COMMENT ON COLUMN episodes.tech_tags            IS '技术线标签(多选JSONB数组): 无人作战/智能化/有人无人协同';
COMMENT ON COLUMN episodes.narrative_structure  IS '叙事结构(单选): 主线演进/并列结构';
COMMENT ON COLUMN episodes.opening_hook         IS '开篇钩子(单选): 强/中/弱';
COMMENT ON COLUMN episodes.ai_label_confidence  IS '打标状态: draft(AI草稿)/reviewed(制片人确认)/inferred(标题推断)';
