<?php

namespace Modules\Dummy\Database\Seeders\Core\versions\v1_2_0;

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

class PermissionTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run() {

        $permission = Permission::where(['name' => 'Modules\OpenAI\Http\Controllers\Api\V1\User\OpenAIPreferenceController@contentPreferences'])->first();

        if (!$permission) {
            return null;
        }

        $role = PermissionRole::where(['permission_id' => $permission->id, 'role_id' => 2])->first();

        if (!$role) {
            \DB::table('permission_roles')->insert([
                'permission_id' => $permission->id,
                'role_id' => 2
            ]);
        }
        
        $permission = Permission::where(['name' => 'Modules\OpenAI\Http\Controllers\Api\V1\User\OpenAIPreferenceController@imagePreferences'])->first();

        if (!$permission) {
            return null;
        }

        $role = PermissionRole::where(['permission_id' => $permission->id, 'role_id' => 2])->first();

        if (!$role) {
            \DB::table('permission_roles')->insert([
                'permission_id' => $permission->id,
                'role_id' => 2
            ]);
        }
        
        $permission = Permission::where(['name' => 'Modules\OpenAI\Http\Controllers\Api\V1\User\OpenAIPreferenceController@codePreferences'])->first();

        if (!$permission) {
            return null;
        }

        $role = PermissionRole::where(['permission_id' => $permission->id, 'role_id' => 2])->first();

        if (!$role) {
            \DB::table('permission_roles')->insert([
                'permission_id' => $permission->id,
                'role_id' => 2
            ]);
        }
        
        $permission = Permission::where(['name' => 'Modules\OpenAI\Http\Controllers\Api\V1\User\UserController@index'])->first();

        if (!$permission) {
            return null;
        }

        $role = PermissionRole::where(['permission_id' => $permission->id, 'role_id' => 2])->first();

        if (!$role) {
            \DB::table('permission_roles')->insert([
                'permission_id' => $permission->id,
                'role_id' => 2
            ]);
        }

        addPermission('Modules\\OpenAI\\Http\\Controllers\\Api\\V1\\User\\OpenAIController@contentTogglebookmark')->assignToCustomer();
        addPermission('Modules\\OpenAI\\Http\\Controllers\\Api\\V1\\User\\UseCasesController@useCaseToggleFavorite')->assignToCustomer();
        addPermission('Modules\\OpenAI\\Http\\Controllers\\Api\\V1\\User\\OpenAIPreferenceController@chatPreferences')->assignToCustomer();
        addPermission('Modules\\Subscription\\Http\\Controllers\\PackageSubscriptionController@store')->assignToCustomer();
        addPermission('Modules\\Subscription\\Http\\Controllers\\PackageSubscriptionController@setting')->assignToCustomer();
        addPermission('Modules\\Subscription\\Http\\Controllers\\Api\\V1\\User\\PackageSubscriptionController@cancel')->assignToCustomer();
        addPermission('Modules\\Subscription\\Http\\Controllers\\Api\\V1\\User\\PackageSubscriptionController@store')->assignToCustomer();
        addPermission('Modules\\Subscription\\Http\\Controllers\\Api\\V1\\User\\PackageSubscriptionController@setting')->assignToCustomer();
    }
}
