<?php

namespace App\Listeners;

use App\Events\OrderConfirmed;
use App\Services\AuditService;

class LogOrderConfirmed
{
    /**
     * Create the event listener.
     */
    public function __construct(
        protected AuditService $auditService,
    ) {}

    /**
     * Handle the event.
     */
    public function handle(OrderConfirmed $event): void
    {
        $this->auditService->log(
            action: 'order_confirmed',
            model: $event->order,
            userId: $event->confirmedBy->id,
            data: [
                'order_number' => $event->order->order_number,
                'order_type' => $event->order->order_type,
                'money_amount' => $event->order->money_amount,
                'customer_id' => $event->order->user_id,
            ]
        );
    }
}
