<?php

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

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

// Simulate the response structure from the log
$body = [
    'Data' => '{"angle":0,"content":[{"word":"测试文本","prob":99}],"height":1052,"width":1052}',
    'message' => null,
    'requestId' => 'test'
];

echo "Testing Aliyun response parsing...\n";
echo "Body Data field type: " . gettype($body['Data']) . "\n";
echo "Body Data is string: " . (is_string($body['Data']) ? 'yes' : 'no') . "\n";

$data = is_string($body['Data']) ? json_decode($body['Data'], true) : $body['Data'];

echo "Decoded data keys: " . implode(', ', array_keys($data ?? [])) . "\n";
echo "Has content: " . (isset($data['content']) ? 'yes' : 'no') . "\n";
echo "Content count: " . (isset($data['content']) ? count($data['content']) : 0) . "\n";

if (isset($data['content']) && is_array($data['content'])) {
    foreach ($data['content'] as $item) {
        if (isset($item['word'])) {
            echo "Found word: {$item['word']}\n";
        }
    }
}
