<?php

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

$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

// Read the last Aliyun Data Preview log entry
$logFile = storage_path('logs/laravel.log');
$content = file_get_contents($logFile);

// Find entries with "answer" in the cutType
preg_match_all('/Aliyun Data Preview.*?"data":"(.*?)"}\s*$/m', $content, $matches);

if (!empty($matches[1])) {
    $lastMatch = end($matches[1]);
    
    // Unescape JSON
    $jsonStr = str_replace('\\"', '"', $lastMatch);
    $jsonStr = str_replace('\\\\', '\\', $jsonStr);
    
    $data = json_decode($jsonStr, true);
    
    if (isset($data['page_list'][0]['answer_list'])) {
        echo "Answer List Structure:\n\n";
        
        foreach ($data['page_list'][0]['answer_list'] as $i => $answer) {
            echo "Answer #{$i}:\n";
            echo "  IDs: " . json_encode($answer['ids'] ?? []) . "\n";
            echo "  Text: " . ($answer['text'] ?? 'N/A') . "\n";
            echo "  Keys: " . implode(', ', array_keys($answer)) . "\n";
            
            // Check if there's a separate answer mark field
            if (isset($answer['answer_mark'])) {
                echo "  Answer Mark: " . $answer['answer_mark'] . "\n";
            }
            
            echo "\n";
            
            if ($i >= 1) break; // Show first 2 answers
        }
    } else {
        echo "No answer_list found in response\n";
    }
} else {
    echo "No Aliyun Data Preview logs found\n";
}
