<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

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

final class LeaderboardController extends Controller
{
    public function creators(Request $request, LeaderboardService $leaderboards): JsonResponse
    {
        return response()->json(
            $leaderboards->getLeaderboard(Leaderboard::TYPE_CREATOR, (string) $request->query('period', 'weekly'))
        );
    }

    public function artworks(Request $request, LeaderboardService $leaderboards): JsonResponse
    {
        return response()->json(
            $leaderboards->getLeaderboard(Leaderboard::TYPE_ARTWORK, (string) $request->query('period', 'weekly'))
        );
    }

    public function groups(Request $request, LeaderboardService $leaderboards): JsonResponse
    {
        return response()->json(
            $leaderboards->getLeaderboard(Leaderboard::TYPE_GROUP, (string) $request->query('period', 'weekly'))
        );
    }

    public function stories(Request $request, LeaderboardService $leaderboards): JsonResponse
    {
        return response()->json(
            $leaderboards->getLeaderboard(Leaderboard::TYPE_STORY, (string) $request->query('period', 'weekly'))
        );
    }

    public function worlds(Request $request, LeaderboardService $leaderboards): JsonResponse
    {
        return response()->json(
            $leaderboards->getLeaderboard(Leaderboard::TYPE_WORLD, (string) $request->query('period', 'weekly'))
        );
    }
}
