<?php

use Illuminate\Database\Seeder;

use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User;

class PermissionsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
      // Reset cached roles and permissions
      app()['cache']->forget('spatie.permission.cache');

      //Permission list
      Permission::create(['name' => 'dashboard.index']);

      Permission::create(['name' => 'articles.index']);
      Permission::create(['name' => 'articles.store']);
      Permission::create(['name' => 'articles.update']);
      Permission::create(['name' => 'articles.destroy']);

      Permission::create(['name' => 'customers.index']);
      Permission::create(['name' => 'customers.store']);
      Permission::create(['name' => 'customers.update']);
      Permission::create(['name' => 'customers.destroy']);

      Permission::create(['name' => 'expenses.index']);
      Permission::create(['name' => 'expenses.store']);
      Permission::create(['name' => 'expenses.update']);
      Permission::create(['name' => 'expenses.destroy']);

      Permission::create(['name' => 'purchase_orders.index']);
      Permission::create(['name' => 'purchase_orders.store']);
      Permission::create(['name' => 'purchase_orders.update']);
      Permission::create(['name' => 'purchase_orders.destroy']);

      Permission::create(['name' => 'sales.index']);
      Permission::create(['name' => 'sales.store']);
      Permission::create(['name' => 'sales.update']);
      Permission::create(['name' => 'sales.destroy']);

      Permission::create(['name' => 'users.index']);
      Permission::create(['name' => 'users.store']);
      Permission::create(['name' => 'users.update']);
      Permission::create(['name' => 'users.destroy']);

      Permission::create(['name' => 'views.reports']);

      //Admin
      $admin = Role::create(['name' => 'Admin']);
      $admin->givePermissionTo(Permission::all());

      //Guest
      $guest = Role::create(['name' => 'Guest']);

      $guest->givePermissionTo([
        'dasboard.index'
      ]);

      //User Admin
      $user = User::find(1); //Admin
      $user->assignRole('Admin');

    }
}
