<?php

/**
 * MathRecSys集成测试脚本
 */

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

$app = require_once __DIR__ . '/bootstrap/app.php';

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

try {
    // 测试服务类
    echo "=== MathRecSys服务集成测试 ===\n\n";

    // 1. 测试MathRecSysService类是否存在
    echo "1. 检查MathRecSysService类...\n";
    if (class_exists(\App\Services\MathRecSysService::class)) {
        echo "   ✅ MathRecSysService类存在\n";
    } else {
        echo "   ❌ MathRecSysService类不存在\n";
        exit(1);
    }

    // 2. 尝试创建服务实例
    echo "\n2. 创建服务实例...\n";
    $mathRecSysService = new \App\Services\MathRecSysService();
    echo "   ✅ 服务实例创建成功\n";

    // 3. 测试健康检查
    echo "\n3. 测试MathRecSys API健康检查...\n";
    $isHealthy = $mathRecSysService->isHealthy();
    if ($isHealthy) {
        echo "   ✅ MathRecSys服务健康\n";
    } else {
        echo "   ⚠️  MathRecSys服务未就绪 (可能是网络或服务未启动)\n";
    }

    // 4. 测试API调用
    echo "\n4. 测试API调用...\n";
    try {
        $result = $mathRecSysService->getStudentProfile('test_student_001');
        echo "   ✅ API调用成功\n";
        echo "   数据: " . json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
    } catch (\Exception $e) {
        echo "   ⚠️  API调用失败: " . $e->getMessage() . "\n";
    }

    // 5. 测试KnowledgeGraphService
    echo "\n5. 检查KnowledgeGraphService类...\n";
    if (class_exists(\App\Services\KnowledgeGraphService::class)) {
        echo "   ✅ KnowledgeGraphService类存在\n";
    } else {
        echo "   ❌ KnowledgeGraphService类不存在\n";
    }

    // 6. 检查控制器
    echo "\n6. 检查StudentController类...\n";
    if (class_exists(\App\Http\Controllers\Api\StudentController::class)) {
        echo "   ✅ StudentController类存在\n";
    } else {
        echo "   ❌ StudentController类不存在\n";
    }

    echo "\n=== 测试完成 ===\n\n";

} catch (\Exception $e) {
    echo "❌ 测试失败: " . $e->getMessage() . "\n";
    echo "堆栈跟踪:\n" . $e->getTraceAsString() . "\n";
    exit(1);
}
