-- Minimal Güvenlik Sistemi SQL
-- Sadece gerekli alanlar ve tablolar

-- 1. Admins tablosuna güvenlik alanları ekle
ALTER TABLE `admins` 
ADD COLUMN IF NOT EXISTS `failed_login_attempts` int(11) DEFAULT 0,
ADD COLUMN IF NOT EXISTS `last_failed_login` timestamp NULL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS `account_locked_until` timestamp NULL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS `last_login_ip` varchar(45) DEFAULT NULL,
ADD COLUMN IF NOT EXISTS `last_logout` timestamp NULL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS `session_duration` int(11) DEFAULT NULL;

-- 2. Basit güvenlik logları tablosu (opsiyonel)
CREATE TABLE IF NOT EXISTS `security_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `admin_id` int(11) DEFAULT NULL,
  `event_type` varchar(50) NOT NULL,
  `ip_address` varchar(45) NOT NULL,
  `details` text,
  `created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_admin_id` (`admin_id`),
  KEY `idx_event_type` (`event_type`),
  KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 3. IP rate limiting tablosu (minimal)
CREATE TABLE IF NOT EXISTS `ip_limits` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ip_address` varchar(45) NOT NULL,
  `action` varchar(50) NOT NULL,
  `attempts` int(11) DEFAULT 1,
  `last_attempt` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `blocked_until` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ip_action` (`ip_address`, `action`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;