<?php
/**
 * Exposition publique des réglages d'intégration du widget dans WPGraphQL.
 */

defined('ABSPATH') || exit;

add_action('graphql_register_types', 'cvb_chatbot_register_graphql_types');

function cvb_chatbot_register_graphql_types(): void {
    if (!function_exists('register_graphql_object_type') || !function_exists('register_graphql_field')) {
        return;
    }

    register_graphql_object_type('CovalbaChatbotSettings', [
        'description' => "Réglages publics du widget chatbot Covalba.",
        'fields'      => [
            'enabled'   => ['type' => 'Boolean', 'description' => 'Indique si le widget doit être chargé sur le front.'],
            'widgetUrl' => ['type' => 'String', 'description' => "Origine publique de l'app chatbot, sans slash final."],
        ],
    ]);

    register_graphql_field('RootQuery', 'covalbaChatbotSettings', [
        'type'        => 'CovalbaChatbotSettings',
        'description' => "Réglages publics du widget chatbot Covalba.",
        'resolve'     => static fn() => cvb_chatbot_public_settings(),
    ]);
}
