<?php

namespace App\EventHooks\Catalog;

use App\EventHooks\HookEvent;
use App\Models\Post;

/**
 * Fire noktası: PostCrudActions::store — postType()==='announcement' iken yeni
 * duyuru oluşturulduğunda → AnnouncementAdd. Gap (Task 11).
 * Context: announcement (Post modeli), announcementid/announcement_id, title, published.
 *
 * NOT: PROCP'te ayrı Announcement modeli yok — UnifiedPost STI (Post, type='announcement').
 */
class AnnouncementAdded extends HookEvent
{
    public const HOOK = 'AnnouncementAdd';

    public function announcement(): ?Post
    {
        $a = $this->get('announcement');
        if ($a instanceof Post) {
            return $a;
        }
        $id = $this->get('announcement_id') ?? $this->get('announcementid');

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