<?php

namespace App\Http\Controllers\Api;

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

class LeaderboardController extends Controller
{
    public function __construct(private readonly LeaderboardService $leaderboardService) {}

    public function index(): JsonResponse
    {
        return response()->json([
            'leaderboard' => $this->leaderboardService->getLeaderboard(50),
        ]);
    }

    public function myRank(Request $request): JsonResponse
    {
        $user = $request->user();
        $rank = $this->leaderboardService->getUserRank($user->id);

        return response()->json([
            'rank'         => $rank,
            'total_points' => $user->total_points,
            'fan_level'    => $user->fan_level,
        ]);
    }
}
