<?php

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Manager;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin\SocialNetwork\SocialNetworkNetworkInterface;

final class SocialNetworkNetworkManager
{
    /** @var list<SocialNetworkNetworkInterface> */
    private array $networks = [];

    public function addMethod(SocialNetworkNetworkInterface $network): void
    {
        $this->networks[] = $network;
    }

    /**
     * @return class-string
     *
     * @throws \RuntimeException
     */
    public function createFormSocialNetworkManager(string $network): string
    {
        foreach ($this->networks as $item) {
            if ($item->getNetwork() === $network) {
                // Symfony 7: on retourne la FQCN du type
                return $item::class;
            }
        }

        throw new \RuntimeException('Pas de réseau social configuré pour ce site');
    }
}
