{
	"$schema":"http://json-schema.org/draft/2020-12/schema#",
	"$id":"processes.json",
	"type":"object",
	"properties":{
		"processes":{
			"type":"array",
			"items":{
				"$ref":"#/$defs/process"
			}
		}
	},
	"$defs":{
		"process_base":{
			"description":"Base of any process object",
			"type":"object",
			"required":[
				"id",
				"type"
			],
			"properties":{
				"id":{
					"$ref":"#/$defs/__uuid"
				},
				"type":{
					"description":"Process type",
					"type":"string",
					"examples":[
						"track",
						"emotion",
						"action"
					]
				},
				"time_interval":{
					"description":"Begin and end timestamps of the process",
					"type":"array",
					"minItems":2,
					"maxItems":2,
					"items":{
						"$ref":"#/$defs/timestamp"
					}
				},
				"frame_interval":{
					"description":"Begin and end frame number of the process",
					"type":"array",
					"minItems":2,
					"maxItems":2,
					"items":{
						"$ref":"#/$defs/positive_integer"
					}
				},
				"finalized":{
					"type":"boolean"
				}
			}
		},
		"object_base":{
			"type":"object",
			"required":[
				"object"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the source creating the process",
					"type":"object",
					"properties":{
						"id":{
							"$ref":"#/$defs/__uuid"
						},
						"class":{
							"type":"string",
							"examples":[
								"human",
								"face",
								"body"
							]
						}
					},
					"required":[
						"class",
						"id"
					]
				}
			}
		},
		"child_process_base":{
			"type":"object",
			"required":[
				"parent"
			],
			"properties":{
				"parent":{
					"description":"Identifier of parent's process",
					"type":"string",
					"$ref":"#/$defs/__uuid"
				}
			}
		},
		"numerical_base":{
			"type":"object",
			"required":[
				"numerical_id"
			],
			"properties":{
				"numerical_id":{
					"description":"Numerical (internal) identifier of process.",
					"type":"integer"
				}
			}
		},
		"object_source_base":{
			"type":"object",
			"required":[
				"object"
			],
			"properties":{
				"object":{
					"type":"object",
					"properties":{
						"source":{
							"type":"string",
							"description":"Structure identifying the source creating the process"
						}
					},
					"required":[
						"source"
					]
				}
			}
		},
		"process_source_base":{
			"type":"object",
			"properties":{
				"source":{
					"type":"string",
					"description":"Structure identifying the source creating the process"
				}
			},
			"required":[
				"source"
			]
		},
		"crop_base_base64":{
			"type":"object",
			"properties":{
				"best_shot":{
					"type":"string",
					"contentEncoding":"base64",
					"contentMediaType":"image/jpg",
					"note":"best shot might not be included"
				}
			}
		},
		"crop_base_binary":{
			"type":"object",
			"properties":{
				"$best_shot":{
					"$ref":"#/$defs/__bsm",
					"note":"best shot might not be included"
				}
			}
		},
		"__bsm":{
			"description":"Binary sample with meta",
			"type":"object",
			"properties":{
				"blob":{
					"type":"string",
					"contentEncoding":"base64"
				},
				"format":{
					"type":"string",
					"description":"",
					"examples": ["NDARRAY"]
				},
				"dtype":{
					"$ref":"#/$defs/__dtype"
				},
				"shape":{
					"type":"array",
					"items":{
						"type":"integer"
					},
					"description":"Shape of the binary sample"
				},
				"color_format":{
					"enum":[
						"GRAY",
						"RGB",
						"BGR",
						"YUV_NV21",
						"YUV_NV12"
					]
				}
			},
			"required":[
				"blob",
				"format",
				"dtype",
				"shape"
			],
			"optional":[
				"color_format"
			]
		},
		"process_base_track_impl":{
			"type":"object",
			"required":[
				"type"
			],
			"properties":{
				"type":{
					"description":"Process type",
					"type":"string",
					"const":"track"
				}
			}
		},
		"process_base_track":{
			"allOf":[
				{
					"$ref":"#/$defs/process_base_track_impl"
				},
				{
					"$ref":"#/$defs/process_base"
				}
			]
		},
		"process_base_action_impl":{
			"type":"object",
			"required":[
				"type"
			],
			"properties":{
				"type":{
					"description":"Process type",
					"type":"string",
					"const":"action"
				},
				"action":{
					"type":"string",
					"examples":[
						"fall",
						"roi_presence"
					]
				}
			}
		},
		"process_base_action":{
			"allOf":[
				{
					"$ref":"#/$defs/process_base_action_impl"
				},
				{
					"$ref":"#/$defs/process_base"
				}
			]
		},
		"human_process_impl":{
			"type":"object",
			"required":[
				"object"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the human creating the process",
					"type":"object",
					"properties":{
						"class":{
							"type":"string",
							"const":"human"
						},
						"match_data":{
							"type":"object",
							"description":"",
							"properties":{
								"profileGroups":{
									"type":"array",
									"description":"Array of group identifers in which current person is found.",
									"items":{
										"$ref":"#/$defs/__uuid"
									}
								},
								"distance":{
									"type":"number"
								},
								"fr_r":{
									"type":"number"
								},
								"fa_r":{
									"type":"number"
								},
								"score":{
									"type":"number"
								}
							}
						}
					},
					"required":[
						"class"
					],
					"optional":[
						"match_data"
					]
				}
			}
		},
		"human_process":{
			"description":"Process of human",
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/human_process_impl"
				},
				{
					"$ref":"#/$defs/process_source_base"
				},
				{
					"$ref":"#/$defs/process_base_track"
				},
				{
					"$ref":"#/$defs/object_base"
				}
			]
		},
		"face_process_impl":{
			"type":"object",
			"required":[
				"object"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the face creating the process",
					"type":"object",
					"properties":{
						"age":{
							"$ref":"#/$defs/positive_integer"
						},
						"gender":{
							"enum":[
								"MALE",
								"FEMALE",
								"UNKNOWN"
							]
						},
						"quality": {
							"type":"number"
						},
						"class":{
							"type":"string",
							"const":"face"
						}
					},
					"required":[
						"class"
					],
					"optional":[
						"age",
						"gender",
						"quality"
					]
				}
			}
		},
		"face_process":{
			"description":"Process of face",
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/face_process_impl"
				},
				{
					"$ref":"#/$defs/process_base_track"
				},
				{
					"$ref":"#/$defs/object_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				},
				{
					"anyOf":[
						{
							"$ref":"#/$defs/crop_base_base64"
						},
						{
							"$ref":"#/$defs/crop_base_binary"
						}
					]
				}
			]
		},
		"body_process_impl":{
			"type":"object",
			"required":[
				"object"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the body creating the process",
					"type":"object",
					"properties":{
						"class":{
							"type":"string",
							"const":"body"
						},
						"bbox":{
							"description":"Latest position of this body",
							"type":"array",
							"items": {
								"type": "number"
							},
							"minItems":4,
							"maxItems":4
						},
						"score":{
							"description":"Latest score of this body detection",
							"type":"number"
						}
					},
					"required":[
						"class"
					]
				}
			}
		},
		"body_process":{
			"description":"Process of body",
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/body_process_impl"
				},
				{
					"$ref":"#/$defs/process_base_track"
				},
				{
					"$ref":"#/$defs/object_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				},
				{
					"anyOf":[
						{
							"$ref":"#/$defs/crop_base_base64"
						},
						{
							"$ref":"#/$defs/crop_base_binary"
						}
					]
				}
			]
		},
		"emotion_process_impl":{
			"type":"object",
			"required":[
				"emotion",
				"type"
			],
			"properties":{
				"emotion":{
					"type":"string"
				},
				"type":{
					"type":"string",
					"const":"emotion"
				}
			}
		},
		"emotion_process":{
			"description":"Process of emotion",
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/emotion_process_impl"
				},
				{
					"$ref":"#/$defs/process_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				}
			]
		},
		"attention_process_impl":{
			"type":"object",
			"required":[
				"type"
			],
			"properties":{
				"type":{
					"type":"string",
					"const":"attention"
				}
			}
		},
		"attention_process":{
			"description":"Process of attention",
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/attention_process_impl"
				},
				{
					"$ref":"#/$defs/process_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				}
			]
		},
		"presence_process_impl":{
			"type":"object",
			"required":[
				"object", "type", "action"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the roi",
					"type":"object",
					"properties":{
						"class":{
							"type":"string",
							"const":"roi"
						},
						"name":{
							"type":"string"
						}
					},
					"required":[
						"class",
						"name"
					]
				},
				"type":{
					"type":"string",
					"const":"action"
				},
				"action":{
					"type":"string",
					"const":"roi_presence"
				}
			}
		},
		"presence_process":{
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/presence_process_impl"
				},
				{
					"$ref":"#/$defs/process_base_action"
				},
				{
					"$ref":"#/$defs/object_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				}
			]
		},
		"trigger_crossing_process_impl":{
			"type":"object",
			"required":[
				"object", "type", "action", "direction"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the trigger",
					"type":"object",
					"properties":{
						"class":{
							"type":"string",
							"const":"trigger"
						},
						"name":{
							"type":"string"
						}
					},
					"required":[
						"class",
						"name"
					]
				},
				"type":{
					"type":"string",
					"const":"action"
				},
				"action":{
					"type":"string",
					"const":"trigger_crossing"
				},
				"direction":{
					"enum":[
						"in",
						"out"
					]
				}
			}
		},
		"trigger_crossing_process":{
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/trigger_crossing_process_impl"
				},
				{
					"$ref":"#/$defs/process_base_action"
				},
				{
					"$ref":"#/$defs/object_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				}
			]
		},
		"action_recognition_process_impl":{
			"type":"object",
			"required":[
				"type", "action"
			],
			"properties":{
				"type":{
					"type":"string"
				},
				"action":{
					"type":"string"
				}
			}
		},
		"action_recognition_process":{
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/action_recognition_process_impl"
				},
				{
					"$ref":"#/$defs/process_base_action"
				},
				{
					"$ref":"#/$defs/child_process_base"
				}
			]
		},
		"external_process_impl":{
			"type":"object",
			"required":[
				"object", "repeats", "duration", "internal_time_interval"
			],
			"properties":{
				"object":{
					"description":"Structure identifying the trigger",
					"type":"object",
					"properties":{
						"name":{
							"type":"string"
						},
						"class":{
							"type":"string",
							"examples": [
								"media"
							]
						}
					},
					"required":[
						"class",
						"name"
					]
				},
				"type": {
					"type": "string",
					"const": "external"
				},
				"repeats":{
					"type":"boolean"
				},
				"duration":{
					"type":"integer"
				},
				"internal_time_interval":{
					"description": "Internal time interval of an external process (media)",
					"type":"array",
					"minItems":2,
					"maxItems":2,
					"items":{
						"$ref":"#/$defs/positive_integer"
					}
				}
			}
		},
		"external_process":{
			"type":"object",
			"allOf":[
				{
					"$ref":"#/$defs/external_process_impl"
				},
				{
					"$ref":"#/$defs/process_base_action"
				},
				{
					"$ref":"#/$defs/object_base"
				},
				{
					"$ref":"#/$defs/child_process_base"
				}
			]
		},
		"__uuid":{
			"description":"Process UUID",
			"type":"string",
			"pattern":"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
		},
		"timestamp":{
			"description":"Timestamp, ISO8601 format",
			"type":"string",
			"format":"date-time"
		},
		"positive_integer":{
			"description":"Positive integer value",
			"type":"integer",
			"minimum":0
		},
		"__dtype":{
			"enum":[
				"uint8_t",
				"int8_t",
				"uint16_t",
				"int16_t",
				"int32_t",
				"float",
				"double"
			]
		},
		"process":{
			"anyOf":[
				{
					"$ref":"#/$defs/human_process"
				},
				{
					"$ref":"#/$defs/external_process"
				},
				{
					"$ref":"#/$defs/face_process"
				},
				{
					"$ref":"#/$defs/body_process"
				},
				{
					"$ref":"#/$defs/attention_process"
				},
				{
					"$ref":"#/$defs/emotion_process"
				},
				{
					"$ref":"#/$defs/trigger_crossing_process"
				},
				{
					"$ref":"#/$defs/action_recognition_process"
				},
				{
					"$ref":"#/$defs/presence_process"
				}
			]
		}
	}
}
