<?php
require_once __DIR__ . '/../../public/vendor/autoload.php';

$dsn = 'mysql:host=127.0.0.1;dbname=projects_membershipdb;charset=utf8mb4';
$user = 'root';
$pass = '';
$db = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);

$keys = [
    'payment_gateway_enabled' => ['group' => 'payment', 'value' => 'true', 'type' => 'boolean'],
    'paystack_enabled' => ['group' => 'payment', 'value' => 'true', 'type' => 'boolean'],
    'paystack_public_key' => ['group' => 'payment', 'value' => 'PAYSTACK_PUBLIC_KEY_PLACEHOLDER', 'type' => 'text'],
    'paystack_secret_key' => ['group' => 'payment', 'value' => 'PAYSTACK_SECRET_KEY_PLACEHOLDER', 'type' => 'text'],
    'hubtel_enabled' => ['group' => 'payment', 'value' => 'false', 'type' => 'boolean'],
    'hubtel_client_id' => ['group' => 'payment', 'value' => 'HUBTEL_CLIENT_ID_PLACEHOLDER', 'type' => 'text'],
    'hubtel_client_secret' => ['group' => 'payment', 'value' => 'HUBTEL_CLIENT_SECRET_PLACEHOLDER', 'type' => 'text'],
];

foreach ($keys as $key => $data) {
    $stmt = $db->prepare('SELECT id FROM settings WHERE `key` = ?');
    $stmt->execute([$key]);
    if ($stmt->fetch()) {
        $upd = $db->prepare('UPDATE settings SET `group` = ?, `value` = ?, `type` = ? WHERE `key` = ?');
        $upd->execute([$data['group'], $data['value'], $data['type'], $key]);
        echo "Updated {$key}\n";
    } else {
        $ins = $db->prepare('INSERT INTO settings (`group`, `key`, `value`, `type`) VALUES (?, ?, ?, ?)');
        $ins->execute([$data['group'], $key, $data['value'], $data['type']]);
        echo "Inserted {$key}\n";
    }
}
