<?php

/**
 * Vvveb
 *
 * Copyright (C) 2022  Ziadin Givan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

namespace Vvveb;



/**
 * Get a configuration value or the Config instance.
 *
 * @param string|null $key     Config key to retrieve, or null for the Config instance
 * @param mixed       $default Default value if key is not found
 *
 * @return mixed Configuration value or Config instance
 */

function config(?string $key = null, mixed $default = null): mixed {
	if (is_null($key)) {
		return System\Config::getInstance();
	}

	return System\Config::getInstance()->get($key, $default);
}



/**
 * Get a configuration value.
 *
 * @param string|null $key     Config key to retrieve, or null for all config
 * @param mixed       $default Default value if key is not found
 *
 * @return mixed Configuration value
 */

function getConfig(?string $key = null, mixed $default = null): mixed {
	return System\Config::getInstance()->get($key, $default);
}



/**
 * Set a configuration value.
 *
 * @param string $key   Config key to set
 * @param mixed  $value Value to set
 *
 * @return bool True on success
 */

function setConfig(string $key, mixed $value = null): bool {
	return System\Config::getInstance()->set($key, $value);
}



/**
 * Remove a configuration value.
 *
 * @param string $key Config key to remove
 *
 * @return mixed Result of the unset operation
 */

function unsetConfig(string $key): mixed {
	return System\Config::getInstance()->unset($key);
}

