-- ==========================================
-- Advance Bot Spy v12.6 - Database Structure
-- ==========================================
-- This file is for reference only
-- The installer creates these tables automatically

-- Admin Users Table
CREATE TABLE IF NOT EXISTS abs_spymaster_users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    password_hash VARCHAR(255) NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    last_login DATETIME NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Settings Table
CREATE TABLE IF NOT EXISTS abs_settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(100) UNIQUE NOT NULL,
    setting_value TEXT,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Geo Cache Table
CREATE TABLE IF NOT EXISTS abs_geo_cache (
    id INT AUTO_INCREMENT PRIMARY KEY,
    ip_address VARCHAR(45) UNIQUE NOT NULL,
    country_code VARCHAR(2) NOT NULL,
    country_name VARCHAR(100),
    cached_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    expires_at DATETIME NOT NULL,
    INDEX idx_ip (ip_address),
    INDEX idx_expires (expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Blocked Logs Table
CREATE TABLE IF NOT EXISTS abs_blocked_logs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    ip_address VARCHAR(45) NOT NULL,
    country_code VARCHAR(2),
    user_agent TEXT,
    blocked_reason VARCHAR(100) NOT NULL,
    blocked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_ip (ip_address),
    INDEX idx_date (blocked_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Default Settings (inserted by installer)
-- redirect_url_base64: base64 encoded redirect URL
-- allowed_countries: JSON array of country codes
-- enable_js_check: 1 or 0
-- enable_logging: 1 or 0

-- ==========================================
-- License System Table (v12.7)
-- ==========================================
CREATE TABLE IF NOT EXISTS `abs_license` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `license_key` varchar(255) NOT NULL,
  `valid_days` int(11) NOT NULL DEFAULT 90,
  `issued_date` datetime NOT NULL,
  `expiry_date` datetime NOT NULL,
  `status` enum('active','expired','suspended') NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `license_key` (`license_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
