<?php

namespace App\Jobs;

use App\Models\TransaksiParkir;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class VerificationSkiper implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $dateNow = Carbon::now();
        
        $RealtimeTrans = TransaksiParkir::select('no_pol')
        ->where('status', 1)
        ->where('veri_check','1')
        ->where('status_transaksi', '3')
        ->whereDate('veri_date', $dateNow)
        ->first();

        Log::channel('apps')->info('Verification member check : ' . json_encode($RealtimeTrans));

        if ($RealtimeTrans) {
            DB::table('transaksi_parkir')
            ->where('no_pol', $RealtimeTrans->no_pol )
            ->update(['veri_check' => 2,
            'veri_date' => $dateNow,
            'veri_adm' => 'SYSTEM'
            ]);
            
            // $response = true;
            $message = [
                'no_pol' => $RealtimeTrans->no_pol,
                'message' => 'member skipped'
            ];
            Log::info('Skip verification ' . $RealtimeTrans->no_pol . ' Succesfully...');
        }
    }
}
