<?php

declare(strict_types=1);

namespace TechnoArtisan\FilamentCms\Listeners;

use Illuminate\Support\Facades\Log;
use JsonException;
use Spatie\Honeypot\Events\SpamDetectedEvent;

use function json_encode;

class HandleSpamDetect
{
    /**
     * Create the event listener.
     */
    public function __construct() {}

    /**
     * Handle the event.
     * @throws JsonException
     */
    public function handle(SpamDetectedEvent $event): void
    {
        Log::warning(
            'SpamDetectedEvent [' . $event->request->fullUrl() . ']: ' . json_encode(
                $event->request->toArray(),
                JSON_THROW_ON_ERROR
            )
        );
    }
}
