<?php
/**
 * القائمة البيضاء للـ IPs — عناوين لا تُحظر أبداً
 * whitelisted_ips: tenant_id, ip_address
 */
$config = require __DIR__ . '/../config/config.php';
$pdo = new PDO(
    'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['name'] . ';charset=utf8mb4',
    $config['db']['user'],
    $config['db']['pass'],
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);

$changes = [];

$pdo->exec(
    "CREATE TABLE IF NOT EXISTS whitelisted_ips (
        id INT AUTO_INCREMENT PRIMARY KEY,
        tenant_id INT NOT NULL DEFAULT 1,
        ip_address VARCHAR(45) NOT NULL,
        created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
        created_by INT NULL,
        UNIQUE KEY uk_tenant_ip (tenant_id, ip_address),
        INDEX idx_tenant (tenant_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
);
$changes[] = 'whitelisted_ips';

echo "Whitelisted IPs migration done. Changes: " . implode(', ', $changes) . "\n";
