-- Database Schema Update for Auto-Logout Settings
-- Add failed login attempts and auto logout settings

-- Add failed login tracking columns to users table
ALTER TABLE users ADD COLUMN IF NOT EXISTS failed_login_attempts INT DEFAULT 0 AFTER last_activity;
ALTER TABLE users ADD COLUMN IF NOT EXISTS last_failed_login DATETIME NULL AFTER failed_login_attempts;

-- Add auto logout settings to settings table  
ALTER TABLE settings ADD COLUMN IF NOT EXISTS auto_logout_enabled BOOLEAN DEFAULT 1 AFTER maintenance_mode;
ALTER TABLE settings ADD COLUMN IF NOT EXISTS auto_logout_minutes INT DEFAULT 5 AFTER auto_logout_enabled;

-- Initialize settings if not exists
INSERT INTO settings (id, site_name, site_description, maintenance_mode, auto_logout_enabled, auto_logout_minutes) 
VALUES (1, 'QuickRe', 'Secure Messaging Platform', 0, 1, 5) 
ON DUPLICATE KEY UPDATE auto_logout_enabled = 1, auto_logout_minutes = 5;
