<?php

namespace Modules\Payment\Observers;

use Illuminate\Support\Facades\Mail;
use Modules\Payment\Enums\PaymentStatus;
use Modules\Payment\Mail\NewBookingAlert;
use Modules\Payment\Models\Payment;

class PaymentObserver
{
    public function created(Payment $payment): void
    {
        if ($payment->status === PaymentStatus::Failed) return;

        try {
            $admin_emails = config('booking.admin_emails');

            Mail::bcc($admin_emails)->queue(new NewBookingAlert($payment));
        } catch (\Exception $e) {
            // Log the exception or handle it as needed
            \Log::error('Failed to send NewBookingAlert email: ' . $e->getMessage());
        }
    }

    public function updated(Payment $payment): void
    {
        // Handle the event when a payment is updated for a booking
    }

    public function deleted(Payment $payment): void
    {
        // Handle the event when a payment is deleted for a booking
    }
}
