<?php

namespace App\Modules\Transactions\Listeners;

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

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

        SendNotification::dispatch(
            $transaction->user_id,
            'transaction.success',
            'Purchase Successful',
            "Your {$transaction->service_name} purchase of ₦" . number_format($transaction->total_amount, 2) . " was successful. Reference: {$transaction->reference}",
            'database',
            'normal',
            ['transaction_id' => $transaction->id, 'reference' => $transaction->reference]
        );
    }
}
