<?php

namespace Modules\Linker;

use Illuminate\Support\Facades\Artisan;

class Linker
{

    protected static string $mainTitle = '链接管理';

    /**
     * Notes   : 模块初始化要做的一些操作
     * @Date   : 2021/3/12 11:34 上午
     * @Author : < Jason.C >
     */
    public static function install()
    {
        Artisan::call('migrate', [
            '--path' => 'modules/Linker/Database/Migrations',
        ]);

        self::createAdminMenu();
    }

    /**
     * Notes   : 卸载模块的一些操作
     * @Date   : 2021/3/12 11:35 上午
     * @Author : < Jason.C >
     */
    public static function uninstall()
    {
        $menu = config('admin.database.menu_model');

        $main = $menu::where('title', self::$mainTitle)->first();

        $main->delete();
    }

    /**
     * Notes   : 创建后台菜单
     * @Date   : 2021/3/17 9:48 上午
     * @Author : < Jason.C >
     */
    protected static function createAdminMenu()
    {
        $menu = config('admin.database.menu_model');

        $main = $menu::create([
            'parent_id' => 0,
            'order'     => 45,
            'title'     => self::$mainTitle,
            'icon'      => 'fa-bars',
        ]);

        $main->children()->createMany([
            [
                'order' => 0,
                'title' => '链接管理',
                'icon'  => 'fa-bars',
                'uri'   => 'linkers',
            ],
        ]);
    }

}