CREATE TABLE audit_events (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    public_id VARCHAR(40) NOT NULL,
    event_type VARCHAR(100) NOT NULL,
    severity VARCHAR(20) NOT NULL,
    occurred_at DATETIME(6) NOT NULL,
    request_id VARCHAR(64) NULL,
    route_name VARCHAR(150) NULL,
    method VARCHAR(16) NULL,
    path VARCHAR(255) NULL,
    status_code SMALLINT UNSIGNED NULL,
    tenant_id VARCHAR(64) NULL,
    tenant_slug VARCHAR(100) NULL,
    api_key_id VARCHAR(64) NULL,
    api_key_name VARCHAR(150) NULL,
    actor_source VARCHAR(32) NULL,
    auth_status VARCHAR(32) NULL,
    key_class VARCHAR(32) NULL,
    context JSON NULL,
    PRIMARY KEY (id),
    UNIQUE KEY audit_events_public_id_unique (public_id),
    KEY audit_events_event_type_index (event_type),
    KEY audit_events_severity_index (severity),
    KEY audit_events_occurred_at_index (occurred_at),
    KEY audit_events_tenant_id_index (tenant_id),
    KEY audit_events_api_key_id_index (api_key_id),
    KEY audit_events_request_id_index (request_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
