-- ============================================================
-- 表6：system_core_principles（Layer 1 · 核心原则表·版本化）
-- 用途：数据库OS内核级核心原则，在init时创建并填充
-- D110更新：添加shuangyan层 + axiom/meta_principle/cognitive_pattern类别
-- ============================================================

CREATE TABLE IF NOT EXISTS system_core_principles (
  principle_id      VARCHAR(32)   PRIMARY KEY,
  layer             VARCHAR(16)   NOT NULL
                    CHECK (layer IN ('bingshuo', 'zhuyuan', 'shuangyan', 'hololake', 'axiom')),
  category          VARCHAR(32)   NOT NULL
                    CHECK (category IN (
                      'core_principle', 'thinking_pattern', 'tech_creed',
                      'communication_style', 'security_rule', 'development_spec',
                      'axiom', 'meta_principle', 'cognitive_pattern',
                      'fix_pattern', 'existence_premise'
                    )),
  content           TEXT          NOT NULL,
  version           VARCHAR(16)   NOT NULL,
  status            VARCHAR(16)   NOT NULL DEFAULT 'active'
                    CHECK (status IN ('active', 'deprecated', 'superseded')),
  superseded_by     VARCHAR(32)   REFERENCES system_core_principles(principle_id),
  source            TEXT,
  created_at        TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_scp_layer ON system_core_principles(layer);
CREATE INDEX IF NOT EXISTS idx_scp_category ON system_core_principles(category);
CREATE INDEX IF NOT EXISTS idx_scp_version ON system_core_principles(version);
