<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;

class ShowUsers extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'show:users {page=1}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Show all users';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $page = (int) $this->argument('page');
        $users = User::all()->forPage($page, 20)->all();
        
        $rows = [];
        foreach ($users as $user) {
            array_push($rows, [$user->id, $user->name, $user->balance]);
        }

        $this->info("Listing all users for page $page");
        $this->table([ 'ID', 'Name', 'Balance' ], $rows);
    }
}