<?php

declare(strict_types=1);
// SPDX-FileCopyrightText: IndieHosters <contact@indiehosters.net>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\CustomNav\AppInfo;

use OCA\CustomNav\Service\Manager;
use OCA\CustomNav\BeforeTemplateRenderedListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IConfig;
use OCP\INavigationManager;
use Psr\Container\ContainerInterface;

class Application extends App implements IBootstrap
{
    public const APP_ID = 'customnav';
    public const APP_NAME = 'Navigation personnalisée';

    public function __construct()
    {
        parent::__construct(self::APP_ID);
    }

    public function register(IRegistrationContext $context): void
    {
        $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class, -1);
        $context->registerService(Manager::class, function (ContainerInterface $c) {
            return new Manager(
                $c->get(INavigationManager::class),
                $c->get(IConfig::class),
            );
        });
    }

    public function boot(IBootContext $context): void
    {
    }
}
