<?php

namespace App\EventHooks\Invoice;

use App\EventHooks\HookEvent;
use App\Models\Invoice;

/**
 * Fire noktası: InvoiceObserver::updated → buildInvoiceContext (hook adı: UpdateInvoiceTotal)
 * Context: invoice (model), invoice_id, status.
 */
class InvoiceTotalUpdated extends HookEvent
{
    public const HOOK = 'UpdateInvoiceTotal';

    public function invoice(): ?Invoice
    {
        $i = $this->get('invoice');
        if ($i instanceof Invoice) {
            return $i;
        }
        $id = $this->get('invoice_id');

        return $id ? Invoice::find($id) : null;
    }
}
