<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin\SocialNetwork;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin\DataTransformer\JsonModelTransformerFactory;
use CpCreation\VitiCore\SocialNetwork\Model\Network\Instagram;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class InstagramNetworkType extends AbstractType implements SocialNetworkNetworkInterface
{
    public const TYPE = 'instagram';

    public function __construct(
        private readonly JsonModelTransformerFactory $transformers,
    ) {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('clientId', TextType::class, [
                'label' => 'Client ID',
                'required' => true,
            ])
            ->add('clientSecret', TextType::class, [
                'label' => 'Client Secret',
                'required' => true,
            ]);

        $builder->addModelTransformer(
            $this->transformers->for(Instagram::class)
        );
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Instagram::class,
        ]);
    }

    public function getNetwork(): string
    {
        return self::TYPE;
    }

    public function getBlockPrefix(): string
    {
        return 'instagram_network';
    }
}
