<?php

namespace App\Console\Commands;

use App\Helpers\Notification;
use App\UsersNotification;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Log::info('Task schedule run successfully from documentation change status');

        $date = Carbon::now()->format('Y-m-d');
        $documentations = DB::table('documentations')->whereNull('deleted_at')
            ->whereStatus(1)->where('documentation_date', '<', $date);

        $consultings = DB::table('consultings')->whereNull('deleted_at')
            ->whereStatus(1)->where('consulting_date', '<', $date);

        if (count($documentations->cursor())){
            $documentations->update(['status' => 0]);
        }

        if (count($consultings->cursor())){
            $consultings->update(['status' => 0]);
        }
    }
}
