<?php
namespace boru\ai\Runtime;

abstract class AbstractTool implements ToolInterface
{
    public function description()
    {
        return '';
    }

    public function schema()
    {
        return array(
            'type' => 'object',
            'properties' => array(),
        );
    }

    public function toToolDefinition()
    {
        $tool = $this;
        $metadata = array(
            'class' => get_class($this),
        );

        if ($this instanceof ToolPromptAdditionInterface) {
            $promptAddition = trim((string)$this->promptAddition());
            if ($promptAddition !== '') {
                $metadata['prompt_addition'] = $promptAddition;
            }
        }

        $definition = new ToolDefinition();
        $definition->name($this->name())
            ->description($this->description())
            ->schema($this->schema())
            ->callback(function (array $arguments, ToolExecutionContext $context = null) use ($tool) {
                return $tool->handle($arguments, $context);
            })
            ->metadata($metadata);

        return $definition;
    }
}
