/* RAIET v1.45.2 — progressive anti-abuse cooldowns.
   Run once after 033_anti_abuse_foundation.sql. */

CREATE TABLE IF NOT EXISTS security_abuse_state (
    user_id BIGINT UNSIGNED NOT NULL,
    family VARCHAR(32) NOT NULL,
    strike_count SMALLINT UNSIGNED NOT NULL DEFAULT 0,
    window_started_at DATETIME NOT NULL,
    cooldown_until DATETIME NULL,
    last_violation_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL,
    PRIMARY KEY (user_id, family),
    KEY idx_security_abuse_cooldown (cooldown_until),
    KEY idx_security_abuse_updated (updated_at),
    CONSTRAINT fk_security_abuse_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
