<?php
namespace App\Jobs;
use App\Application\Services\Payouts\{PayoutPolicyService,PayoutStateMachine};use App\Models\Payout;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Illuminate\Support\Facades\Cache;
final class ApprovePayoutJob implements ShouldQueue {use Dispatchable,InteractsWithQueue,Queueable,SerializesModels;public function __construct(public int $payoutId){$this->onQueue('payouts');}public function handle(PayoutPolicyService $policy,PayoutStateMachine $sm):void{$lock=Cache::lock("payout:{$this->payoutId}",120);if(!$lock->get())return;try{$p=Payout::with('asset')->findOrFail($this->payoutId);if($p->status!=='approved')return;$policy->assertNoKillSwitch($p);BroadcastPayoutJob::dispatch($p->id)->onQueue('payouts');}finally{$lock->release();}}}
