<?php

declare(strict_types=1);

namespace BotGuard\Controllers\Api;

use BotGuard\Core\Request;
use BotGuard\Core\Response;
use BotGuard\Services\VerificationService;

/**
 * Issues a fresh challenge/session so the verification page can request a new
 * puzzle (e.g. after a failed attempt) without a full reload.
 */
final class ChallengeApiController
{
    public function __construct(private VerificationService $verification)
    {
    }

    public function issue(Request $request): Response
    {
        $issued = $this->verification->createSession($request);

        return Response::json([
            'token'        => $issued['token'],
            'challenge'    => $issued['challenge'],
            'provider'     => $issued['provider'],
            'issued_at_ms' => $issued['issued_at_ms'],
        ]);
    }
}
