<?php

namespace App\EventHooks\System;

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

/**
 * Fire noktası: AcmeService — sertifika başarıyla issue edilince
 * 'SSLCertificateIssued' hook'u (hook adı boşluksuz). Context:
 * ssl_certificate_id, client_product_id, service_id (=client_product_id),
 * client_id, domain (common_name).
 */
class SslCertificateIssued extends HookEvent
{
    public const HOOK = 'SSLCertificateIssued';

    public function serviceId(): ?int
    {
        $id = $this->get('service_id') ?? $this->get('client_product_id');

        return $id ? (int) $id : null;
    }

    public function service(): ?ClientProduct
    {
        $id = $this->serviceId();

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

    public function domain(): ?string
    {
        return $this->get('domain');
    }
}
