<?php

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

use Illuminate\Http\Request;
use App\Support\AdminApiList;
use App\Models\RiskCapVersion;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Support\AdminConfigPresenter;
use App\Services\Config\RiskCapStreamService;

/** GET /api/v1/admin/config/risk-cap-versions */
final class RiskCapVersionIndexController extends Controller
{
    public function __invoke(Request $request, RiskCapStreamService $service): JsonResponse
    {
        $p = AdminApiList::readPaging($request);
        $status = trim((string) $request->query('status', ''));

        $paginator = $service->paginate($status === '' ? null : $status, $p['perPage'], $p['page']);

        return AdminApiList::json($paginator, fn (RiskCapVersion $v) => AdminConfigPresenter::riskCapVersionSummary($v));
    }
}
