<?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 === CfgType::T_ARR
            || $type === CfgType::T_BOOL
            || $type === CfgType::T_INT
            || $type === CfgType::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 = [
        CfgType::T_ANY => null,
        CfgType::T_STR => '',
        CfgType::T_INT => 0,
        CfgType::T_BOOL => false,
        CfgType::T_ARR => [],
    ];

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