<?php

namespace App\EventHooks\Domain;

use App\EventHooks\HookEvent;
use App\Models\ClientDomain;

/**
 * Fire noktası: RegistrarManager::call() generic after-hook (registerDomain →
 * suffix=Register → AfterRegistrarRegister). Otomatik fire — her register
 * çağrısında. Context: params (DomainModuleParamsBuilder zenginleştirmesi:
 * domain=ad string, domain_id, module_name, ...), results, functionExists,
 * functionSuccessful. Context'te 'domain' modeli/registrar anahtarı YOK —
 * params'tan çözülür.
 */
class RegistrarRegistered extends HookEvent
{
    public const HOOK = 'AfterRegistrarRegister';

    public function domain(): ?ClientDomain
    {
        $params = $this->get('params', []);
        $id = is_array($params) ? ($params['domain_id'] ?? null) : null;

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

    public function registrar(): ?string
    {
        $params = $this->get('params', []);

        return is_array($params) ? ($params['module_name'] ?? null) : null;
    }
}
