<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

class RoleSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Reset cached roles and permissions
        app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();

        // Create base roles
        $superAdmin = Role::create(['name' => 'super_admin']);
        $portalAdmin = Role::create(['name' => 'portal_admin']);
        $user = Role::create(['name' => 'user']);

        // Create permissions (optional - you can expand this as needed)
        $permissions = [
            'manage_users',
            'manage_roles',
            'manage_portals',
            'manage_payment_gateways',
            'view_admin_dashboard',
        ];

        foreach ($permissions as $permission) {
            Permission::create(['name' => $permission]);
        }

        // Assign all permissions to super_admin
        $superAdmin->givePermissionTo(Permission::all());

        $this->command->info('✓ Roles and permissions seeded successfully!');
    }
}
