<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\DB;

class DisplayRoles extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'display:roles';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Display roles and permissions in the system';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $roles = Role::all();

        $this->info('Role permissions:');

        foreach ($roles as $role) {
            $this->line("\n<fg=yellow>Role: {$role->name}</>");
            $permissions = $role->permissions->pluck('name')->toArray();
            $this->line("Permissions: " . implode(', ', $permissions));
        }

        return Command::SUCCESS;
    }
}
