<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Console\Commands\AbstractCommand;
use App\Modules\Bookings\Support;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Config;

class SupportReminders extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'support:reminders';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Sends a reminder email for all the jobs that haven\'t been started.';

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

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire()
    {
        $tasks = Support::support()->where('completed', 0)->whereNull('assigned_to')->where('updated_at', '<', Carbon::now()->subMinutes(29)->toDateTimeString())->get();

        if (count($tasks) > 0) {
            \App\Seraph\Services\GlobalMailerService::send('emails.alerts.support-reminders', ['tasks' => $tasks], function ($message) {
                $message->to(Config::get('emails.support'))->subject('[Seraph3] Remote support jobs that need to be assigned asap!')->priority(1);
            });

            $this->info('['.Carbon::now()->toDateTimeString().'] Email successfully sent! Count: '.count($tasks));
        } else {
            $this->info('['.Carbon::now()->toDateTimeString().'] No remote support jobs found that require notification');
        }
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return [

        ];
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return [

        ];
    }
}
