<?php

declare(strict_types=1);

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Leaderboard;
use App\Services\LeaderboardService;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class LeaderboardPageController extends Controller
{
    public function __invoke(Request $request, LeaderboardService $leaderboards): Response
    {
        $period = $leaderboards->normalizePeriod((string) $request->query('period', 'weekly'));
        $type = match ((string) $request->query('type', 'creators')) {
            'artworks', Leaderboard::TYPE_ARTWORK => Leaderboard::TYPE_ARTWORK,
            'stories', Leaderboard::TYPE_STORY => Leaderboard::TYPE_STORY,
            default => Leaderboard::TYPE_CREATOR,
        };

        return Inertia::render('Leaderboard/LeaderboardPage', [
            'initialType' => $type,
            'initialPeriod' => $period,
            'initialData' => $leaderboards->getLeaderboard($type, $period),
            'meta' => [
                'title' => 'Top Creators & Artworks Leaderboard | Skinbase',
                'description' => 'Track the leading creators, artworks, and stories across Skinbase by daily, weekly, monthly, and all-time performance.',
            ],
        ]);
    }
}
