<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();

        // create permissions
        Permission::create(['name' => 'control contents']);
        Permission::create(['name' => 'control engineer data']);
        Permission::create(['name' => 'control firm data']);
        Permission::create(['name' => 'control skills']);
        Permission::create(['name' => 'control categories']);
        Permission::create(['name' => 'control notifications']);
        Permission::create(['name' => 'control projects']);
        Permission::create(['name' => 'control services']);
        Permission::create(['name' => 'control contracts']);
        Permission::create(['name' => 'control services orders']);
        Permission::create(['name' => 'control users']);
        Permission::create(['name' => 'control founders']);
        Permission::create(['name' => 'control wallet']);
        Permission::create(['name' => 'control roles and permissions']);
        // create roles and assign created permissions

        // this can be done as separate statements
        $role = Role::create(['name' => 'accountant']);
        $role->givePermissionTo('control wallet');

        // or may be done by chaining
        $role = Role::create(['name' => 'moderator'])
            ->givePermissionTo(['control contents', 'control categories','control skills']);

        $role = Role::create(['name' => 'super-admin']);
        $role->givePermissionTo(Permission::all());
    }
}
