<?php

namespace Licenzo\Framework\Support;

/**
 * Parameter Bag for storing request attributes and parameters
 */
class ParameterBag
{
    /**
     * Parameter storage.
     */
    protected array $parameters = [];

    /**
     * Create a new parameter bag.
     */
    public function __construct(array $parameters = [])
    {
        $this->parameters = $parameters;
    }

    /**
     * Get all parameters.
     */
    public function all(): array
    {
        return $this->parameters;
    }

    /**
     * Get a parameter value.
     */
    public function get(string $key, $default = null)
    {
        return $this->parameters[$key] ?? $default;
    }

    /**
     * Set a parameter value.
     */
    public function set(string $key, $value): void
    {
        $this->parameters[$key] = $value;
    }

    /**
     * Check if a parameter exists.
     */
    public function has(string $key): bool
    {
        return array_key_exists($key, $this->parameters);
    }

    /**
     * Remove a parameter.
     */
    public function remove(string $key): void
    {
        unset($this->parameters[$key]);
    }

    /**
     * Replace all parameters.
     */
    public function replace(array $parameters): void
    {
        $this->parameters = $parameters;
    }

    /**
     * Add parameters.
     */
    public function add(array $parameters): void
    {
        $this->parameters = array_merge($this->parameters, $parameters);
    }

    /**
     * Get parameter keys.
     */
    public function keys(): array
    {
        return array_keys($this->parameters);
    }

    /**
     * Count parameters.
     */
    public function count(): int
    {
        return count($this->parameters);
    }
}
