<?php

namespace Database\Seeders;

use App\Models\ModulePermission;
use App\Models\User;
use Illuminate\Database\Seeder;

class UserModulePermissionSeeder extends Seeder
{
    public function run(): void
    {
        $user = User::where('email', 'admin@admin.com')->first();

        if (! $user) {
            return;
        }

        $permissions = ModulePermission::where('is_active', 1)->get();

        foreach ($permissions as $permission) {
            $user->modulePermissions()->syncWithoutDetaching([
                $permission->id => ['is_active' => 1],
            ]);
        }
    }
}

