<?php
/**
 * Configuration Repository
 *
 * @package ZenoChatbot\Framework\Config
 */

namespace ZenoChatbot\Framework\Config;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Configuration repository for accessing config data
 */
class Repository
{
    /**
     * Configuration data
     *
     * @var array
     */
    protected array $config;

    /**
     * Constructor
     *
     * @param array $config
     */
    public function __construct(array $config = [])
    {
        $this->config = $config;
    }

    /**
     * Get a configuration value using dot notation
     *
     * @param string $key
     * @param mixed $default
     * @return mixed
     */
    /**
     * @param mixed $default
     * @return mixed
     */
    public function get(string $key, $default = null)
    {
        $value = $this->config;
        foreach (explode('.', $key) as $segment) {
            if (!is_array($value) || !array_key_exists($segment, $value)) {
                return $default;
            }
            $value = $value[$segment];
        }
        return $value;
    }

    /**
     * Check if a configuration value exists
     *
     * @param string $key
     * @return bool
     */
    public function has(string $key): bool
    {
        return $this->get($key) !== null;
    }

    /**
     * Get all configuration values
     *
     * @return array
     */
    public function all(): array
    {
        return $this->config;
    }
}
