<?php
namespace boru\ai\Schema;

class ToolResult
{
    /** @var string */
    protected $toolCallId;

    /** @var string */
    protected $name;

    /** @var mixed */
    protected $output;

    /** @var bool */
    protected $success = true;

    /** @var array */
    protected $metadata = array();

    public function toolCallId($value = null)
    {
        if ($value !== null) {
            $this->toolCallId = (string)$value;
            return $this;
        }
        return $this->toolCallId;
    }

    public function name($value = null)
    {
        if ($value !== null) {
            $this->name = (string)$value;
            return $this;
        }
        return $this->name;
    }

    public function output($value = null)
    {
        if (func_num_args() > 0) {
            $this->output = $value;
            return $this;
        }
        return $this->output;
    }

    public function success($value = null)
    {
        if ($value !== null) {
            $this->success = $value ? true : false;
            return $this;
        }
        return $this->success ? true : false;
    }

    public function metadata($key = null, $value = null)
    {
        if ($key === null) {
            return $this->metadata;
        }
        if (is_array($key)) {
            $this->metadata = $key;
            return $this;
        }
        if (func_num_args() > 1) {
            $this->metadata[$key] = $value;
            return $this;
        }
        return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
    }

    public function toArray()
    {
        return array(
            'tool_call_id' => $this->toolCallId(),
            'name' => $this->name(),
            'output' => $this->output(),
            'success' => $this->success(),
            'metadata' => $this->metadata(),
        );
    }
}
