<?php
/**
 * @author Carsten Rose <carsten.rose@math.uzh.ch>
 */
defined('TYPO3') or die('Access denied.');

(static function () {

    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
        'qfq',
        'Qfq',
        [\IMATHUZH\Qfq\Controller\QfqController::class => 'show'],
        [\IMATHUZH\Qfq\Controller\QfqController::class => 'show'],
        \TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT
    );

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('@import "EXT:qfq/Configuration/PageTSconfig/PageTSconfig.tsconfig"');

    // By default, the 'tt_content' Header will be rendered: Avoid this, because it's much nicer to use the header in the backend as a description title of what the record does.
    $addLine = '
    tt_content.qfq_qfq = COA
    tt_content.qfq_qfq {
            10 >
    }
    ';
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('qfq', 'setup', '# Setting ' . 'qfq' . $addLine . '', 'defaultContentRendering');

    // Enable the authentication service by Qfq
    $extensionConfig = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
        \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
    )->get('qfq');

    if ($extensionConfig['authEnable']) {
        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
            'qfq',
            'auth' /* sv type */,
            'tx_qfq_auth' /* sv key */,
            [
                'title' => 'Authentication service',
                'description' => 'Authentication with Qfq',
                'subtype' => 'getUserFE,authUserFE',
                'available' => true,
                'priority' => intval($extensionConfig['authPriority']),
                'quality' => intval($extensionConfig['authQuality']),
                'os' => '',
                'exec' => '',
                'className' => \IMATHUZH\Qfq\Core\Typo3\QfqAuthenticationService::class,
            ]
        );
    }


})();
