<?php

namespace Modules\Dummy\Database\Seeders\Core\Versions\V1_7_0;

use App\Models\Permission;
use App\Models\PermissionRole;
use Illuminate\Database\Seeder;

class PermissionsTableSeeder extends Seeder
{
    public function run()
    {
        if (! Permission::where('name', 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@index')->first()) {

            $permissionId = Permission::insertGetId([
                'name' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@index',
                'controller_path' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController',
                'controller_name' => 'CustomerController',
                'method_name' => 'index',
            ]);

            PermissionRole::insert([
                [
                    'permission_id' => $permissionId,
                    'role_id' => 1,
                ],
                [
                    'permission_id' => $permissionId,
                    'role_id' => 2,
                ],
            ]);
        }

        if (! Permission::where('name', 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@create')->first()) {

            $permissionId = Permission::insertGetId([
                'name' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@create',
                'controller_path' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController',
                'controller_name' => 'CustomerController',
                'method_name' => 'create',
            ]);

            PermissionRole::insert([
                'permission_id' => $permissionId,
                'role_id' => 2,
            ]);
        }

        if (! Permission::where('name', 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@store')->first()) {

            $permissionId = Permission::insertGetId([
                'name' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@store',
                'controller_path' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController',
                'controller_name' => 'CustomerController',
                'method_name' => 'store',
            ]);

            PermissionRole::insert([
                'permission_id' => $permissionId,
                'role_id' => 2,
            ]);
        }

        if (! Permission::where('name', 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@edit')->first()) {

            $permissionId = Permission::insertGetId([
                'name' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@edit',
                'controller_path' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController',
                'controller_name' => 'CustomerController',
                'method_name' => 'edit',
            ]);

            PermissionRole::insert([
                'permission_id' => $permissionId,
                'role_id' => 2,
            ]);
        }

        if (! Permission::where('name', 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@update')->first()) {

            $permissionId = Permission::insertGetId([
                'name' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@update',
                'controller_path' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController',
                'controller_name' => 'CustomerController',
                'method_name' => 'update',
            ]);

            PermissionRole::insert([
                'permission_id' => $permissionId,
                'role_id' => 2,
            ]);
        }

        if (! Permission::where('name', 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@destroy')->first()) {

            $permissionId = Permission::insertGetId([
                'name' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController@destroy',
                'controller_path' => 'App\\Http\\Controllers\\Vendor\\Customers\\CustomerController',
                'controller_name' => 'CustomerController',
                'method_name' => 'destroy',
            ]);

            PermissionRole::insert([
                'permission_id' => $permissionId,
                'role_id' => 2,
            ]);
        }
    }
}
