{
	"$schema": "http://json-schema.org/draft/2020-12/schema#",
	"$id": "events.json",
	"type": "object",
	"$ref": "#/$defs/event",
	"$defs": {
		"event_base": {
			"description": "Base of any event object",
			"type": "object",
			"required": [
				"id",
				"type",
				"date"
			],
			"properties": {
				"id": {
					"$ref": "#/$defs/__uuid"
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"examples": [
						"identification",
						"crossing",
						"har"
					]
				},
				"date": {
					"description": "Timestamp of this event",
					"$ref": "#/$defs/timestamp"
				}
			}
		},
		"object_base": {
			"type": "object",
			"required": [
				"object"
			],
			"properties": {
				"object": {
					"description": "Structure identifying the entity that creates this event",
					"type": "object",
					"properties": {
						"id": {
							"description": "Identifier of an entity",
							"$ref": "#/$defs/__uuid"
						},
						"class": {
							"description": "Class of the said entity",
							"type": "string",
							"examples": [
								"human",
								"face",
								"body"
							]
						}
					},
					"required": [
						"class",
						"id"
					]
				}
			}
		},
		"parents_base": {
			"type": "object",
			"required": [
				"parents"
			],
			"properties": {
				"parents": {
					"description": "Data identifying the event's \"parent\" - usually linked to processes",
					"type": "array",
					"items": {
						"type": "object",
						"required": [
							"id",
							"type"
						],
						"properties": {
							"id": {
								"type": "string",
								"$ref": "#/$defs/__uuid"
							},
							"type": {
								"description": "Type of parent",
								"type": "string",
								"examples": [
									"human",
									"face",
									"body"
								]
							}
						}
					}
				}
			}
		},
		"trigger_source_base": {
			"type": "object",
			"required": [
				"trigger_source"
			],
			"properties": {
				"trigger_source": {
					"description": "Structure identifying the trigger, that has created this event",
					"type": "object",
					"properties": {
						"id": {
							"description": "Identifier of a trigger",
							"$ref": "#/$defs/__uuid"
						}
					},
					"required": [
						"id"
					]
				}
			}
		},
		"event_source_base": {
			"type": "object",
			"required": [
				"source"
			],
			"properties": {
				"source": {
					"description": "Identifier of the stream on which the event has been created",
					"$ref": "#/$defs/__uuid"
				}
			}
		},
		"crop_base": {
			"type": "object",
			"required": [
				"image",
				"image_bbox"
			],
			"properties": {
				"image": {
					"description": "base64 encoded crop of detection on which the event was created",
					"type": "string",
					"contentEncoding": "base64",
					"contentMediaType": "image/jpg"
				},
				"image_bbox": {
					"description": "Normalised coordinates of detection's bounding box (x1, y1, x2, y2)",
					"type": "array",
					"minItems": 4,
					"maxItems": 4,
					"items": {
						"type": "number",
						"examples": [
							0,
							0.2,
							0.4,
							0.6
						]
					}
				},
				"original_image": {
					"description": "base64 encoded source frame on which the event was created",
					"type": "string",
					"contentEncoding": "base64",
					"contentMediaType": "image/jpg"
				}
			}
		},
		"non_identification_event_impl": {
			"type": "object",
			"required": [
				"type",
				"object",
				"parents"
			],
			"properties": {
				"object": {
					"type": "object",
					"properties": {
						"class": {
							"description": "Event object class",
							"type": "string",
							"const": "human"
						}
					}
				},
				"parents": {
					"type": "array",
					"items": {
						"type": "object",
						"required": [
							"type",
							"id"
						],
						"properties": {
							"id": {
								"description": "Identifier of human process that created this event",
								"$ref": "#/$defs/__uuid"
							},
							"type": {
								"type": "string",
								"const": "human"
							}
						}
					}
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"const": "non_identification"
				}
			}
		},
		"non_identification_event": {
			"description": "Event of human being not identified based on Agent's database",
			"type": "object",
			"allOf": [
				{
					"$ref": "#/$defs/non_identification_event_impl"
				},
				{
					"$ref": "#/$defs/event_base"
				},
				{
					"$ref": "#/$defs/parents_base"
				},
				{
					"$ref": "#/$defs/object_base"
				},
				{
					"$ref": "#/$defs/crop_base"
				},
				{
					"$ref": "#/$defs/trigger_source_base"
				},
				{
					"$ref": "#/$defs/event_source_base"
				}
			]
		},
		"identification_event_impl": {
			"type": "object",
			"required": [
				"type",
				"object",
				"parents",
				"identification_data"
			],
			"properties": {
				"object": {
					"type": "object",
					"required": [
						"class"
					],
					"properties": {
						"class": {
							"description": "Event object class",
							"type": "string",
							"const": "human"
						}
					}
				},
				"parents": {
					"type": "array",
					"items": {
						"type": "object",
						"required": [
							"type",
							"id"
						],
						"properties": {
							"id": {
								"description": "Identifier of human process that created this event",
								"$ref": "#/$defs/__uuid"
							},
							"type": {
								"type": "string",
								"const": "human"
							}
						}
					}
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"const": "identification"
				},
				"identification_data": {
					"description": "Array of identified profiles",
					"type": "array",
					"items": {
						"type": "object",
						"required": [
							"profile_id",
							"group_ids",
							"score",
							"far",
							"frr",
							"distance"
						],
						"properties": {
							"profile_id": {
								"description": "Identifier (UUID) of profile",
								"$ref": "#/$defs/__uuid"
							},
							"group_ids": {
								"type": "array",
								"description": "Array of profile group identifers in which current person is found.",
								"items": {
									"$ref": "#/$defs/__uuid"
								}
							},
							"score": {
								"description": "Distance to the found profile",
								"type": "number",
								"examples": [
									0.846,
									0.94856
								]
							},
							"far": {
								"description": "False acceptance rate",
								"type": "number",
								"examples": [
									0.0001,
									0.002
								]
							},
							"frr": {
								"description": "False rejection rate",
								"type": "number",
								"examples": [
									0.0001,
									0.002
								]
							},
							"distance": {
								"description": "Distance to the found profile",
								"type": "number",
								"examples": [
									5065,
									9515
								]
							}
						}
					}
				}
			}
		},
		"identification_event": {
			"description": "Event of human being identified based on Agent's database",
			"type": "object",
			"allOf": [
				{
					"$ref": "#/$defs/identification_event_impl"
				},
				{
					"$ref": "#/$defs/event_base"
				},
				{
					"$ref": "#/$defs/parents_base"
				},
				{
					"$ref": "#/$defs/object_base"
				},
				{
					"$ref": "#/$defs/crop_base"
				},
				{
					"$ref": "#/$defs/trigger_source_base"
				},
				{
					"$ref": "#/$defs/event_source_base"
				}
			]
		},
		"line_crossing_event_impl": {
			"type": "object",
			"required": [
				"parents",
				"type",
				"crossing_data",
				"trigger_source"
			],
			"properties": {
				"parents": {
					"type": "array",
					"minItems": 2,
					"maxItems": 2,
					"items": {
						"oneOf": [
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human process that created this event",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "human"
									}
								}
							},
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human body process that crossed the line",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "body"
									}
								}
							}
						]
					}
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"const": "crossing"
				},
				"crossing_data": {
					"type": "object",
					"required": [
						"direction"
					],
					"properties": {
						"direction": {
							"description": "Direction of line crossing",
							"type": "string",
							"enum": [
								"in",
								"out"
							]
						}
					}
				},
				"trigger_source": {
					"type": "object",
					"required": [
						"id"
					],
					"properties": {
						"id": {
							"description": "Crossed line identifier",
							"$ref": "#/$defs/__uuid"
						}
					}
				}
			}
		},
		"line_crossing_event": {
			"description": "Event of human's body crossing the \"line\" region",
			"type": "object",
			"allOf": [
				{
					"$ref": "#/$defs/line_crossing_event_impl"
				},
				{
					"$ref": "#/$defs/event_base"
				},
				{
					"$ref": "#/$defs/parents_base"
				},
				{
					"$ref": "#/$defs/object_base"
				},
				{
					"$ref": "#/$defs/crop_base"
				},
				{
					"$ref": "#/$defs/trigger_source_base"
				},
				{
					"$ref": "#/$defs/event_source_base"
				}
			]
		},
		"roi_crossing_event_impl": {
			"type": "object",
			"required": [
				"type",
				"trigger_source",
				"parents",
				"roi_data"
			],
			"properties": {
				"parents": {
					"type": "array",
					"minItems": 2,
					"maxItems": 2,
					"items": {
						"oneOf": [
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human process that created this event",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "human"
									}
								}
							},
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human body process that crossed the roi",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "body"
									}
								}
							}
						]
					}
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"const": "roi"
				},
				"roi_data": {
					"type": "object",
					"required": [
						"direction"
					],
					"properties": {
						"direction": {
							"description": "Direction of roi crossing",
							"type": "string",
							"enum": [
								"in",
								"out"
							]
						}
					}
				},
				"trigger_source": {
					"type": "object",
					"required": [
						"id"
					],
					"properties": {
						"id": {
							"description": "Crossed roi identifier",
							"$ref": "#/$defs/__uuid"
						}
					}
				}
			}
		},
		"roi_crossing_event": {
			"description": "Event of human's body crossing the ROI",
			"type": "object",
			"allOf": [
				{
					"$ref": "#/$defs/roi_crossing_event_impl"
				},
				{
					"$ref": "#/$defs/event_base"
				},
				{
					"$ref": "#/$defs/parents_base"
				},
				{
					"$ref": "#/$defs/object_base"
				},
				{
					"$ref": "#/$defs/crop_base"
				},
				{
					"$ref": "#/$defs/trigger_source_base"
				},
				{
					"$ref": "#/$defs/event_source_base"
				}
			]
		},
		"har_event_impl": {
			"type": "object",
			"required": [
				"parents",
				"type",
				"har_data"
			],
			"properties": {
				"parents": {
					"type": "array",
					"minItems": 2,
					"maxItems": 2,
					"items": {
						"oneOf": [
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human process that created this event",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "human"
									}
								}
							},
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human body process that performed the action",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "body"
									}
								}
							}
						]
					}
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"const": "har"
				},
				"har_data": {
					"type": "object",
					"required": [
						"action"
					],
					"properties": {
						"action": {
							"description": "Name of performed action",
							"type": "string",
							"enum": [
								"fall",
								"sit",
								"lie",
								"fight"
							]
						}
					}
				}
			}
		},
		"har_event": {
			"description": "Human action recognition",
			"type": "object",
			"allOf": [
				{
					"$ref": "#/$defs/har_event_impl"
				},
				{
					"$ref": "#/$defs/event_base"
				},
				{
					"$ref": "#/$defs/parents_base"
				},
				{
					"$ref": "#/$defs/object_base"
				},
				{
					"$ref": "#/$defs/crop_base"
				},
				{
					"$ref": "#/$defs/trigger_source_base"
				},
				{
					"$ref": "#/$defs/event_source_base"
				}
			]
		},
		"face_hide_control_impl": {
			"type": "object",
			"required": [
				"type",
				"parents",
				"face_hide_control_data"
			],
			"properties": {
				"parents": {
					"type": "array",
					"minItems": 2,
					"maxItems": 2,
					"items": {
						"oneOf": [
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human process that created this event",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "human"
									}
								}
							},
							{
								"type": "object",
								"required": [
									"type",
									"id"
								],
								"properties": {
									"id": {
										"description": "Identifier of human body process that crossed the selection region",
										"$ref": "#/$defs/__uuid"
									},
									"type": {
										"type": "string",
										"const": "body"
									}
								}
							}
						]
					}
				},
				"type": {
					"description": "Event type",
					"type": "string",
					"const": "face_hide_control"
				},
				"face_hide_control_data": {
					"type": "object",
					"required": [
						"no_suitable_face",
						"status",
						"match_event_id",
						"profile_id",
						"group_ids"
					],
					"properties": {
						"no_suitable_face": {
							"description": "Flag describing whether there was a face detection worth trying to search in database",
							"type": "boolean"
						},
						"status": {
							"description": "Status of the control check",
							"type": "string",
							"enum": [
								"non_identification",
								"hidden_or_low_quality",
								"identification"
							]
						},
						"match_event_id": {
							"description": "Identifier of person identification event or null",
							"oneOf": [
								{
									"type": "null"
								},
								{
									"$ref": "#/$defs/__uuid"
								}
							]
						},
						"profile_id": {
							"description": "Identifier of matched profile or null",
							"oneOf": [
								{
									"type": "null"
								},
								{
									"$ref": "#/$defs/__uuid"
								}
							]
						},
						"group_ids": {
							"description": "List of profile groups for match event or null",
							"oneOf": [
								{
									"type": "null"
								},
								{
									"type": "array",
									"description": "Array of profile group identifers in which current person is found.",
									"items": {
										"$ref": "#/$defs/__uuid"
									}
								}
							]
						}
					}
				}
			}
		},
		"face_hide_control": {
			"description": "Face hide control",
			"type": "object",
			"allOf": [
				{
					"$ref": "#/$defs/face_hide_control_impl"
				},
				{
					"$ref": "#/$defs/event_base"
				},
				{
					"$ref": "#/$defs/parents_base"
				},
				{
					"$ref": "#/$defs/object_base"
				},
				{
					"$ref": "#/$defs/crop_base"
				},
				{
					"$ref": "#/$defs/trigger_source_base"
				},
				{
					"$ref": "#/$defs/event_source_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"
		},
		"event": {
			"anyOf": [
				{
					"$ref": "#/$defs/identification_event"
				},
				{
					"$ref": "#/$defs/non_identification_event"
				},
				{
					"$ref": "#/$defs/line_crossing_event"
				},
				{
					"$ref": "#/$defs/roi_crossing_event"
				},
				{
					"$ref": "#/$defs/har_event"
				},
				{
					"$ref": "#/$defs/face_hide_control"
				}
			]
		}
	}
}