<?php

declare(strict_types=1);

namespace App\Http\Controllers\Filament;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Services\SupportCenter\HostSystemUpdateAutoCheckTriggerService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

final class HostSystemUpdateAutoCheckPingController extends Controller
{
    public function __invoke(Request $request, HostSystemUpdateAutoCheckTriggerService $trigger): JsonResponse
    {
        $user = $request->user();

        if (! $user instanceof User) {
            return response()->json(['queued' => false, 'reason' => 'unauthenticated'], 401);
        }

        return response()->json($trigger->handlePing($user));
    }
}
