<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Twig;

use Ferienpass\CoreBundle\Entity\PageConfig;
use Ferienpass\CoreBundle\Settings\IntegrationsManager;
use Ferienpass\CoreBundle\Settings\MailConfigManager;
use Ferienpass\CoreBundle\Settings\PageConfigManager;
use Ferienpass\CoreBundle\Settings\SettingsManager;
use Ferienpass\CoreBundle\Settings\SystemSettingsManager;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
use Twig\TwigFunction;

class PageConfigExtension extends AbstractExtension implements GlobalsInterface
{
    public function __construct(
        private readonly PageConfigManager $pageConfigManager,
        private readonly MailConfigManager $mailConfigManager,
        private readonly SystemSettingsManager $systemSettingsManager,
        private readonly IntegrationsManager $integrationsManager,
        private readonly SettingsManager $settingsManager,
    ) {
    }

    public function getGlobals(): array
    {
        return [
            'page_config_manager' => $this->pageConfigManager,
            'mail_config_manager' => $this->mailConfigManager,
            'system_settings_manager' => $this->systemSettingsManager,
            'integrations_manager' => $this->integrationsManager,
            'settings_manager' => $this->settingsManager,
        ];
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('page_config', [$this, 'getPageConfig']),
        ];
    }

    public function getPageConfig(): PageConfig
    {
        return $this->pageConfigManager->getPageConfig();
    }
}
