<?php
namespace App\Jobs;
use App\Application\Services\PaymentStateMachine;
use App\Domain\Payments\PaymentStatus;
use App\Models\Invoice;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
final class ExpirePaymentsJob implements ShouldQueue {use Dispatchable,InteractsWithQueue,Queueable,SerializesModels;public function handle(PaymentStateMachine $states):void{Invoice::where('status','waiting')->where('expires_at','<=',now())->where('paid_amount_atomic','0')->chunkById(100,fn($rows)=>$rows->each(fn($i)=>$states->transition($i,PaymentStatus::Expired)));}}
