<?php

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

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

/** GET /api/v1/admin/config/play-versions */
final class PlayConfigVersionIndexController extends Controller
{
    public function __invoke(Request $request, PlayConfigStreamService $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 (PlayConfigVersion $v) => AdminConfigPresenter::playConfigVersionSummary($v));
    }
}
