-- ============================================================
-- 表14：audit_log_guanghu（审计日志 · 光湖操作 · append-only）
-- 用途：光湖系统内部操作审计，冰朔操作记录
-- 与audit_log_national分开存储，用于双面灯塔审计分离
-- ============================================================

CREATE TABLE IF NOT EXISTS audit_log_guanghu (
  log_id            INTEGER       PRIMARY KEY AUTOINCREMENT,
  operation         VARCHAR(64)   NOT NULL,
  actor_id          VARCHAR(32)   NOT NULL,        -- 人格体ID或冰朔标识
  target_type       VARCHAR(32),
  target_id         VARCHAR(64),
  details           TEXT,                          -- JSON object
  ip_address        VARCHAR(45),
  result            VARCHAR(16)   NOT NULL
                    CHECK (result IN ('success', 'failure', 'pending')),
  checksum          VARCHAR(128),                   -- optional integrity check
  timestamp         TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_alg_actor ON audit_log_guanghu(actor_id);
CREATE INDEX IF NOT EXISTS idx_alg_timestamp ON audit_log_guanghu(timestamp);
