<?php

declare(strict_types=1);

namespace CpCreation\AltchaBundle\Tests\Fixture;

use CpCreation\AltchaBundle\CpCreationAltchaBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

final class TestKernel extends Kernel
{
    use MicroKernelTrait;

    public function registerBundles(): iterable
    {
        yield new FrameworkBundle();
        yield new TwigBundle();
        yield new CpCreationAltchaBundle();
    }

    public function getCacheDir(): string
    {
        return sys_get_temp_dir().'/cpcreation_altcha_bundle/cache';
    }

    public function getLogDir(): string
    {
        return sys_get_temp_dir().'/cpcreation_altcha_bundle/log';
    }

    private function configureContainer(ContainerConfigurator $container): void
    {
        $container->extension('framework', [
            'secret' => 'kernel-test-secret',
            'test' => true,
            'http_method_override' => false,
            'router' => ['utf8' => true],
            'http_client' => ['enabled' => true],
            'validation' => ['enabled' => true],
            'form' => ['enabled' => true],
            'translator' => ['enabled' => true, 'fallbacks' => ['en']],
        ]);
        $container->extension('twig', [
            'strict_variables' => true,
        ]);
        $container->extension('cp_creation_altcha', [
            'service_url' => 'http://127.0.0.1:1',
            'runtime_token' => 'runtime-test-token',
            'scope_sync_token' => 'scope-sync-test-token',
            'envelope_secret' => 'kernel-envelope-test-secret-at-least-32-bytes',
            'subject_secret' => '',
            'scopes' => ['custom.form' => 'Custom form'],
        ]);

        $services = $container->services();
        $services->alias('test.altcha.form_factory', 'form.factory')->public();
        $services->alias('test.altcha.twig', 'twig')->public();
    }

    private function configureRoutes(RoutingConfigurator $routes): void
    {
        $routes->import(dirname(__DIR__, 2).'/src/Resources/config/routes.php');
    }
}
