{
  "$defs": {
    "BayesianModel": {
      "additionalProperties": false,
      "properties": {
        "edges": {
          "items": {
            "$ref": "#/$defs/EdgeSpec"
          },
          "title": "Edges",
          "type": "array"
        },
        "id": {
          "default": "model",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
          "title": "Id",
          "type": "string"
        },
        "metadata": {
          "$ref": "#/$defs/ModelMetadata"
        },
        "name": {
          "default": "Untitled model",
          "title": "Name",
          "type": "string"
        },
        "nodes": {
          "items": {
            "$ref": "#/$defs/NodeSpec"
          },
          "title": "Nodes",
          "type": "array"
        }
      },
      "title": "BayesianModel",
      "type": "object",
      "required": [
        "id",
        "name",
        "nodes",
        "edges"
      ]
    },
    "CPTDefinition": {
      "additionalProperties": false,
      "properties": {
        "rows": {
          "items": {
            "$ref": "#/$defs/CPTRow"
          },
          "title": "Rows",
          "type": "array"
        },
        "type": {
          "const": "cpt",
          "default": "cpt",
          "title": "Type",
          "type": "string"
        }
      },
      "required": [
        "rows"
      ],
      "title": "CPTDefinition",
      "type": "object"
    },
    "CPTRow": {
      "additionalProperties": false,
      "properties": {
        "probabilities": {
          "items": {
            "type": "number"
          },
          "title": "Probabilities",
          "type": "array"
        },
        "when": {
          "additionalProperties": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              }
            ]
          },
          "title": "When",
          "type": "object"
        }
      },
      "required": [
        "probabilities"
      ],
      "title": "CPTRow",
      "type": "object"
    },
    "DeterministicDefinition": {
      "additionalProperties": false,
      "properties": {
        "expression": {
          "title": "Expression",
          "type": "string"
        },
        "type": {
          "const": "deterministic",
          "default": "deterministic",
          "title": "Type",
          "type": "string"
        }
      },
      "required": [
        "expression"
      ],
      "title": "DeterministicDefinition",
      "type": "object"
    },
    "DistributionDefinition": {
      "additionalProperties": false,
      "properties": {
        "name": {
          "title": "Name",
          "type": "string"
        },
        "params": {
          "additionalProperties": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              },
              {
                "items": {
                  "type": "number"
                },
                "type": "array"
              },
              {
                "items": {
                  "type": "integer"
                },
                "type": "array"
              },
              {
                "items": {
                  "type": "string"
                },
                "type": "array"
              }
            ]
          },
          "title": "Params",
          "type": "object"
        },
        "type": {
          "const": "distribution",
          "default": "distribution",
          "title": "Type",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "title": "DistributionDefinition",
      "type": "object"
    },
    "EdgeSpec": {
      "additionalProperties": false,
      "properties": {
        "child": {
          "title": "Child",
          "type": "string"
        },
        "label": {
          "default": "",
          "title": "Label",
          "type": "string"
        },
        "parent": {
          "title": "Parent",
          "type": "string"
        }
      },
      "required": [
        "parent",
        "child"
      ],
      "title": "EdgeSpec",
      "type": "object"
    },
    "EvidenceSpec": {
      "additionalProperties": false,
      "properties": {
        "kind": {
          "default": "hard",
          "enum": [
            "hard",
            "interval",
            "soft",
            "normal"
          ],
          "title": "Kind",
          "type": "string"
        },
        "likelihoods": {
          "additionalProperties": {
            "type": "number"
          },
          "title": "Likelihoods",
          "type": "object"
        },
        "lower": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Lower"
        },
        "sd": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sd"
        },
        "upper": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Upper"
        },
        "value": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "integer"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Value"
        }
      },
      "title": "EvidenceSpec",
      "type": "object"
    },
    "InferenceSettings": {
      "additionalProperties": false,
      "properties": {
        "engine": {
          "default": "auto",
          "enum": [
            "auto",
            "exact",
            "monte_carlo"
          ],
          "title": "Engine",
          "type": "string"
        },
        "exact_state_limit": {
          "default": 100000,
          "maximum": 5000000,
          "minimum": 2,
          "title": "Exact State Limit",
          "type": "integer"
        },
        "samples": {
          "default": 20000,
          "maximum": 2000000,
          "minimum": 100,
          "title": "Samples",
          "type": "integer"
        },
        "seed": {
          "default": 20260821,
          "maximum": 4294967295,
          "minimum": 0,
          "title": "Seed",
          "type": "integer"
        }
      },
      "title": "InferenceSettings",
      "type": "object"
    },
    "ModelMetadata": {
      "additionalProperties": false,
      "properties": {
        "author": {
          "default": "",
          "title": "Author",
          "type": "string"
        },
        "created_at": {
          "default": "",
          "title": "Created At",
          "type": "string"
        },
        "description": {
          "default": "",
          "title": "Description",
          "type": "string"
        },
        "organisation": {
          "default": "",
          "title": "Organisation",
          "type": "string"
        },
        "tags": {
          "items": {
            "type": "string"
          },
          "title": "Tags",
          "type": "array"
        },
        "updated_at": {
          "default": "",
          "title": "Updated At",
          "type": "string"
        }
      },
      "title": "ModelMetadata",
      "type": "object"
    },
    "NodePosition": {
      "additionalProperties": false,
      "properties": {
        "x": {
          "default": 120.0,
          "title": "X",
          "type": "number"
        },
        "y": {
          "default": 120.0,
          "title": "Y",
          "type": "number"
        }
      },
      "title": "NodePosition",
      "type": "object"
    },
    "NodeSpec": {
      "additionalProperties": false,
      "properties": {
        "colour": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Colour"
        },
        "definition": {
          "discriminator": {
            "mapping": {
              "cpt": "#/$defs/CPTDefinition",
              "deterministic": "#/$defs/DeterministicDefinition",
              "distribution": "#/$defs/DistributionDefinition",
              "probability_formula": "#/$defs/ProbabilityFormulaDefinition"
            },
            "propertyName": "type"
          },
          "oneOf": [
            {
              "$ref": "#/$defs/DistributionDefinition"
            },
            {
              "$ref": "#/$defs/CPTDefinition"
            },
            {
              "$ref": "#/$defs/ProbabilityFormulaDefinition"
            },
            {
              "$ref": "#/$defs/DeterministicDefinition"
            }
          ],
          "title": "Definition"
        },
        "description": {
          "default": "",
          "title": "Description",
          "type": "string"
        },
        "group": {
          "default": "",
          "title": "Group",
          "type": "string"
        },
        "id": {
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
          "title": "Id",
          "type": "string"
        },
        "kind": {
          "enum": [
            "boolean",
            "labelled",
            "ranked",
            "continuous",
            "integer",
            "discrete_real"
          ],
          "title": "Kind",
          "type": "string"
        },
        "label": {
          "title": "Label",
          "type": "string"
        },
        "position": {
          "$ref": "#/$defs/NodePosition"
        },
        "states": {
          "items": {
            "$ref": "#/$defs/StateSpec"
          },
          "title": "States",
          "type": "array"
        },
        "tags": {
          "items": {
            "type": "string"
          },
          "title": "Tags",
          "type": "array"
        },
        "units": {
          "default": "",
          "title": "Units",
          "type": "string"
        },
        "role": {
          "type": "string",
          "enum": [
            "chance",
            "decision",
            "utility"
          ],
          "default": "chance",
          "description": "Single-stage modelling role; decisions are categorical roots, utilities are deterministic numeric nodes."
        }
      },
      "required": [
        "id",
        "label",
        "kind",
        "definition"
      ],
      "title": "NodeSpec",
      "type": "object"
    },
    "ProbabilityFormulaDefinition": {
      "additionalProperties": false,
      "properties": {
        "probabilities": {
          "additionalProperties": {
            "type": "string"
          },
          "title": "Probabilities",
          "type": "object"
        },
        "type": {
          "const": "probability_formula",
          "default": "probability_formula",
          "title": "Type",
          "type": "string"
        }
      },
      "required": [
        "probabilities"
      ],
      "title": "ProbabilityFormulaDefinition",
      "type": "object"
    },
    "ScenarioSpec": {
      "additionalProperties": false,
      "properties": {
        "description": {
          "default": "",
          "title": "Description",
          "type": "string"
        },
        "evidence": {
          "additionalProperties": {
            "$ref": "#/$defs/EvidenceSpec"
          },
          "title": "Evidence",
          "type": "object"
        },
        "id": {
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
          "title": "Id",
          "type": "string"
        },
        "interventions": {
          "additionalProperties": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              }
            ]
          },
          "title": "Interventions",
          "type": "object"
        },
        "name": {
          "title": "Name",
          "type": "string"
        }
      },
      "required": [
        "id",
        "name"
      ],
      "title": "ScenarioSpec",
      "type": "object"
    },
    "StateSpec": {
      "additionalProperties": false,
      "properties": {
        "colour": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Colour"
        },
        "label": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Label"
        },
        "value": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "integer"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            }
          ],
          "title": "Value"
        }
      },
      "required": [
        "value"
      ],
      "title": "StateSpec",
      "type": "object"
    },
    "UISettings": {
      "additionalProperties": false,
      "properties": {
        "active_scenario_id": {
          "default": "baseline",
          "title": "Active Scenario Id",
          "type": "string"
        },
        "selected_node_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Selected Node Id"
        },
        "target_node_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Target Node Id"
        },
        "theme": {
          "default": "light",
          "enum": [
            "light",
            "dark"
          ],
          "title": "Theme",
          "type": "string"
        }
      },
      "title": "UISettings",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "properties": {
    "application": {
      "const": "AUClimRisk",
      "default": "AUClimRisk",
      "title": "Application",
      "type": "string"
    },
    "extensions": {
      "additionalProperties": true,
      "title": "Extensions",
      "type": "object"
    },
    "inference": {
      "$ref": "#/$defs/InferenceSettings"
    },
    "model": {
      "$ref": "#/$defs/BayesianModel"
    },
    "scenarios": {
      "items": {
        "$ref": "#/$defs/ScenarioSpec"
      },
      "title": "Scenarios",
      "type": "array"
    },
    "schema_version": {
      "default": "1.1.0",
      "title": "Schema Version",
      "type": "string",
      "enum": [
        "1.0.0",
        "1.1.0"
      ]
    },
    "ui": {
      "$ref": "#/$defs/UISettings"
    }
  },
  "required": [
    "application",
    "schema_version",
    "model"
  ],
  "title": "ModelDocument",
  "type": "object",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:auclimrisk:model:1.1.0"
}
