<?php

declare(strict_types=1);

namespace App\Listeners;

use App\Events\PaymentFailed;
use App\Notifications\PaymentFailedNotification;
use Illuminate\Support\Facades\Log;

class HandlePaymentFailed
{
    public function handle(PaymentFailed $event): void
    {
        Log::warning("Payment failed for user #{$event->user->id}", [
            'gateway' => $event->gateway,
            'transaction_id' => $event->gatewayTransactionId,
            'amount' => $event->amount,
            'currency' => $event->currency,
            'reason' => $event->reason,
        ]);

        $event->user->notify(new PaymentFailedNotification(
            gateway: $event->gateway,
            amount: $event->amount,
            currency: $event->currency,
            reason: $event->reason,
        ));
    }
}
