<?php

namespace App\Console\Commands;

use App\Models\Laboratory;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

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

    /**
     * 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 int
     */
    public function handle()
    {
        try{
            $labs = Laboratory::query()->where('record_status_id', 1)
                ->whereRaw("DATEDIFF(end_date, CURDATE())<=-7")
                ->update(['record_status_id' => 0]);
            Log::channel('jobs')->info($labs);
        } catch (\Exception $e){
            Log::channel('jobs')->error($e->getMessage());
        }
    }
}
