<?php

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

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

class PermissionsTableSeeder extends Seeder
{
    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {
        $permissionAdmin = Permission::where('name', 'App\Http\Controllers\Admin\Product\ProductController@duplicate');

        if ($permissionAdmin->exists()) {
            $permissionAdmin->delete();
        }

        $permissionVendor = Permission::where('name', 'App\Http\Controllers\Vendor\Product\ProductController@duplicate');

        if ($permissionVendor->exists()) {
            $permissionVendor->delete();
        }

        $permissionId = Permission::insertGetId([
            'name' => 'App\\Http\\Controllers\\Admin\\Product\\ProductController@duplicate',
            'controller_path' => 'App\\Http\\Controllers\\Admin\\Product\\ProductController',
            'controller_name' => 'ProductController',
            'method_name' => 'duplicate',
        ]);

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

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