<?php

namespace App\Jobs;

use App\Models\Order;
use App\Services\OrderMatchingService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    protected Order $order;

    /**
     * Create a new job instance.
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
        $this->onQueue('matching_' . $order->market_id); // Dedicated queue per market
    }

    /**
     * Execute the job.
     */
    public function handle(OrderMatchingService $matchingService): void
    {
        $matchingService->processOrder($this->order);
    }
}
