<?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 ProcessMarketOrderJob 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('market_orders'); // Queue for market orders
    }

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