<?php

namespace App\Observers;

use App\Models\DetailPembayaran;

class DetailPembayaranObserver
{
    /**
     * Handle the DetailPembayaran "created" event.
     * Apply the payment amount to the associated Tagihan using its applyPayment method.
     */
    public function created(DetailPembayaran $detail): void
    {
        $tagihan = $detail->tagihan;
        if ($tagihan) {
            $tagihan->applyPayment((float) $detail->jumlah_bayar);
        }
    }
}
