<?php

namespace App\Console\Commands\Mock;

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

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

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

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $create_registered = $this->confirm('Create registered users?');
        $total_users = (int) $this->ask('How much users num?')?:10;

        $status_bar = $this->output->createProgressBar($total_users);
        $status_bar->start();

        factory(User::class, $total_users)
            ->create()->each(function (User $user) use ($create_registered, $status_bar) {
                $user->is_registered = $create_registered;
                $user->save();
                $status_bar->advance();
            });

        $status_bar->finish();
        $this->info('');
    }
}
