<?php

namespace Plainwork\Http;

class Response
{
    private $statusCode;
    private $body;
    private $headers = [];
    private $protocolVersion = '1.1';

    public function __construct($statusCode = 200)
    {
        $this->statusCode = $statusCode;
    }

    public function getBody()
    {
        return $this->body;
    }

    public function withBody($body)
    {
        $ret = clone $this;
        $ret->body = $body;

        return $ret;
    }

    public function withHeader($k, $v)
    {
        $ret = clone $this;
        if (!isset($ret->headers[$k])) {
            $ret->headers[$k] = [];
        }
        $ret->headers[$k][] = $v;

        return $ret;
    }

    public function getHeader(string $name)
    {
        return isset($this->headers[$name]) ? join('', $this->headers[$name]) : null;
    }

    public function getHeaders()
    {
        return $this->headers;
    }

    public function getStatusCode()
    {
        return $this->statusCode;
    }

    public function getProtocolVersion()
    {
        return $this->protocolVersion;
    }
}
