<?php

namespace Database\Seeders;

use App\Models\GroupPermission;
use Illuminate\Database\Seeder;
use DB;

class EnterpriseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        //Organisation
        DB::table('organisations')->insert([
            'name' => config('creatia.automation.main_organisation_name')
        ]);

        //Insert some permissions
        DB::table('groups')->insert([[
            'id' => 1,
            'name' => 'Admin',
        ], [
            'id' => 2,
            'name' => 'Creatia Standard User',
        ], [
            'id' => 3,
            'name' => 'Creatia Read-Only User',
        ]]);

        foreach([
            '1' => ['goliath.l1.report', 'hook.view', 'hook.update', 'goliath.l1.special', 'network.view', 'management.view', 'management.write', 'goliath.l1.view', 'goliath.l1.edit', 'goliath.l1.log', 'goliath.l1.manage', 'goliath.l2.view', 'goliath.l2.edit', 'goliath.l2.log', 'goliath.l2.manage', 'network.subtenant', 'network.rename', 'network.delete', 'network.manage'],
            '2' => ['goliath.l1.report', 'hook.view', 'hook.update', 'goliath.l1.special', 'network.view', 'goliath.l1.view', 'goliath.l1.edit', 'goliath.l1.log', 'goliath.l2.view', 'goliath.l2.edit', 'goliath.l2.log', 'network.subtenant', 'network.rename', 'network.delete'],
            '3' => ['goliath.l1.report', 'hook.view', 'network.view', 'goliath.l1.view', 'goliath.l1.log', 'goliath.l2.view', 'goliath.l2.log'],
        ] as $id => $perms) {
            foreach($perms as $perm) {
                GroupPermission::create([
                    'permission' => $perm, 'status' => 1, 'group_id' => $id
                ]);
            }

        }

        //Insert our initial administrators...
        DB::table('users')->insert([[
            'name'          => 'Primary Creatia User',
            'email'         => 'creatia@globalsecurelayer.com',
            'created_at'    => now(),
            'updated_at'    => now(),
            'group_id'      => 1,
            'organisation_id' => 1,
            'password'      => '',
            'signup_token'   => 'primary-user-setup-token',
        ]]);

    }
}
