{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Scheduling Block Instance (SBI)",
    "description": "Schema for a SIP interpretation of an SKA SBI",
    "version": "1.0.0",
    "type": "object",
    "required": [
        "id",
        "version",
        "scheduling_block",
        "processing_blocks"
    ],
    "properties": {
        "id": {
            "description": "Primary SBI Id, SBI-[date]-[project]-*",
            "type": "string",
            "pattern": "^SBI-[0-9]{8}-[a-z|A-Z]+-.*$"
        },
        "version": {
            "description": "SBI configuration version",
            "type": "string",
            "pattern": "[0-9]{1,4}.[0-9]{1,4}.[0-9]{1,4}"
        },
        "scheduling_block": {
            "description": "Scheduling Block properties",
            "$ref": "#/definitions/scheduling_block"
        },
        "processing_blocks": {
            "description": "Array of PBs defined for this SBI",
            "type": "array",
            "items": {
                "description": "PB configuration",
                "$ref": "#/definitions/processing_block"
            }
        },
        "scans": {
            "description": "Array of Scans assocaited with this SBI",
            "type": "array",
            "items": {
                "description": "Scan configuration object",
                "type": "object"
            }
        }
    },
    "definitions": {
        "scheduling_block": {
            "type": "object",
            "required": [
                "id"
            ],
            "properties": {
                "id": {
                    "description": "SB Id",
                    "type": "string"
                },
                "project": {
                    "description": "Project Id",
                    "type": "string"
                },
                "telescope": {
                    "description": "Telescope Id",
                    "type": "string"
                },
                "programme_block": {
                    "description": "Programme block Id",
                    "type": "string"
                }
            }
        },
        "processing_block": {
            "type": "object",
            "required": [
                "id",
                "version",
                "type",
                "workflow"
            ],
            "properties": {
                "id": {
                    "description": "Primary PB Id, PB-[date]-[project]-*",
                    "type": "string",
                    "pattern": "^PB-[0-9]{8}-[a-z|A-Z]+-.*$"
                },
                "version": {
                    "description": "PB configuration version",
                    "type": "string",
                    "pattern": "[0-9]{1,4}.[0-9]{1,4}.[0-9]{1,4}"
                },
                "type": {
                    "description": "[realtime, offline]",
                    "enum": [
                        "realtime",
                        "offline"
                    ]
                },
                "workflow": {
                    "description": "PB workflow description",
                    "type": "object",
                    "required": [
                        "id",
                        "version",
                        "configuration"
                    ],
                    "$ref": "#/definitions/workflow"
                },
                "priority": {
                    "description": "PB priority",
                    "type": "number",
                    "minimum": -1,
                    "maximum": 100
                },
                "dependencies": {
                    "description": "PB dependencies",
                    "type": "array",
                    "items": {
                        "description": "PB dependency",
                        "type": "object",
                        "required": [
                            "type",
                            "value",
                            "condition"
                        ],
                        "$ref": "#/definitions/dependency"
                    }
                }
            }
        },
        "workflow": {
            "properties": {
                "id": {
                    "description": "Workflow Id",
                    "type": "string"
                },
                "version": {
                    "description": "Workflow version",
                    "type": "string",
                    "pattern": "^[0-9]{1,4}.[0-9]{1,4}.[0-9]{1,4}"
                },
                "parameters": {
                    "description": "Workflow parameters",
                    "type": "object"
                }
            }
        },
        "dependency": {
            "properties": {
                "type": {
                    "description": "Type of dependency",
                    "type": "string"
                },
                "value": {
                    "description": "Value of the dependency",
                    "type": "string"
                },
                "condition": {
                    "description": "Dependency condition",
                    "type": "string"
                },
                "parameters": {
                    "description": "Additional parameters describing the dependency",
                    "type": "object"
                }
            }
        }
    }
}