<?php

namespace EIS\Component\EIS;

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\Extension\Service\Provider\RouterFactory;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use EIS\Component\EIS\Site\Controller\DownloadController;

return new class implements ServiceProviderInterface
{
    public function register(Container $container): void
    {
        // MVC-Basisregistrierung
        $container->registerServiceProvider(new ComponentDispatcherFactory('\\EIS\\Component\\EIS'));
        $container->registerServiceProvider(new MVCFactory('\\EIS\\Component\\EIS'));
        $container->registerServiceProvider(new RouterFactory('\\EIS\\Component\\EIS'));

        // Optional: DownloadController explizit registrieren (kann auch weggelassen werden)
        $container->set(
            DownloadController::class,
            fn(Container $c) => new DownloadController()
        );

        // Komponentenschnittstelle
        $container->set(
            ComponentInterface::class,
            static fn(Container $c) => new MVCComponent(
                $c->get(ComponentDispatcherFactoryInterface::class)
            )
        );
    }
};
