<?php

namespace Database\Seeders;

use App\Models\Admin;
use App\Models\Permission;
use App\Models\Role;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $role = Role::create(['name' => 'super admin']);

        $admin = Admin::firstWhere('username', 'admin');
        $admin->roles()->attach($role->id);

        $permissions = [
            'manage_user:user_edit',
            'manage_user:user_create',
            'manage_user:user_balance_edit',
            'manage_user:login_as_user',
            'manage_user:user_kyc_data_edit',
            'manage_user:user_kyc_data_verify',
            'manage_user:user_ban',
            'manage_user:user_password_edit',
            'manage_user:network fully active',
            'manage_user:plan purchased',
            'manage_user:network pending',
            'manage_user:email unverified',
            'manage_user:mobile unverified',
            'manage_user:kyc unverified',
            'manage_user:kyc pending',
            'manage_user:kyc rejected',
            'manage_user:with earning',
            'manage_user:dummy users',
            'manage_user:dummy users edit',
            'manage_user:all users',
            'manage_user:banned users',
            'manage_user:working users',
            'manage_user:app download list',
            'product_details:edit',
            'reward:view_list',
            'reward:approve_reject',
            'coupon:list',
            'coupon:bulk_upload',
            'coupon:create',
            'coupon:edit',
            'social_media:list',
            'social_media:edit',
            'social_media:create',
            'level_wise_reward:list',
            'level_wise_reward:edit',
            'support_ticket:list',
            'support_ticket:view',
            'support_ticket:reply',
            'report:transactions',
            'report:login_history',
            'report:notification_history',
            'notice_board',
        ];

        foreach ($permissions as $permission) {
            Permission::create([
                'name' => str($permission)->snake()->toString(),
                'guard_name' => 'web'
            ]);
        }

        $role->assignPermission($permissions);
    }
}
