<?php

namespace Sitecake\Http;

/**
 * Simple HTTP header bag used by Response.
 */
class HeaderBag
{
    private array $headers;

    public function __construct(array $headers = [])
    {
        $this->headers = $headers;
    }

    public function set(string $name, string $value): void
    {
        $this->headers[$name] = $value;
    }

    public function has(string $name): bool
    {
        return isset($this->headers[$name]);
    }

    public function get(string $name, ?string $default = null): ?string
    {
        return $this->headers[$name] ?? $default;
    }

    public function all(): array
    {
        return $this->headers;
    }
}
