-- DecisionEngine-ready decision log for Otto Chat.
-- Run manually outside Cursor. Documentation only.

CREATE TABLE IF NOT EXISTS otto_chat_decision_log (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    trace_id VARCHAR(64) NOT NULL,
    session_id VARCHAR(128) NULL,
    decision_type VARCHAR(64) NOT NULL,
    authority_source VARCHAR(32) NOT NULL,
    deterministic_confidence DECIMAL(5,4) NULL,
    advisory_confidence DECIMAL(5,4) NULL,
    confidence_band VARCHAR(32) NOT NULL,
    model_used VARCHAR(128) NULL,
    tokens_prompt INT NULL,
    tokens_completion INT NULL,
    tokens_total INT NULL,
    cost_usd DECIMAL(10,6) NULL,
    latency_ms INT NULL,
    environment VARCHAR(16) NOT NULL,
    user_input TEXT NULL,
    system_output TEXT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_trace_id (trace_id),
    INDEX idx_created_at (created_at),
    INDEX idx_environment (environment)
);
