<?php
namespace boru\ai\Provider;

class ProviderSignal
{
    const RESPONSE_CREATED = 'provider.response.created';
    const TEXT_DELTA = 'provider.text.delta';
    const TEXT_COMPLETED = 'provider.text.completed';
    const TOOL_CALL_STARTED = 'provider.tool_call.started';
    const TOOL_CALL_ARGUMENTS_DELTA = 'provider.tool_call.arguments.delta';
    const TOOL_CALL_COMPLETED = 'provider.tool_call.completed';
    const RESPONSE_COMPLETED = 'provider.response.completed';
    const RESPONSE_FAILED = 'provider.response.failed';
    const RESPONSE_ERROR = 'provider.response.error';

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

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

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

    public function __construct($type = null, $data = array(), $response = null)
    {
        $this->type = $type;
        if (is_array($data)) {
            $this->data = $data;
        }
        $this->response = $response;
    }

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

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

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