<?php

declare(strict_types=1);

namespace App\Events\Wiki\Anime\Theme\Entry;

use App\Contracts\Events\UpdateRelatedIndicesEvent;
use App\Events\Base\Wiki\WikiDeletedEvent;
use App\Filament\Resources\Wiki\Anime\Theme\Entry as EntryFilament;
use App\Models\Wiki\Anime\Theme\AnimeThemeEntry;
use App\Models\Wiki\Video;

/**
 * @extends WikiDeletedEvent<AnimeThemeEntry>
 */
class EntryDeleted extends WikiDeletedEvent implements UpdateRelatedIndicesEvent
{
    public function __construct(AnimeThemeEntry $entry)
    {
        parent::__construct($entry);
    }

    public function getModel(): AnimeThemeEntry
    {
        return $this->model;
    }

    protected function getDiscordMessageDescription(): string
    {
        return "Entry '**{$this->getModel()->getName()}**' has been deleted.";
    }

    protected function getNotificationMessage(): string
    {
        return "Entry '{$this->getModel()->getName()}' has been deleted. It will be automatically pruned in one week. Please review.";
    }

    protected function getFilamentNotificationUrl(): string
    {
        return EntryFilament::getUrl('view', ['record' => $this->getModel()]);
    }

    public function updateRelatedIndices(): void
    {
        $entry = $this->getModel();

        $videos = $entry->videos;
        $videos->each(fn (Video $video) => $video->searchable());
    }
}
