<?php

namespace App\Domain\Manga\Application\EventListener;

use App\Domain\Manga\Application\Command\FetchMangaChapters;
use App\Domain\Manga\Application\CommandHandler\FetchMangaChaptersHandler;
use App\Domain\Manga\Domain\Event\MangaCreated;
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;

readonly class MangaCreatedEventListener
{
    public function __construct(
        private FetchMangaChaptersHandler $fetchMangaChaptersHandler
    ) {
    }

    public function __invoke(MangaCreated $event): void
    {
        $this->fetchMangaChaptersHandler->handle(
            new FetchMangaChapters(new MangaId($event->mangaId))
        );
    }
}
