<?php

namespace App\EventHooks\System;

use App\EventHooks\HookEvent;
use App\Models\EmailMarketingSubscriber;

/**
 * Fire noktası: PublicUnsubscribeController (subscriber_id + email) ve
 * Store\UnsubscribeController (client_id + email + channel) — ikisi de
 * 'SubscriberUnsubscribed' hook'unu fire eder. subscriber_id yalnız ilk
 * yolda var; consent-link yolunda email tek güvenilir anahtar.
 */
class SubscriberUnsubscribed extends HookEvent
{
    public const HOOK = 'SubscriberUnsubscribed';

    public function subscriberId(): ?int
    {
        $id = $this->get('subscriber_id');

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

    public function subscriber(): ?EmailMarketingSubscriber
    {
        $id = $this->subscriberId();

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

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