<?php
namespace boru\ai\Mcp;

class McpServerConfig
{
    /** @var string */
    protected $name;

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

    /** @var string */
    protected $protocolVersion = '2025-06-18';

    /** @var string|null */
    protected $command;

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

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

    /** @var string|null */
    protected $url;

    /** @var string|null */
    protected $host;

    /** @var int|null */
    protected $port;

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

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

    /** @var float */
    protected $connectTimeout = 3.0;

    /** @var float */
    protected $readTimeout = 3.0;

    public function __construct(array $data = array())
    {
        if (isset($data['name'])) {
            $this->name($data['name']);
        }
        if (isset($data['transport'])) {
            $this->transport($data['transport']);
        }
        if (isset($data['protocol_version'])) {
            $this->protocolVersion($data['protocol_version']);
        }
        if (isset($data['command'])) {
            $this->command($data['command']);
        }
        if (isset($data['args'])) {
            $this->args($data['args']);
        }
        if (isset($data['env'])) {
            $this->env($data['env']);
        }
        if (isset($data['url'])) {
            $this->url($data['url']);
        }
        if (isset($data['host'])) {
            $this->host($data['host']);
        }
        if (isset($data['port'])) {
            $this->port($data['port']);
        }
        if (isset($data['headers'])) {
            $this->headers($data['headers']);
        }
        if (isset($data['auth'])) {
            $this->auth($data['auth']);
        }
        if (isset($data['connect_timeout'])) {
            $this->connectTimeout($data['connect_timeout']);
        }
        if (isset($data['read_timeout'])) {
            $this->readTimeout($data['read_timeout']);
        }
    }

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

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

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

    public function command($value = null)
    {
        if ($value !== null) {
            $this->command = $value === '' ? null : (string)$value;
            return $this;
        }
        return $this->command;
    }

    public function args(array $value = null)
    {
        if ($value !== null) {
            $this->args = array_values($value);
            return $this;
        }
        return $this->args;
    }

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

    public function url($value = null)
    {
        if ($value !== null) {
            $this->url = $value === '' ? null : (string)$value;
            return $this;
        }
        return $this->url;
    }

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

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

    public function host($value = null)
    {
        if ($value !== null) {
            $this->host = $value === '' ? null : (string)$value;
            return $this;
        }
        return $this->host;
    }

    public function port($value = null)
    {
        if ($value !== null) {
            $this->port = $value === null ? null : (int)$value;
            return $this;
        }
        return $this->port;
    }

    public function connectTimeout($value = null)
    {
        if ($value !== null) {
            $value = (float)$value;
            $this->connectTimeout = $value > 0 ? $value : 3.0;
            return $this;
        }
        return $this->connectTimeout;
    }

    public function readTimeout($value = null)
    {
        if ($value !== null) {
            $value = (float)$value;
            $this->readTimeout = $value > 0 ? $value : 3.0;
            return $this;
        }
        return $this->readTimeout;
    }

    public function toArray()
    {
        return array(
            'name' => $this->name(),
            'transport' => $this->transport(),
            'protocol_version' => $this->protocolVersion(),
            'command' => $this->command(),
            'args' => $this->args(),
            'env' => $this->env(),
            'url' => $this->url(),
            'host' => $this->host(),
            'port' => $this->port(),
            'headers' => $this->headers(),
            'auth' => $this->auth(),
            'connect_timeout' => $this->connectTimeout(),
            'read_timeout' => $this->readTimeout(),
        );
    }
}
