{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "https://schema.stfform.at/stf.schema.json",
	"title": "STF Definition",
	"description": "The JSON definition of an STF file",

	"type": "object",
	"properties": {
		"stf": {
			"type": "object",
			"properties": {
				"version": {
					"type": "array",
					"items": {
						"type": "integer",
						"minimum": 0
					},
					"minItems": 2,
					"maxItems": 2,
					"description": "Semantic version of the STF definition as an array of integers. e.g. [1, 0] for version 1.0"
				},
				"root": {
					"type": "string",
					"minLength": 1,
					"description": "The key of the root \"resources\" object"
				},
				"asset_info": {
					"type": "object",
					"properties": {
						"asset_name": { "type": "string" },
						"version": { "type": "string" },
						"url": { "type": "string" },
						"author": { "type": "string" },
						"license": { "type": "string" },
						"license_url": { "type": "string" },
						"documentation_url": { "type": "string" }
					},
					"description": "Meta-properties such as authorship and license"
				},
				"asset_properties": {
					"type": "object",
					"patternProperties": {
						".+": {
							"anyOf": [
								{ "type": "string" },
								{ "type": "null" }
							]
						}
					},
					"additionalProperties": false,
					"description": "Additional user defined meta-properties"
				},
				"generator": {
					"type": "string",
					"description": "The application or tool that created the STF file"
				},
				"generator_version": {
					"type": "string",
					"description": "The version of the application or tool that created the STF file"
				},
				"timestamp": {
					"type": "string"
				},
				"metric_multiplier": {
					"type": "number",
					"default": 1,
					"exclusiveMinimum": 0,
					"description": "The number that represents one meter"
				}
			},
			"required": [
				"version",
				"root"
			]
		},
		"resources": {
			"type": "object",
			"patternProperties": {
				".+": {
					"allOf": [
						{ "$ref": "#/$defs/stf_data_resource" },
						{ "$ref": "#/$defs/stf_node_resource" },
						{ "$ref": "#/$defs/stf_instance_resource" },
						{ "$ref": "#/$defs/stf_component_resource" }
					],
					"description": "This is using `allOf` the stf_resource subtypes, since all their keys are reserved."
				}
			},
			"minProperties": 1,
			"additionalProperties": false,
			"description": "STF resources, must contain at least the one resource, whose key is specified in stf/root"
		},
		"buffers": {
			"type": "object",
			"patternProperties": {
				".+": {
					"type": "object",
					"properties": {
						"type": {
							"const": "stf.buffer.included",
							"description": "The only supported buffer type is `stf.buffer.included` for now."
						},
						"index": {
							"type": "integer",
							"minimum": 0,
							"description": "Index of the buffer in the STF file. See the binary file schema: https://schema.stfform.at/stf.ksy"
						}
					},
					"required": [
						"type",
						"index"
					]
				}
			},
			"additionalProperties": false,
			"description": "Each buffer object defines access to arbitrary binary data"
		}
	},
	"required": [
		"stf",
		"resources",
		"buffers"
	],
	"additionalProperties": false,

	"$defs": {
		"stf_resource": {
			"title": "STF Resource Base",
			"description": "Schema for all STF resources must extend",
			"type": "object",
			"properties": {
				"type": {
					"type": "string",
					"minLength": 1,
					"examples": [
						"stf.prefab",
						"stf.node",
						"stf.mesh",
						"stf.instance.mesh"
					],
					"description": "The type identifies which schema should be used to parse any further properties"
				},
				"name": {
					"anyOf": [
						{ "type": "string" },
						{ "type": "null" }
					]
				},
				"referenced_resources": {
					"type": "array",
					"items": {
						"type": "string",
						"minLength": 1
					},
					"description": "Each entry must be a key in the stf/resources object"
				},
				"referenced_buffers": {
					"type": "array",
					"items": {
						"type": "string",
						"minLength": 1
					},
					"description": "Each entry must be a key in the stf/buffers object"
				}
			},
			"required": [
				"type"
			]
		},
		"stf_data_resource": {
			"title": "STF Data Resource",
			"description": "",
			"allOf": [{ "$ref": "#/$defs/stf_resource" }],
			"properties": {
				"fallback": {
					"type": "integer",
					"minimum": 0,
					"description": "Index of an ID in the `referenced_resources` array."
				},
				"components": {
					"type": "array",
					"items": {
						"type": "string",
						"minLength": 1
					},
					"description": "Each entry must be a key in the /stf/resources object."
				}
			}
		},
		"stf_node_resource": {
			"title": "STF Node Resource",
			"description": "",
			"allOf": [{ "$ref": "#/$defs/stf_resource" }],
			"properties": {
				"children": {
					"type": "array",
					"items": {
						"type": "integer",
						"minimum": 0,
						"description": "Index of an ID in the `referenced_resources` array."
					}
				},
				"components": {
					"type": "array",
					"items": {
						"type": "string",
						"minLength": 1
					},
					"description": "Each entry must be a key in the /stf/resources object"
				}
			}
		},
		"stf_instance_resource": {
			"title": "STF Instance Resource",
			"description": "",
			"allOf": [{ "$ref": "#/$defs/stf_resource" }],
			"properties": {
				"enabled": {
					"type": "boolean",
					"default": true
				}
			}
		},
		"stf_component_resource": {
			"title": "STF Component Resource",
			"description": "",
			"allOf": [{ "$ref": "#/$defs/stf_resource" }],
			"properties": {
				"enabled": {
					"type": "boolean",
					"default": true
				},
				"exclusion_group": {
					"type": "string",
					"minLength": 1
				}
			}
		}
	}
}