<?php

namespace App\Listeners;

use App\Events\TransactionSettled;
use App\Services\AuditService;

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

    /**
     * Handle the event.
     */
    public function handle(TransactionSettled $event): void
    {
        $this->auditService->log(
            action: 'transaction_settled',
            model: $event->transaction,
            userId: $event->settledBy->id,
            data: [
                'transaction_number' => $event->transaction->transaction_number,
                'amount' => $event->transaction->amount,
                'from_user_id' => $event->transaction->from_user_id,
                'to_user_id' => $event->transaction->to_user_id,
            ]
        );
    }
}
