<?php

use boru\boruai\Models\Functions\FunctionBase;
use boru\boruai\Models\ToolDefinition;

class LegacyWeatherTemperatureTool extends FunctionBase
{
    public static function functionDefinitions()
    {
        $tool = new ToolDefinition();
        $tool->name(static::functionName());
        $tool->description(static::functionDescription());
        static::setupParameters($tool);
        $tool->register(static::class);
        return $tool;
    }

    public static function functionName()
    {
        return 'get_current_temperature';
    }

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

    public static function agentInstructions()
    {
        return 'Use this tool when the user asks for the current weather temperature.';
    }

    public static function setupParameters($toolDefinition)
    {
        $toolDefinition->addString('location', 'The city and state, e.g., San Francisco, CA');
        $toolDefinition->addString(
            'unit',
            'The temperature unit to use. Infer this from the user\'s location.',
            array('Fahrenheit', 'Celsius')
        );
    }

    public static function handle($tool)
    {
        $temp = $tool->context('temp', 69);
        $someObject = $tool->context('someobject');

        return json_encode(array(
            'location' => $tool->get('location'),
            'unit' => $tool->get('unit'),
            'temperature' => $temp,
            'context_object' => $someObject,
        ));
    }
}
