CREATE TABLE IF NOT EXISTS users (
  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(100) NOT NULL,
  email VARCHAR(190) NOT NULL UNIQUE,
  password_hash VARCHAR(255) NOT NULL,
  hwid VARCHAR(128) NULL,
  status ENUM('Active','Not Active','Blocked') NOT NULL DEFAULT 'Not Active',
  expires_at DATETIME NULL,
  info VARCHAR(255) NULL,
  last_login_at DATETIME NULL,
  last_ip VARCHAR(45) NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_status(status),
  INDEX idx_expires(expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS api_rate_limits (
  ip VARCHAR(45) NOT NULL,
  scope VARCHAR(50) NOT NULL,
  last_seen DATETIME NOT NULL,
  PRIMARY KEY(ip, scope)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
