<?php
/**
 * Detailed smoke test with enhanced logging
 */
$log_file = __DIR__.'/smoke-test-detailed.log';
file_put_contents($log_file, "=== Starting detailed smoke test ===\n", FILE_APPEND);

try {
    // 1. Verify test doubles exist
    file_put_contents($log_file, "1. Checking test doubles file...\n", FILE_APPEND);
    if (!file_exists(__DIR__.'/test-doubles.php')) {
        throw new Exception("test-doubles.php not found");
    }
    file_put_contents($log_file, "✓ test-doubles.php exists\n", FILE_APPEND);

    // 2. Load test doubles first
    file_put_contents($log_file, "2. Loading test doubles...\n", FILE_APPEND);
    require_once __DIR__.'/test-doubles.php';
    file_put_contents($log_file, "✓ test doubles loaded\n", FILE_APPEND);

    // 3. Verify plugin file exists
    file_put_contents($log_file, "3. Checking plugin file...\n", FILE_APPEND);
    $plugin_file = dirname(dirname(__DIR__)) . '/hvac-community-events.php';
    if (!file_exists($plugin_file)) {
        throw new Exception("Plugin file not found at: $plugin_file");
    }
    file_put_contents($log_file, "✓ plugin file exists\n", FILE_APPEND);

    // 4. Load plugin
    file_put_contents($log_file, "4. Loading plugin...\n", FILE_APPEND);
    require_once $plugin_file;
    file_put_contents($log_file, "✓ plugin loaded\n", FILE_APPEND);

    // 5. Verify plugin class
    file_put_contents($log_file, "5. Checking plugin class...\n", FILE_APPEND);
    if (!class_exists('HVAC_Community_Events')) {
        throw new Exception("Plugin class not loaded");
    }
    file_put_contents($log_file, "✓ plugin class exists\n", FILE_APPEND);

    // 6. Verify version constant
    file_put_contents($log_file, "6. Checking version constant...\n", FILE_APPEND);
    if (!defined('HVAC_CE_VERSION')) {
        throw new Exception("Version constant not defined");
    }
    file_put_contents($log_file, "✓ version constant exists\n", FILE_APPEND);

    // 7. Verify TEC functions
    file_put_contents($log_file, "7. Checking TEC functions...\n", FILE_APPEND);
    if (!function_exists('tribe_get_events')) {
        throw new Exception("TEC functions not available");
    }
    file_put_contents($log_file, "✓ TEC functions available\n", FILE_APPEND);

    file_put_contents($log_file, "PASS: All checks completed successfully\n", FILE_APPEND);
    exit(0);

} catch (Exception $e) {
    file_put_contents($log_file, "FAIL: " . $e->getMessage() . "\n", FILE_APPEND);
    exit(1);
}