<?php

namespace Modules\Notification;

use Illuminate\Support\Facades\Artisan;

class Notification
{

    protected static string $mainTitle = '通知消息';

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

        self::createAdminMenu();
    }

    protected static function createAdminMenu()
    {
        $menu = config('admin.database.menu_model');

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

        $main->children()->createMany([
            [
                'order' => 1,
                'title' => '消息模板',
                'icon'  => 'fa-dashboard',
                'uri'   => 'notifications/templates',
            ],
            [
                'order' => 2,
                'title' => '消息设置',
                'icon'  => 'fa-cogs',
                'uri'   => 'notifications/settings',
            ],
        ]);
    }

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

        $mains = $menu::where('title', self::$mainTitle)->get();

        foreach ($mains as $main) {
            $main->delete();
        }
    }

}
