<?php

namespace App\Http\Controllers\Admin;

use App\FiveM\Contracts\FrameworkAdapter;
use App\Http\Controllers\Controller;
use App\Models\AuditLog;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class VehicleManagerController extends Controller
{
    public function index(Request $request, FrameworkAdapter $adapter): Response
    {
        return Inertia::render('Admin/Vehicles/Index', [
            'vehicles' => $adapter->paginateVehicles(25, $request->string('search')->value() ?: null),
            'search' => $request->string('search')->value(),
        ]);
    }

    public function update(int|string $vehicle): RedirectResponse
    {
        // Garage reassignment is intentionally out of the FrameworkAdapter
        // contract (too framework-specific to generalize usefully); left as
        // a follow-up once a specific server's garage resource is targeted.
        abort(501, 'Garage reassignment is not yet implemented for this framework.');
    }

    public function destroy(FrameworkAdapter $adapter, int|string $vehicle): RedirectResponse
    {
        $adapter->deleteVehicle($vehicle);

        AuditLog::record('vehicle.deleted', null, ['vehicle_id' => $vehicle]);

        return back()->with('success', 'Vehicle removed.');
    }
}
