<?php
namespace Misuzu\Config;

final class CfgTools {
    public static function type($value): string {
        return gettype($value);
    }

    public static function isValidType(string $type): bool {
        return $type === IConfig::T_ARR
            || $type === IConfig::T_BOOL
            || $type === IConfig::T_INT
            || $type === IConfig::T_STR;
    }

    public static function validateName(string $name): bool {
        // this should better validate the format, this allows for a lot of shittery
        return preg_match('#^([a-z][a-zA-Z0-9._]+)$#', $name) === 1;
    }

    private const DEFAULTS = [
        IConfig::T_ANY => null,
        IConfig::T_STR => '',
        IConfig::T_INT => 0,
        IConfig::T_BOOL => false,
        IConfig::T_ARR => [],
    ];

    public static function default(string $type) {
        return self::DEFAULTS[$type] ?? null;
    }
}
