<?php

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

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

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

// Find the last "Aliyun Data Preview" entry
preg_match_all('/Aliyun Data Preview.*?{\"data\":\"(.*?)\"}/', $content, $matches);

if (!empty($matches[1])) {
    $lastMatch = end($matches[1]);
    // Unescape the JSON string
    $jsonStr = str_replace('\\"', '"', $lastMatch);
    $jsonStr = str_replace('\\\\', '\\', $jsonStr);
    
    $data = json_decode($jsonStr, true);
    
    if (isset($data['page_list'][0]['subject_list'][0])) {
        echo "First subject structure:\n";
        print_r($data['page_list'][0]['subject_list'][0]);
    } else {
        echo "No subject_list found\n";
        echo "Available keys in page_list[0]: " . implode(', ', array_keys($data['page_list'][0] ?? [])) . "\n";
    }
}
