<?php

namespace Database\Seeders;

use Encore\Admin\Auth\Database\Administrator;
use Encore\Admin\Auth\Database\Menu;
use Encore\Admin\Auth\Database\Permission;
use Encore\Admin\Auth\Database\Role;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class AdminPanelSeeder extends Seeder
{

    /**
     * Seed the application's database.
     * @return void
     */
    public function run()
    {
        Administrator::create([
            'username' => 'admin',
            'password' => bcrypt('admin'),
            'name'     => 'Administrator',
        ]);

        Role::create([
            'name' => 'Administrator',
            'slug' => 'administrator',
        ]);

        Permission::create([
            'name'        => 'All permission',
            'slug'        => '*',
            'http_method' => '',
            'http_path'   => '*',
        ]);

        Menu::create([
            'id'        => 1,
            'parent_id' => 0,
            'order'     => 0,
            'title'     => 'Dashboard',
            'icon'      => 'fa-bar-chart',
            'uri'       => '/',
        ]);

        $menu = Menu::create([
            'id'        => 2,
            'parent_id' => 0,
            'order'     => 99,
            'title'     => 'Admin',
            'icon'      => 'fa-tasks',
        ]);

        $menu->children()->createMany([
            [
                'parent_id' => 2,
                'order'     => 1,
                'title'     => '模块管理',
                'icon'      => 'fa-windows',
                'uri'       => 'modules',
            ],
            [
                'parent_id' => 2,
                'order'     => 2,
                'title'     => 'Users',
                'icon'      => 'fa-users',
                'uri'       => 'auth/users',
            ],
            [
                'parent_id' => 2,
                'order'     => 3,
                'title'     => 'Roles',
                'icon'      => 'fa-user',
                'uri'       => 'auth/roles',
            ],
            [
                'parent_id' => 2,
                'order'     => 4,
                'title'     => 'Permission',
                'icon'      => 'fa-ban',
                'uri'       => 'auth/permissions',
            ],
            [
                'parent_id' => 2,
                'order'     => 1,
                'title'     => 'Menu',
                'icon'      => 'fa-bars',
                'uri'       => 'auth/menu',
            ],
            [
                'parent_id' => 2,
                'order'     => 1,
                'title'     => 'Operation log',
                'icon'      => 'fa-history',
                'uri'       => 'auth/logs',
            ],
        ]);

        DB::insert("INSERT INTO `admin_role_menu` VALUES (1, 2, NULL, NULL);");
        DB::insert("INSERT INTO `admin_role_permissions` VALUES (1, 1, NULL, NULL);");
        DB::insert("INSERT INTO `admin_role_users` VALUES (1, 1, NULL, NULL);");
    }

}