<?php

namespace App\Domain\Scraping\Infrastructure\Service;

use App\Domain\Scraping\Domain\Contract\Service\CbzGeneratorInterface;
use App\Domain\Scraping\Domain\Model\ValueObject\CbzGenerationRequest;
use App\Domain\Scraping\Domain\Model\ValueObject\CbzPath;
use App\Domain\Shared\Domain\Contract\MangaPathManagerInterface;

readonly class CbzGenerator implements CbzGeneratorInterface
{
    public function __construct(
        private MangaPathManagerInterface $mangaPathManager,
    ) {
    }

    public function generate(CbzGenerationRequest $request): CbzPath
    {
        $cbzPath = $this->mangaPathManager->buildChapterCbzPath(
            $request->getMangaTitle(),
            $request->getPublicationYear(),
            $request->getVolumeNumber(),
            $request->getChapterNumber(),
        );
        $this->mangaPathManager->createCbzArchive($request->getFiles(), $cbzPath);
        return new CbzPath($cbzPath);
    }
}
