<?php

namespace App\EventHooks\Service;

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

/**
 * Fire noktası (DİNAMİK köprü): HookServiceProvider::bridgeLifecycleEvents —
 * App\Events\ProductProvisioningFailed (action='terminate') → AfterModuleTerminateFailed.
 * buildServiceContext + ['params' => [], 'failureResponseMessage' => message].
 * Context: service (model), service_id/serviceid, failureResponseMessage.
 */
class ModuleTerminateFailed extends HookEvent
{
    public const HOOK = 'AfterModuleTerminateFailed';

    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 failureMessage(): ?string
    {
        return $this->get('failureResponseMessage');
    }
}
