<?php

namespace Modules\Cms;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Facade;

class Cms extends Facade
{

    protected static string $mainTitle = '内容管理';

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

        self::createAdminMenu();
    }

    /**
     * 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();
        }
    }

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

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

        $main->children()->createMany([
            [
                'order' => 1,
                'title' => '文章管理',
                'icon'  => 'fa-bars',
                'uri'   => 'cms/articles',
            ],
            [
                'order' => 2,
                'title' => '单页管理',
                'icon'  => 'fa-newspaper-o',
                'uri'   => 'cms/pages',
            ],
            [
                'order' => 3,
                'title' => '分类管理',
                'icon'  => 'fa-indent',
                'uri'   => 'cms/categories',
            ],
            [
                'order' => 4,
                'title' => '标签管理',
                'icon'  => 'fa-tags',
                'uri'   => 'cms/tags',
            ],
            [
                'order' => 5,
                'title' => '素材管理',
                'icon'  => 'fa-adjust',
                'uri'   => 'cms/storages',
            ],
        ]);
    }

}