<?php

namespace App\EventHooks\Ticket;

use App\EventHooks\HookEvent;
use App\Models\Ticket;

/**
 * Fire noktası: TicketObserver::updated (title değişti) → TicketSubjectChange.
 * buildTicketContext (PROCP'de subject = title alanı). Context: ticket (model),
 * subject (güncel başlık).
 */
class TicketSubjectChanged extends HookEvent
{
    public const HOOK = 'TicketSubjectChange';

    public function ticket(): ?Ticket
    {
        $t = $this->get('ticket');
        if ($t instanceof Ticket) {
            return $t;
        }
        $id = $this->get('ticket_id') ?? $this->get('ticketid');

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

    /** Güncel başlık (ctx 'subject' = title). */
    public function subject(): mixed
    {
        return $this->get('subject');
    }
}
