<?php

namespace App\Modules\Transactions\Listeners;

use App\Modules\Transactions\Events\TransactionFailed;
use App\Modules\Notifications\Jobs\SendNotification;

class SendTransactionFailedNotification
{
    public function handle(TransactionFailed $event): void
    {
        $transaction = $event->transaction;

        SendNotification::dispatch(
            $transaction->user_id,
            'transaction.failed',
            'Purchase Failed',
            "Your {$transaction->service_name} purchase of ₦" . number_format($transaction->total_amount, 2) . " failed. {$event->reason}. You have been refunded.",
            'database',
            'high',
            ['transaction_id' => $transaction->id, 'reference' => $transaction->reference, 'reason' => $event->reason]
        );
    }
}
