<?php

namespace app\modules\tag;

use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;

class TagModule extends Module
{

    public MenuService $menuService;
    public MigrationService $migrationService;
    public function __construct()
    {
        $this->menuService = new MenuService();
        $this->migrationService = new MigrationService();
    }

    /**
     * @throws \Exception
     */
    public function init(): void
    {
        $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");

        $this->menuService->createItem([
            "label" => "Тэги",
            "url" => "/admin/tag",
            "slug" => "tag",
        ]);
    }

    public function deactivate(): void
    {
        $this->menuService->removeItemBySlug("tag");
    }
}