<?php

namespace App\Jobs;

use App\Models\DesawarRecord;
use App\Models\MarketRecord;
use App\Models\Otp;
use App\Models\StartLineRecord;
use App\Models\Transaction;
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;

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

    public function __construct()
    {
        //
    }

    public function handle(): void
    {
        Otp::where('created_at', '<=', now()->subMinutes(30))->delete();
        Transaction::where('created_at', '<=', now()->subDays(4))->delete();
        StartLineRecord::where('created_at', '<=', now()->subDays(4))->delete();
        DesawarRecord::where('created_at', '<=', now()->subDays(4))->delete();
        MarketRecord::where('created_at', '<=', now()->subDays(4))->delete();
    }
}
