{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://docs.bernard-gruppe.com/events/schema/6.0",
    "title": "Bernard Event Schema",
    "definitions": {
        "id": {
            "type": "string",
            "examples": [
                "56317209-9B83-43A6-A63E-58C9191A7869"
            ]
        },
        "tenantId": {
            "type": "string",
            "examples": [
                "12347209-9B83-43A6-A63E-58C9191A7869"
            ]
        },
        "node": {
            "type": "object",
            "properties": {
                "id": {
                    "$ref": "#/definitions/id"
                },
                "name": {
                    "type": "string"
                },
                "metadata": {
                    "$ref": "#/definitions/metadata"
                }
            },
            "required": [
                "id",
                "name"
            ]
        },
        "stream": {
            "type": "object",
            "properties": {
                "id": {
                    "$ref": "#/definitions/id"
                },
                "name": {
                    "type": "string"
                },
                "geoLocation": {
                    "$ref": "#/definitions/geoLocation"
                }
            },
            "required": [
                "id",
                "name"
            ]
        },
        "metadata": {
            "type": "object",
            "additionalProperties": {
                "type": "string"
            }
        },
        "geoLocation": {
            "type": "object",
            "required": [
                "coordinates"
            ],
            "properties": {
                "coordinates": {
                    "type": "array",
                    "minItems": 2,
                    "items": {
                        "type": "number"
                    }
                }
            }
        },
        "journeyTimeInformation": {
            "type": "object",
            "properties": {
                "saltId": {
                    "type": "string",
                    "format": "uuid"
                },
                "hash": {
                    "type": "string",
                    "minLength": 64,
                    "maxLength": 64
                },
                "validFrom": {
                    "type": "string",
                    "format": "date-time"
                },
                "validUntil": {
                    "type": "string",
                    "format": "date-time"
                },
                "parkingJourney": {
                    "type": "boolean"
                }
            },
            "required": [
                "saltId",
                "hash",
                "validFrom",
                "validUntil"
            ]
        },
        "ruleEvents": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "regionOfInterestEvent": {
                        "$ref": "#/definitions/regionOfInterestEvent"
                    },
                    "parkingEvent": {
                        "$ref": "#/definitions/parkingEvent"
                    },
                    "crossingLineEvent": {
                        "$ref": "#/definitions/crossingLineEvent"
                    },
                    "virtualDoorEvent": {
                        "$ref": "#/definitions/virtualDoorEvent"
                    },
                    "originDestinationEvent": {
                        "$ref": "#/definitions/originDestinationEvent"
                    }
                },
                "oneOf": [
                    {
                        "required": [
                            "regionOfInterestEvent"
                        ]
                    },
                    {
                        "required": [
                            "parkingEvent"
                        ]
                    },
                    {
                        "required": [
                            "crossingLineEvent"
                        ]
                    },
                    {
                        "required": [
                            "virtualDoorEvent"
                        ]
                    },
                    {
                        "required": [
                            "originDestinationEvent"
                        ]
                    }
                ]
            }
        },
        "heatmapEvent": {
            "type": "object",
            "properties": {
                "class": {
                    "type": "string"
                },
                "subClass": {
                    "type": "string"
                },
                "trackId": {
                    "type": "number"
                },
                "trackUuid": {
                    "$ref": "#/definitions/id"
                },
                "path": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "x": {
                                "type": "number"
                            },
                            "y": {
                                "type": "number"
                            },
                            "w": {
                                "type": "number"
                            },
                            "h": {
                                "type": "number"
                            },
                            "timestamp": {
                                "type": "string",
                                "format": "date-time"
                            }
                        },
                        "required": [
                            "x",
                            "y",
                            "w",
                            "h",
                            "timestamp"
                        ]
                    }
                }
            },
            "required": [
                "class",
                "path"
            ]
        },
        "virtualDoorEvent": {
            "type": "object",
            "properties": {
                "virtualDoorId": {
                    "$ref": "#/definitions/id"
                },
                "virtualDoorName": {
                    "type": "string"
                },
                "direction": {
                    "type": "string",
                    "enum": [
                        "in",
                        "out"
                    ]
                },
                "timestamp": {
                    "type": "string",
                    "format": "date-time"
                },
                "trackId": {
                    "type": "number"
                },
                "trackUuid": {
                    "$ref": "#/definitions/id"
                },
                "object": {
                    "type": "object",
                    "properties": {
                        "class": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "class"
                    ]
                }
            },
            "required": [
                "virtualDoorId",
                "virtualDoorName",
                "timestamp",
                "direction",
                "object"
            ]
        },
        "regionOfInterestEvent": {
            "type": "object",
            "properties": {
                "roiId": {
                    "$ref": "#/definitions/id"
                },
                "roiName": {
                    "type": "string"
                },
                "triggerType": {
                    "enum": [
                        "time",
                        "change"
                    ]
                },
                "capacity": {
                    "type": "number"
                },
                "timestamp": {
                    "type": "string",
                    "format": "date-time"
                },
                "state": {
                    "type": "string",
                    "enum": [
                        "occupied",
                        "vacant"
                    ]
                },
                "objects": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "class": {
                                "type": "string"
                            },
                            "trackId": {
                                "type": "number"
                            },
                            "dwellTime": {
                                "type": "number"
                            },
                            "subClass":
                            {
                                "type": "string"
                            },
                            "trackUuid": {
                                "$ref": "#/definitions/id"
                            },
                            "numberPlate":
                            {
                                "type": "string"
                            },
                            "numberPlateOrigin":
                            {
                                "type": "string"
                            },
                            "numberPlateArea":
                            {
                                "type": "string"
                            },
                            "numberPlateLines": {
                                "type": "integer"
                            },
                            "numberPlateRect": {
                                "$ref": "#/definitions/numberPlateRectangle"
                            },
                            "vehicleRect": {
                                "$ref": "#/definitions/rectangle"
                            },
                            "numberPlateImage": {
                                "type": "string",
                                "contentEncoding": "base64",
                                "contentMediaType": "image/jpeg"
                            }
                        },
                        "required": [
                            "class"
                        ]
                    }
                }
            },
            "required": [
                "roiId",
                "roiName",
                "triggerType",
                "timestamp",
                "state",
                "objects"
            ]
        },
        "parkingEvent": {
            "type": "object",
            "properties": {
                "parkingSummary": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "roiId": {
                                "$ref": "#/definitions/id"
                            },
                            "roiName": {
                                "type": "string"
                            },
                            "capacity": {
                                "type": "number"
                            },
                            "vehicles": {
                                "type": "number"
                            },
                            "numberPlates": {
                                "type": "array",
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "numberPlate": {
                                            "type": "string"
                                        },
                                        "numberPlateOrigin": {
                                            "type": "string"
                                        },
                                        "numberPlateArea": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        },
                        "required": [
                            "roiId",
                            "roiName",
                            "capacity",
                            "vehicles"
                        ]
                    }
                },
                "timestamp": {
                    "type": "string",
                    "format": "date-time"
                },
                "totalCapacity": {
                    "type": "number"
                },
                "totalVehicles": {
                    "type": "number"
                }
            },
            "required": [
                "timestamp",
                "parkingSummary"
            ]
        },
        "crossingLineEvent": {
            "type": "object",
            "properties": {
                "lineId": {
                    "$ref": "#/definitions/id"
                },
                "lineName": {
                    "type": "string"
                },
                "class": {
                    "type": "string"
                },
                "subClass": {
                    "type": "string"
                },
                "direction": {
                    "type": "string",
                    "enum": [
                        "in",
                        "out"
                    ]
                },
                "directionName": {
                    "type": "string"
                },
                "trackId": {
                    "type": "number"
                },
                "trackUuid": {
                    "$ref": "#/definitions/id"
                },
                "speedestimate": {
                    "type": "string"
                },
                "numberPlate": {
                    "type": "string"
                },
                "numberPlateOrigin": {
                    "type": "string"
                },
                "numberPlateArea": {
                    "type": "string"
                },
                "numberPlateLines": {
                    "type": "integer"
                },
                "numberPlateImage": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "contentMediaType": "image/jpeg"
                },
                "journeyTimePrimaryTag": {
                    "$ref": "#/definitions/journeyTimeInformation"
                },
                "journeyTimeSecondaryTag": {
                    "$ref": "#/definitions/journeyTimeInformation"
                },
                "timestamp": {
                    "type": "string",
                    "format": "date-time"
                },
                "path": {
                    "$ref": "#/definitions/originDestinationEvent/properties/movementPath"
                },
                "numberPlateRect": {
                    "$ref": "#/definitions/numberPlateRectangle"
                },
                "vehicleRect": {
                    "$ref": "#/definitions/rectangle"
                }
            },
            "required": [
                "class",
                "lineId",
                "lineName",
                "direction",
                "timestamp"
            ]
        },
        "rectangle": {
            "type": "object",
            "properties": {
                "x": {
                    "type": "number"
                },
                "y": {
                    "type": "number"
                },
                "h": {
                    "type": "number"
                },
                "w": {
                    "type": "number"
                }
            },
            "required": [
                "x",
                "y",
                "h",
                "w"
            ]
        },
        "numberPlateRectangle": {
            "allOf": [
                {
                    "$ref": "#/definitions/rectangle"
                },
                {
                    "type": "object"
                }
            ]
        },
        "zone": {
            "type": "object",
            "properties": {
                "zoneId": {
                    "$ref": "#/definitions/id"
                },
                "name": {
                    "type": "string"
                }
            },
            "required": [
                "zoneId"
            ]
        },
        "originDestinationEvent": {
            "properties": {
                "classification": {
                    "type": "string"
                },
                "subClass": {
                    "type": "string"
                },
                "entry": {
                    "properties": {
                        "zone": {
                            "$ref": "#/definitions/zone"
                        },
                        "timestamp": {
                            "type": "string",
                            "format": "date-time"
                        }
                    },
                    "required": [
                        "zone",
                        "timestamp"
                    ]
                },
                "exit": {
                    "properties": {
                        "zone": {
                            "$ref": "#/definitions/zone"
                        },
                        "timestamp": {
                            "type": "string",
                            "format": "date-time"
                        }
                    },
                    "required": [
                        "zone",
                        "timestamp"
                    ]
                },
                "trackId": {
                    "type": "number"
                },
                "trackUuid": {
                    "$ref": "#/definitions/id"
                },
                "movementPath": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "timestamp": {
                                "type": "string",
                                "format": "date-time"
                            },
                            "x": {
                                "type": "number"
                            },
                            "y": {
                                "type": "number"
                            },
                            "w": {
                                "type": "number"
                            },
                            "h": {
                                "type": "number"
                            }
                        },
                        "required": [
                            "x",
                            "y",
                            "w",
                            "h",
                            "timestamp"
                        ]
                    }
                }
            },
            "required": [
                "classification",
                "entry",
                "exit",
                "movementPath",
                "trackId"
            ]
        }
    },
    "type": "object",
    "properties": {
        "version": {
            "type": "string",
            "const": "6.0"
        },
        "eventSchema": {
            "type": "string"
        },
        "node": {
            "$ref": "#/definitions/node"
        },
        "uuid": {
            "type": "string",
            "format": "uuid",
            "examples": [
                "12347209-9B83-43A6-A63E-58C9191A7869"
            ]
        },
        "tenantId": {
            "type": "string",
            "format": "uuid",
            "examples": [
                "12347209-9B83-43A6-A63E-58C9191A7869"
            ]
        },
        "stream": {
            "$ref": "#/definitions/stream"
        },
        "ruleId": {
            "type": "string"
        },
        "ruleName": {
            "type": "string"
        },
        "timestamp": {
            "type": "string",
            "format": "date-time"
        },
        "regionOfInterestEvent": {
            "$ref": "#/definitions/regionOfInterestEvent"
        },
        "parkingEvent": {
            "$ref": "#/definitions/parkingEvent"
        },
        "crossingLineEvent": {
            "$ref": "#/definitions/crossingLineEvent"
        },
        "virtualDoorEvent": {
            "$ref": "#/definitions/virtualDoorEvent"
        },
        "originDestinationEvent": {
            "$ref": "#/definitions/originDestinationEvent"
        },
        "heatmapEvent": {
            "$ref": "#/definitions/heatmapEvent"
        },
        "ruleEvents": {
            "$ref": "#/definitions/ruleEvents"
        }
    },
    "required": [
        "uuid",
        "version",
        "eventSchema",
        "node",
        "stream"
    ],
    "oneOf": [
        {
            "required": [
                "regionOfInterestEvent"
            ]
        },
        {
            "required": [
                "parkingEvent"
            ]
        },
        {
            "required": [
                "crossingLineEvent"
            ]
        },
        {
            "required": [
                "heatmapEvent"
            ]
        },
        {
            "required": [
                "virtualDoorEvent"
            ]
        },
        {
            "required": [
                "originDestinationEvent"
            ]
        },
        {
            "required": [
                "ruleEvents"
            ]
        }
    ],
    "additionalProperties": false
}
