<?php

namespace App\Http\Controllers\Api\V1\Admin\Player;

use App\Models\Player;
use App\Support\ApiResponse;
use App\Support\AdminSiteScope;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Support\PlayerApiPresenter;

/** GET /api/v1/admin/players/{player} */
final class AdminPlayerShowController extends Controller
{
    public function __invoke(Request $request, Player $player): JsonResponse
    {
        $admin = $request->lotteryAdmin();
        abort_if($admin === null, 401);

        if ($denied = AdminSiteScope::denyUnlessPlayerAccessible($admin, $player)) {
            return $denied;
        }

        return ApiResponse::success(PlayerApiPresenter::listItem($player));
    }
}
