<?php

namespace App\DataFixtures;

use App\Doctrine\DBAL\Type\SponsorTypeEnumType;
use App\Entity\Sponsor;
use App\Entity\SponsorType;
use Psr\Log\LoggerInterface;
use App\Utils\ImageFixturesHelper;
use Symfony\Component\Filesystem\Path;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class SponsorFixtures extends Fixture
{
    public function __construct(private LoggerInterface $logger) {
            
    }

    public function load(ObjectManager $manager): void
    {
        $imgHelper = new ImageFixturesHelper($this->logger);

        $raw_sponsors = [

            [
                "name"        => "Centre des arts d'Enghien-les-Bains", 
                "description" => "scène conventionnée art et création pour les écritures numériques et le spectacle vivant",
                "url"         => "https://cda95.fr",
                "address"     => "12-16 Rue de la Libération\n95880 Enghien-les-Bains", 
                "phone"       => "01 30 10 85 59", 
                "email"       => "accueilcda@cdarts.enghien95.fr",
                "logo"        => "Logo-Centre-des-arts-d_Enghien-les-Bains.png",
                "type"        => "partner",
                "sort_name"   => "centre-arts-enghien-les-bains"
            ],

             [
                "name"        => "Espace Michel Berger de Sannois", 
                "description" => "scène de musiques actuelles",
                "url"         => "https://emb-sannois.org",
                "address"     => "2 Rue du Président Georges Pompidou\n95110 Sannois", 
                "phone"       => "01 39 80 01 39", 
                "email"       => "com@emb-sannois.org",
                "logo"        => "Logo-Espace-Michel-Berger.png",
                "type"        => "partner",
                "sort_name"   => "espace-michel-berger-sannois"
            ],

            [
                "name"        => "Festival Baroque de Pontoise", 
                "url"         => "https://festivalbaroque-pontoise.fr", 
                "address"     => "2 Rue des Patis\n95300 Pontoise", 
                "phone"       => "01 34 35 18 71",
                "logo"        => "Logo-Festival-Baroque-de-Pontoise.png", 
                "type"        => "partner",
                "sort_name"   => "festival-baroque-de-pontoise"
            ],

            [
                "name"        => "Festival des arts de la rue Cergy, Soit !", 
                "url"         => "https://cergysoit.fr", 
                "logo"        => "Logo-Cergy-Soit.png", 
                "type"        => "partner",
                "sort_name"   => "cergy-soit"
            ],
            
            [
                "name"        => "Festival Jazz au fil de l’Oise", 
                "url"         => "https://jazzaufildeloise.fr", 
                "address"     => "1 C chemin de Stors\n95290 l’Isle Adam", 
                "phone"       => "06 37 24 90 34", 
                "email"       => "contact@jazzaufildeloise.fr",
                "logo"        => "Logo-Jazz-au-fil-de-l_Oise-rvb.png", 
                "type"        => "partner",
                "sort_name"   => "jazz-au-fil-de-l-oise"
            ],

            [
                "name"        => "Fondation Royaumont", 
                "url"         => "https://royaumont.com", 
                "address"     => "5 Route de Chantilly\n95270 Asnières-sur-Oise", 
                "phone"       => "01 30 35 59 00",
                "logo"        => "Logo-Fondation-Royaumont.png", 
                "type"        => "partner",
                "sort_name"   => "royaumont"
            ],

            [
                "name"        => "Le Forum de Vauréal", 
                "url"         => "https://leforum-vaureal.fr", 
                "address"     => "95 Boulevard de l'Oise\n95490 Vauréal",
                "phone"       => "01 34 41 93 20",
                "logo"        => "Logo-Le-Forum-de-Vaureal.png", 
                "type"        => "partner",
                "sort_name"   => "forum-vaureal"
            ],

            [
                "name"        => "Points communs", 
                "description" => "nouvelle scène nationale Cergy-Pontoise / Val d’Oise", 
                "url"         => "https://points-communs.com", 
                "address"     => "Théâtre des Louvrais\nPlace de la Paix\n95300 Pontoise\n\nThéâtre 95\nAllée des platanes\n95000 Cergy", 
                "phone"       => "01 34 20 14 14", 
                "email"       => "reservation@points-communs.com",
                "logo"        => "Logo-Points-communs.png", 
                "type"        => "partner",
                "sort_name"   => "points-communs"
            ],

            [
                "name"        => "Pôle itinérant en Val d’Oise", 
                "description" => "scène conventionnée art en territoire", 
                "url"         => "https://le-pivo.fr", 
                "address"     => "Hôtel de Mézières\n14 avenue de l’Europe\n95600 EAUBONNE", 
                "phone"       => "01 34 20 32 00", 
                "email"       => "contact@le-pivo.fr",
                "logo"        => "Logo-PIVO-black.png", 
                "type"        => "partner",
                "sort_name"   => "pole-itinerant-val-d-oise"
            ],

            [
                "name"        => "Le Moulin Fondu, Oposito", 
                "description" => "Centre national des arts de la rue et de l’espace public", 
                "url"         => "https://lemoulinfondu.fr", 
                "address"     => "3 Rue Marcel Bourgogne\n95140 Garges-lès-Gonesse", 
                "phone"       => "01 80 96 16 30", 
                "email"       => "contact@oposito.fr",
                "logo"        => "Logo-Le-Moulin-fondu.png", 
                "type"        => "partner",
                "sort_name"   => "moulin-fondu-oposito"
            ],

            [
                "name"        => "Préfecture du Val d’Oise • Ministère chargé de la ville et du logement • le Ministère de la culture (DRAC Île-de-France)", 
                "logo"        => "Logo-Soutenu-par-le-gouvernement.png", 
                "type"        => "sponsor",
                "sort_name"   => "soutien-01"
            ],

            [
                "name"        => "Conseil départemental du Val d’Oise", 
                "logo"        => "Logo-Val-d-Oise-Terre-de-Jeux.png", 
                "type"        => "sponsor",
                "sort_name"   => "soutien-02"
            ],

            [
                "name"        => "Comité d’organisation des Jeux Olympiques et Paralympiques – Paris 2024", 
                "logo"        => "OC_id_RVB_Label_poly.png", 
                "type"        => "sponsor",
                "sort_name"   => "soutien-03"
            ]
        ];

        $nb_data = count($raw_sponsors);

        // $curr_ordre = [ "partner" => 1, "sponsor" => 1 ];
        foreach ($raw_sponsors as $r_sponsor) {


            $xtype = $r_sponsor["type"];
            $type = SponsorType::from($xtype);

            // dump($type);

            // $i_ordre = $curr_ordre[$type];
            // $curr_ordre[$type] += 1;

            // $logoFile = new File("C:\\Travail\\Prince\\repos\\ideev\\l-art-du-collectif\\arco-www\\assets\\" . $logoFileName);

            // https://github.com/dustin10/VichUploaderBundle/issues/70#issuecomment-307373831

            $logo = $imgHelper->prepareUploadedFile($r_sponsor["logo"], "sponsors");

            $sponsor = new Sponsor();
            $sponsor->setName($r_sponsor["name"])
                    // ->setLogoFileName($r_sponsor["logo"])
                    ->setLogoFile($logo)
                    ->setType($type)
                    ->setSortName($r_sponsor["sort_name"])
                    ->setActive(true);
                    // ->setOrdre($i_ordre);

            if (!empty($r_sponsor["description"])) {
                $sponsor->setDescription($r_sponsor["description"]);
            }

            if (!empty($r_sponsor["address"])) {
                $sponsor->setAddress($r_sponsor["address"]);
            }
            if (!empty($r_sponsor["email"])) {
                $sponsor->setEmail($r_sponsor["email"]);
            }
            if (!empty($r_sponsor["phone"])) {
                $sponsor->setPhone($r_sponsor["phone"]);
            }

            if (!empty($r_sponsor["url"])) {
                $sponsor->setUrl($r_sponsor["url"]);
            }

            $manager->persist($sponsor);
        }

        $manager->flush();
    }
}
