<?php

namespace App\EventHooks\Invoice;

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

/**
 * Fire noktası: QuoteService::accept → AcceptQuote (buildQuoteContext + invoice_id)
 * Context: quote_id, status, total, invoice_id. (modeller taşınmaz; id'den lazy load.)
 */
class QuoteAccepted extends HookEvent
{
    public const HOOK = 'AcceptQuote';

    public function quote(): ?Quote
    {
        $q = $this->get('quote');
        if ($q instanceof Quote) {
            return $q;
        }
        $id = $this->get('quote_id');

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

    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;
    }
}
