<?php

declare(strict_types=1);

namespace App\Core;

class Config
{
    private static array $items = [];

    public static function set(
        string $key,
        array $value
    ): void {
        self::$items[$key] = $value;
    }

    public static function get(
        string $key,
        mixed $default = null
    ): mixed {
        $segments = explode('.', $key);

        $value = self::$items;

        foreach ($segments as $segment) {
            if (
                !is_array($value) ||
                !array_key_exists($segment, $value)
            ) {
                return $default;
            }

            $value = $value[$segment];
        }

        return $value;
    }
}