<?php

namespace App\DataFixtures;

use App\Entity\Document;
use App\Factory\CommentFactory;
use App\Factory\ContactFactory;
use App\Factory\DocumentFactory;
use App\Factory\DocumentObjectFactory;
use App\Factory\MediaObjectLogoFactory;
use App\Factory\MediaObjectProductFactory;
use App\Factory\MediaObjectContactFactory;
use App\Factory\MediaObjectUserFactory;
use App\Factory\PartnerFactory;
use App\Factory\PartnerFollowFactory;
use App\Factory\PostingFactory;
use App\Factory\ProductFactory;
use App\Factory\SaleFactory;
use App\Factory\TaskFactory;
use App\Factory\TaskNoteFactory;
use App\Factory\UserFactory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\HttpKernel\KernelInterface;

class AppFixtures extends Fixture
{


    public function __construct(
        private KernelInterface $appKernel
    )
    {
    }

    public function load(ObjectManager $manager): void
    {
        $projectRoot = $this->appKernel->getProjectDir();
        $mediaPath = $projectRoot . '/public/media/';
        $files = glob($mediaPath . '*');
        foreach ($files as $file) {
            if (is_file($file)) {
                unlink($file);
            }
        }

        $documentPath = $projectRoot . '/public/media/';
        $files = glob($documentPath . '*');
        foreach ($files as $file) {
            if (is_file($file)) {
                unlink($file);
            }
        }

        MediaObjectUserFactory::createMany(20);
        $adminD = UserFactory::createOne(
            [
                'email' => 'd.knudsen@spawntree.de',
                'firstName' => 'Daniel',
                'lastName' => 'Knudsen',
                'password' => 'test',
            ]
        );
        $adminD->setRoles(['ROLE_ADMIN']);

        $adminF = UserFactory::createOne(
            [
                'email' => 'f.eisenmenger@spawntree.de',
                'firstName' => 'Florian',
                'lastName' => 'Eisenmenger',
                'password' => 'test',
            ]
        );
        $adminF->setRoles(['ROLE_ADMIN']);

        UserFactory::createMany(10);
        MediaObjectLogoFactory::createMany(50);
        PartnerFactory::createMany(100);
        MediaObjectContactFactory::createMany(50);
        ContactFactory::createMany(200);
        ProductFactory::createMany(100);
        SaleFactory::createMany(50);
        PostingFactory::createMany(200);
        CommentFactory::createMany(300);
        MediaObjectProductFactory::createMany(50);
        TaskFactory::createMany(50);
        TaskNoteFactory::createMany(100);
        PartnerFollowFactory::createMany(100);
        DocumentObjectFactory::createMany(50);
        DocumentFactory::createMany(50);
    }
}
