<?php

namespace App\DataFixtures;

use App\Entity\Post;
use App\Entity\Species;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class AppFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        $faker = \Faker\Factory::create();
        for ($i = 0; $i < 20; ++$i) {
            $name = $faker->text();
            $species = (new Species())
                ->setScientificName($name)
                ->setVernacularName($name)
                ->setRegion($faker->country());
            $date = DateTimeImmutable::createFromMutable($faker->dateTime());
            $post = (new Post())
                ->setFoundDate($date)
                ->setPublicationDate($date)
                ->setLatitude($faker->randomFloat())
                ->setLongitude($faker->randomFloat())
                ->setCommentary($faker->text());
            $manager->persist($species);
            $manager->persist($post);
        }
        $manager->flush();
    }
}
