<?php

declare(strict_types=1);

namespace App\DependencyInjection\Compiler;

use App\Mcp\Schema\CoercingSchemaGenerator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Wires the CoercingSchemaGenerator into the MCP server builder so that
 * generated tool input schemas accept stringified scalar arguments.
 */
final class McpSchemaGeneratorPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition('mcp.server.builder')) {
            return;
        }

        $container->getDefinition('mcp.server.builder')
            ->addMethodCall('setSchemaGenerator', [new Reference(CoercingSchemaGenerator::class)])
        ;
    }
}
