/*
This file is part of »zeitbild«.

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

»zeitbild« 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.

»zeitbild« 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 »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
 */


namespace _zeitbild.api
{
	
	/**
	 */
	export function date_type(
		options : {
			nullable ?: boolean;
		} = {}
	) : lib_plankton.rest_http.type_oas_schema
	{
		options = Object.assign(
			{
				"nullable": false,
			},
			options
		);
		return {
			"nullable": options.nullable,
			"type": "object",
			"properties": {
				"year": {
					"nullable": false,
					"type": "integer"
				},
				"month": {
					"nullable": false,
					"type": "integer"
				},
				"day": {
					"nullable": false,
					"type": "integer"
				},
			},
			"required": [
				"year",
				"month",
				"day"
			],
			"additionalProperties": false
		};
	}
	
	
	/**
	 */
	export function time_type(
		options : {
			nullable ?: boolean;
		} = {}
	) : lib_plankton.rest_http.type_oas_schema
	{
		options = Object.assign(
			{
				"nullable": false,
			},
			options
		);
		return {
			"nullable": options.nullable,
			"type": "object",
			"properties": {
				"hour": {
					"nullable": false,
					"type": "integer"
				},
				"minute": {
					"nullable": false,
					"type": "integer"
				},
				"second": {
					"nullable": false,
					"type": "integer"
				},
			},
			"required": [
				"hour",
				"minute",
				"second"
			],
			"additionalProperties": false
		};
	}
	
	
	/**
	 */
	export function datetime_type(
		options : {
			nullable ?: boolean;
		} = {}
	) : lib_plankton.rest_http.type_oas_schema
	{
		options = Object.assign(
			{
				"nullable": false,
			},
			options
		);
		return {
			"nullable": options.nullable,
			"type": "object",
			"properties": {
				"timezone_shift": {
					"nullable": false,
					"type": "integer"
				},
				"date": date_type({"nullable": false}),
				"time": time_type({"nullable": true}),
			},
			"required": [
			],
			"additionalProperties": false
		};
	}
	
	
	
	/**
	 */
	export function access_level_encode(
		access_level : _zeitbild.enum_access_level
	) : string
	{
		switch (access_level) {
			case _zeitbild.enum_access_level.none: {return "none";}
			case _zeitbild.enum_access_level.view: {return "view";}
			case _zeitbild.enum_access_level.edit: {return "edit";}
			case _zeitbild.enum_access_level.admin: {return "admin";}
			default: {throw (new Error("invalid access level: " + String(access_level)));}
		}
	}
	
	
	/**
	 */
	export function access_level_decode(
		access_level_ : string
	) : _zeitbild.enum_access_level
	{
		switch (access_level_) {
			case "none": {return _zeitbild.enum_access_level.none;}
			case "view": {return _zeitbild.enum_access_level.view;}
			case "edit": {return _zeitbild.enum_access_level.edit;}
			case "admin": {return _zeitbild.enum_access_level.admin;}
			default: {throw (new Error("invalid encoded access level: " + String(access_level_)));}
		}
	}
	
}

