/*
This file is part of »dali«.

Copyright 2025 'kcf' <fenris@folksprak.org>

»dali« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

»dali« 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with »dali«. If not, see <http://www.gnu.org/licenses/>.
 */



namespace _dali.conf
{
	
	/**
	 */
	const _schema : lib_plankton.conf.type_schema = {
		"nullable": false,
		"type": "object",
		"properties": {
			"version": {
				"nullable": false,
				"type": "integer",
				"enum": [1]
			},
			"backend": {
				"nullable": false,
				"type": "object",
				"properties": {
					"scheme": {
						"nullable": false,
						"type": "string",
						"default": "http"
					},
					"host": {
						"nullable": false,
						"type": "string",
						"default": "localhost"
					},
					"port": {
						"nullable": false,
						"type": "integer",
						"default": 7845
					},
					"path": {
						"nullable": false,
						"type": "string",
						"default": ""
					}
				},
				"required": [
				],
				"additionalProperties": false,
				"default": {}
			},
			"misc": {
				"nullable": false,
				"type": "object",
				"properties": {
					"oidc_redirect_uri_template": {
						"nullable": true,
						"type": "string",
						"default": "http://localhost:8888/#oidc_finish,session_key={{session_key}}"
					},
					"use_central_europe_specific_datetime_inputs": {
						"nullable": false,
						"type": "boolean",
						"default": false
					},
					"weekview_cell_day_format": {
						"nullable": false,
						"type": "string",
						"default": "d.b",
						"description": "available placeholders: Y,m,b,d,W,w (as in UNIX command 'date')"
					},
				},
				"required": [
				],
				"additionalProperties": false,
				"default": {}
			},
		},
		"required": [
			"version",
		],
		"additionalProperties": false
	};
	
	
	/**
	 */
	type type_data = {
		version : string;
		backend : {
			scheme : string;
			host : string;
			port : int;
			path : string;
		};
		misc : {
			oidc_redirect_uri_template : string;
			use_central_europe_specific_datetime_inputs : string;
			weekview_cell_day_format : string;
		};
	};
	
	
	/**
	 */
	var _data : (null | type_data) = null;
	
	
	/**
	 */
	export function schema(
	) : lib_plankton.conf.type_schema
	{
		return _schema;
	}
	
	
	/**
	 */
	export function get(
	) : type_data
	{
		if (_data === null)
		{
			throw (new Error("conf not loaded yet"));
		}
		else {
			return _data;
		}
	}
	
	
	/**
	 */
	export async function init(
		path : string
	) : Promise<void>
	{
		_data = ((await lib_plankton.conf.load(_schema, path)) as type_data);
		return Promise.resolve<void>(undefined);
	}
	
}
