<?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='unsuspend') → AfterModuleUnsuspendFailed.
 * buildServiceContext + ['params' => [], 'failureResponseMessage' => message].
 * Context: service (model), service_id/serviceid, failureResponseMessage.
 */
class ModuleUnsuspendFailed extends HookEvent
{
    public const HOOK = 'AfterModuleUnsuspendFailed';

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