<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Support\Facades\Log;
use Laravel\Cashier\Events\WebhookReceived;
use Livewire\Livewire;

class StripeEventListener
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(WebhookReceived $event): void
    {
        if ($event->payload['type'] === 'invoice.payment_succeeded') {
            session()->flash('alert', ['type' => 'success', 'message' => 'Payment completed successfully.']);
            Log::info('Payment succeeded');
        }

        if ($event->payload['type'] === 'customer.subscription.deleted') {
            session()->flash('alert', ['type' => 'error', 'message' => 'Subscription canceled.']);
            Log::info('Subscription canceled');
        }
    }
}
