<?php

namespace Modules\WhatsApp\Observers;

use App\TransactionPayment;
use Modules\WhatsApp\Entities\Services\WaNotifier;

/**
 * Sends a "payment received" WhatsApp when a payment is recorded against a sell
 * invoice. Deduped per payment id, so editing the transaction won't re-send.
 */
class TransactionPaymentObserver
{
    public function created(TransactionPayment $payment): void
    {
        // Only real, non-return inbound payments.
        if ((int) ($payment->is_return ?? 0) === 1) {
            return;
        }
        if ((float) $payment->amount <= 0) {
            return;
        }

        (new WaNotifier())->paymentReceived($payment);
    }
}
