-- ============================================================
-- 表13：audit_log_user（审计日志 · 用户操作 · append-only）
-- 用途：普通用户级别的操作审计
-- ============================================================

CREATE TABLE IF NOT EXISTS audit_log_user (
  log_id            INTEGER       PRIMARY KEY AUTOINCREMENT,
  operation         VARCHAR(64)   NOT NULL,
  actor_id          VARCHAR(64)   NOT NULL,        -- 用户ID
  target_type       VARCHAR(32),
  target_id         VARCHAR(64),
  details           TEXT,                          -- JSON object
  ip_address        VARCHAR(45),
  user_agent        VARCHAR(256),
  result            VARCHAR(16)   NOT NULL
                    CHECK (result IN ('success', 'failure', 'pending')),
  timestamp         TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_alu_actor ON audit_log_user(actor_id);
CREATE INDEX IF NOT EXISTS idx_alu_operation ON audit_log_user(operation);
CREATE INDEX IF NOT EXISTS idx_alu_timestamp ON audit_log_user(timestamp);
