<?php

namespace App\DataFixtures;

use App\Entity\History;
use App\Entity\Place;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
use App\Entity\Stats;

class HistoryFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        $faker = Factory::create('fr_FR');


        $places_list = [];

        // Créer quelques places de test
        for ($i = 0; $i < 15; $i++) {
            $place = new Place();
            $place->setName($faker->company . ' (mock)')
            ->setUuidForUrl($faker->uuid)
            ->setOsmId((string)$faker->numberBetween(1000000, 9999999))
            ->setOsmKind($faker->randomElement(['node', 'way', 'relation']))
            ->setEmail($faker->email)
            ->setOptedOut($faker->boolean)
            ->setDead($faker->boolean)
            ->setNote($faker->text)
            ->setMainTag($faker->randomElement(['amenity=cafe', 'shop=supermarket', 'tourism=museum']))
            ->setModifiedDate($faker->dateTimeBetween('-1 year', 'now'))
            ->setAskedHumainsSupport($faker->boolean)
            ->setLastContactAttemptDate($faker->dateTimeBetween('-1 year', 'now'))
            ->setZipCode($faker->numberBetween(10000, 99999));
            $manager->persist($place);
            $places_list[] = $place;
            // Créer plusieurs historiques pour chaque place
            for ($j = 0; $j < 3; $j++) {
                $history = new History();
                $history->setPlaceId($place);
                $history->setCompletionPercent($faker->numberBetween(0, 100));
                $history->setDateTime($faker->dateTimeBetween('-1 year', 'now'));
                $manager->persist($history);
            }
        }

        // Créer des statistiques de test
        for ($i = 0; $i < 3; $i++) {
            $stat = new Stats();
            $stat->setZone($faker->numberBetween(10000, 99999) )
            ->setCompletionPercent($faker->numberBetween(0, 100))
                ->addPlace( $faker->randomElement($places_list))
                ->addPlace( $faker->randomElement($places_list))
                ->addPlace( $faker->randomElement($places_list))
                ->setPlacesCount($faker->numberBetween(100, 1000));
            $manager->persist($stat);
        }

        $manager->flush();
    }
} 