<?php

namespace App\DataFixtures;

use App\Entity\Forum;
use App\Entity\Categorie;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;

class ForumFixtures extends Fixture implements DependentFixtureInterface
{
    private $faker;

    public function __construct()
    {
        $this->faker = Factory::create("fr_FR");
    }

    public function load(ObjectManager $manager): void
    {
        for ($i = 0; $i < 10; $i++) {
            $forum = new Forum();
            $forum->setNom($this->faker->lastName());
            $forum->setCategorie($this->getReference('categorie_' . mt_rand(0, 4), Categorie::class));
            $this->addReference('forum' . $i, $forum);
            $manager->persist($forum);
        }
        $manager->flush();
    }

    public function getDependencies(): array
    {
        return [
            CategorieFixtures::class
        ];
    }
}