<?php

namespace App\Console\Commands\Mock;

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

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

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

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $capsules = Capsule::repository()->all();

        if ( ! $capsules ) {
            $this->info('No capsules');
            return false;
        }

        $remove_interval = 7;

        $status_bar = $this->output->createProgressBar($capsules->count() / $remove_interval);
        $status_bar->start();

        $loop = 0;
        foreach ($capsules as $capsule) {
            $loop++;

            if (!is_int($loop / 7)) continue;

            /** Remove from timeline */
            $user = User::inRandomOrder()->first();
            CapsuleRemoved::createRelation($capsule, $user);

            $status_bar->advance();
        }

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