<?php
namespace boru\ai\Provider;

/**
 * Immutable-ish provider capability descriptor.
 *
 * Keep this lightweight and PHP 5.6+ compatible.
 */
class Capabilities
{
    /** @var bool */
    protected $streaming = false;
    /** @var bool */
    protected $tools = false;
    /** @var bool */
    protected $vision = false;
    /** @var bool */
    protected $files = false;
    /** @var bool */
    protected $audio = false;
    /** @var bool */
    protected $reasoning = false;
    /** @var bool */
    protected $sessionState = false;
    /** @var bool */
    protected $webSearch = false;
    /** @var bool */
    protected $codeExecution = false;
    /** @var bool */
    protected $embeddings = false;
    /** @var array */
    protected $metadata = array();

    public function __construct($data = array())
    {
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                if (property_exists($this, $key)) {
                    $this->$key = is_bool($this->$key) ? ($value ? true : false) : $value;
                }
            }
        }
    }

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

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

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

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

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

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

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

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

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

    public function embeddings($value = null)
    {
        if ($value !== null) {
            $this->embeddings = $value ? true : false;
            return $this;
        }
        return $this->embeddings ? 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 ($value !== null) {
            $this->metadata[$key] = $value;
            return $this;
        }
        return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
    }

    public function toArray()
    {
        return array(
            'streaming' => $this->streaming(),
            'tools' => $this->tools(),
            'vision' => $this->vision(),
            'files' => $this->files(),
            'audio' => $this->audio(),
            'reasoning' => $this->reasoning(),
            'session_state' => $this->sessionState(),
            'web_search' => $this->webSearch(),
            'code_execution' => $this->codeExecution(),
            'embeddings' => $this->embeddings(),
            'metadata' => $this->metadata(),
        );
    }
}
