<?php
/**
 * Configuration Verification Script
 */

require_once('../config/auth_config.php');

function verifyConfig() {
    $required = [
        'ONESIGNAL_APP_ID',
        'ONESIGNAL_REST_API_KEY',
        'JWT_SECRET',
        'JWT_EXPIRY',
        'OTP_RATE_LIMIT',
        'OTP_RATE_WINDOW',
        'OTP_EXPIRY',
        'OTP_LENGTH',
        'EMAIL_FROM_NAME',
        'EMAIL_FROM_ADDRESS',
        'DB_OTP_TABLE',
        'DB_MEMBERS_TABLE',
        'PASSWORD_HASH_ALGO',
        'PASSWORD_HASH_OPTIONS'
    ];
    
    $missing = [];
    foreach ($required as $key) {
        if (!isset($GLOBALS[$key])) {
            $missing[] = $key;
        }
    }
    
    if (!empty($missing)) {
        echo "Missing configurations:\n";
        foreach ($missing as $key) {
            echo "- $key\n";
        }
        return false;
    }
    
    // Verify OneSignal credentials
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://onesignal.com/api/v1/apps/' . $GLOBALS['ONESIGNAL_APP_ID']);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Basic ' . $GLOBALS['ONESIGNAL_REST_API_KEY']
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($httpCode !== 200) {
        echo "OneSignal API verification failed. Please check your credentials.\n";
        return false;
    }
    
    // Verify database tables
    $tables = ['otp_verification', 'members'];
    foreach ($tables as $table) {
        $result = mysql_query("SHOW TABLES LIKE '$table'");
        if (mysql_num_rows($result) === 0) {
            echo "Table '$table' not found. Please run the database setup script.\n";
            return false;
        }
    }
    
    echo "All configurations verified successfully!\n";
    return true;
}

// Run verification
verifyConfig(); 