<?php

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

use App\Http\Controllers\Controller;
use App\Services\AgentSettlement\SettlementPeriodOpenHintsService;
use App\Support\AdminAgentSettlementScope;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/** GET /api/v1/admin/settlement-periods/open-hints */
final class AgentSettlementPeriodOpenHintsController extends Controller
{
    public function __invoke(
        Request $request,
        SettlementPeriodOpenHintsService $hintsService,
    ): JsonResponse {
        $admin = $request->lotteryAdmin();
        abort_if($admin === null, 401);

        $siteId = (int) $request->query('admin_site_id', 0);
        abort_if($siteId <= 0, 422);
        abort_if(! AdminAgentSettlementScope::siteAccessible($admin, $siteId), 404);

        return ApiResponse::success($hintsService->hints($siteId));
    }
}
