<?php
/**
 * Get Firebase Config API
 */


require_once 'bootstrap.php';

try {
    $pdo = getDBConnection();
    $stmt = $pdo->query("SELECT key_name, key_value FROM settings WHERE key_name LIKE 'firebase_%'");
    $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);

    // Also get the VAPID key which we named firebase_vapid_key

    echo json_encode([
        'success' => true,
        'config' => [
            'apiKey' => $settings['firebase_api_key'] ?? '',
            'authDomain' => $settings['firebase_auth_domain'] ?? '',
            'databaseURL' => $settings['firebase_database_url'] ?? '',
            'projectId' => $settings['firebase_project_id'] ?? '',
            'storageBucket' => $settings['firebase_storage_bucket'] ?? '',
            'messagingSenderId' => $settings['firebase_messaging_sender_id'] ?? '',
            'appId' => $settings['firebase_app_id'] ?? '',
            'vapidKey' => $settings['firebase_vapid_key'] ?? ''
        ]
    ]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
