<?php

declare(strict_types=1);

/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Settings;

use Chamilo\CoreBundle\Form\Type\YesNoType;
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

class WebServiceSettingsSchema extends AbstractSettingsSchema
{
    public function buildSettings(AbstractSettingsBuilder $builder): void
    {
        $builder
            ->setDefaults(
                [
                    'messaging_allow_send_push_notification' => 'false',
                    'messaging_gdc_project_number' => '',
                    'messaging_gdc_api_key' => '',
                    'allow_download_documents_by_api_key' => 'false',
                    'disable_webservices' => 'false',
                    'webservice_enable_adminonly_api' => 'false',
                    'webservice_return_user_field' => 'oauth2_id',
                ]
            )
        ;
        $allowedTypes = [];
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
    }

    public function buildForm(FormBuilderInterface $builder): void
    {
        $builder
            ->add('messaging_allow_send_push_notification', YesNoType::class)
            ->add('messaging_gdc_project_number')
            ->add('messaging_gdc_api_key')
            ->add('allow_download_documents_by_api_key', YesNoType::class)
            ->add('disable_webservices', YesNoType::class)
            ->add('webservice_enable_adminonly_api', YesNoType::class)
            ->add('webservice_return_user_field', TextType::class)
        ;

        $this->updateFormFieldsFromSettingsInfo($builder);
    }
}
