<?php
require __DIR__ . '/../vendor/autoload.php';
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

$id = 69478;

$artwork = DB::table('artworks')->where('id', $id)->first();
echo "Artwork: " . ($artwork ? $artwork->title : 'NOT FOUND') . PHP_EOL;

$stats = DB::table('artwork_stats')->where('artwork_id', $id)->first();
echo "artwork_stats row: " . json_encode($stats) . PHP_EOL;

$viewEvents = DB::table('artwork_view_events')->where('artwork_id', $id)->count();
echo "artwork_view_events count: " . $viewEvents . PHP_EOL;

// Check a few artworks that DO have stats
$sample = DB::table('artwork_stats')->whereColumn('views', '>', 'id')->limit(3)->pluck('artwork_id');
echo "Sample artworks with views > 0: " . json_encode($sample) . PHP_EOL;

// Count how many artworks_stats rows exist at all
$total = DB::table('artwork_stats')->count();
echo "Total artwork_stats rows: " . $total . PHP_EOL;
