<?php
/**
 * Generate VAPID keys for Web Push notifications
 * Run this script once to generate keys, then add them to config.php
 */

require_once __DIR__ . '/../vendor/autoload.php';

use Minishlink\WebPush\VAPID;

try {
    $keys = VAPID::createVapidKeys();
    
    echo "VAPID Keys Generated Successfully!\n\n";
    echo "Add these to your config.php file:\n\n";
    echo "// VAPID keys for push notifications\n";
    echo "define('VAPID_PUBLIC_KEY', '" . $keys['publicKey'] . "');\n";
    echo "define('VAPID_PRIVATE_KEY', '" . $keys['privateKey'] . "');\n";
    echo "define('VAPID_SUBJECT', 'mailto:admin@example.com');\n\n";
    
    echo "Also add the public key to your PWA JavaScript:\n";
    echo "const VAPID_PUBLIC_KEY = '" . $keys['publicKey'] . "';\n";
    
} catch (Exception $e) {
    echo "Error generating VAPID keys: " . $e->getMessage() . "\n";
    echo "Make sure you have installed web-push-php library:\n";
    echo "composer require minishlink/web-push\n";
}
