<?php

namespace App\EventHooks\Service;

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

/**
 * Fire noktası: HandleInvoiceStatusChange::fireServiceRecurringCompleted (fatura paid'e
 * geçince, ilk-cycle olmayan her yenileme ürünü için ayrı fire). buildServiceContext +
 * invoice extra. Context: service (model), service_id/serviceid, invoice_id/invoiceid.
 */
class ServiceRecurringCompleted extends HookEvent
{
    public const HOOK = 'ServiceRecurringCompleted';

    public function service(): ?ClientProduct
    {
        $s = $this->get('service');
        if ($s instanceof ClientProduct) {
            return $s;
        }
        $id = $this->get('service_id') ?? $this->get('serviceid');

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

    public function invoice(): ?Invoice
    {
        $id = $this->get('invoice_id') ?? $this->get('invoiceid');

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