<?php

namespace App\Console\Commands\Report;

use Illuminate\Support\Facades\Artisan;

class GroupAttackCollection extends \App\Console\Commands\BaseCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'group:attack-collection';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Runs attack data collection lifecycle';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        if(env('reporting_disabled')) {
            $this->log_warning("Not running as `reporting_disabled` is set in the .env file.", []);
            return 0;
        }

        $start = microtime(true);

        Artisan::call('report-attack:info');

        $time_info = microtime(true) - $start;

        Artisan::call('report-permit:subtenant');

        if(($time_taken = microtime(true) - $start) && $time_taken > 30) {

            $this->log_warning("Command execution has exceeded desired time.", [
                'event-collection' => $time_info,
                'subtenancy-calculation' => $time_taken,
                'total' => $time_taken
            ]);

        }

        return 0;
    }
}