<?php

use boru\ai\Runtime\AbstractTool;
use boru\ai\Runtime\ToolExecutionContext;

class WeatherTemperatureTool extends AbstractTool
{
    public function name()
    {
        return 'get_current_temperature';
    }

    public function description()
    {
        return 'Get the current temperature for a specific location';
    }

    public function schema()
    {
        return array(
            'type' => 'object',
            'properties' => array(
                'location' => array(
                    'type' => 'string',
                    'description' => 'The city and state, e.g., San Francisco, CA',
                ),
                'unit' => array(
                    'type' => 'string',
                    'description' => 'The temperature unit to use. Infer this from the user\'s location.',
                    'enum' => array('Fahrenheit', 'Celsius'),
                ),
            ),
            'required' => array('location', 'unit'),
        );
    }

    public function handle(array $arguments, ToolExecutionContext $context = null)
    {
        $temp = $context ? $context->get('temp', 69) : 69;

        return json_encode(array(
            'location' => isset($arguments['location']) ? $arguments['location'] : null,
            'unit' => isset($arguments['unit']) ? $arguments['unit'] : null,
            'temperature' => $temp,
        ));
    }
}