<?php

namespace App\Base\Framework\EventListener;

use App\Base\ConfigResolver;
use App\Base\Service\Broadcaster;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;

final class KernelRequestValidateConfig
{
    public function __construct(
        private readonly ConfigResolver $configResolver,
        private readonly Broadcaster $broadcaster,
    ) {}

    #[AsEventListener(event: 'kernel.request', priority: 20)]
    public function validateConfig(RequestEvent $event): void
    {
        if (false === $this->configResolver->validate()) {
            $this->broadcaster->systemAlert('Ruh-roh', 'It looks like your system is misconfigured. Please search the application logs for strings starting with "[error] > [ConfigResolver]" to find more information.');
        }
    }
}
