<?php

namespace App\DataFixtures;

use App\Factory\ApiTokenFactory;
use App\Factory\ChapterFactory;
use App\Factory\MangaFactory;
use App\Factory\PageFactory;
use App\Factory\UserFactory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class AppFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        UserFactory::createMany(20);
        ApiTokenFactory::createMany(60, function () {
            return [
                'ownedBy' => UserFactory::random()
            ];
        });

        $mangas = MangaFactory::createMany(25);

        foreach ($mangas as $manga) {

            for ($i = 1; $i <= 5; $i++) {
                $manga->addChapter(ChapterFactory::createOne([
                    'manga' => $manga,
                    'number' => $i
                ])->object());
            }

            foreach ($manga->getChapters() as $chapter) {
                for ($i = 1; $i <= 5; $i++) {
                    $chapter->addPagesLink(PageFactory::createOne([
                        'chapter' => $chapter,
                        'number' => $i
                    ])->object());
                }
            }
        }
    }
}
