{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://yarramate.org/schema/visual-model/v1",
  "title": "YarraMate visual model",
  "description": "One complete, self-contained native model graph handed to a visual session at start.",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "authority", "initialView", "sourceDigests", "graph"],
  "properties": {
    "format": {
      "const": "yarramate/visual-model/v1"
    },
    "authority": {
      "$ref": "#/$defs/authority"
    },
    "initialView": {
      "$ref": "#/$defs/viewId"
    },
    "sourceDigests": {
      "type": "object",
      "maxProperties": 4096,
      "propertyNames": {
        "$ref": "#/$defs/relativePath"
      },
      "additionalProperties": {
        "$ref": "#/$defs/digest"
      }
    },
    "graph": {
      "$ref": "https://yarramate.org/schema/visual-graph/v1"
    }
  },
  "allOf": [
    {
      "if": {
        "type": "object",
        "required": ["authority"],
        "properties": {
          "authority": {
            "const": "canonical"
          }
        }
      },
      "then": {
        "type": "object",
        "properties": {
          "sourceDigests": {
            "type": "object",
            "minProperties": 1
          }
        }
      }
    }
  ],
  "$defs": {
    "authority": {
      "const": "canonical"
    },
    "viewId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
    },
    "digest": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "relativePath": {
      "type": "string",
      "maxLength": 1024,
      "pattern": "^(?:(?!\\.\\.?/)[A-Za-z0-9._-]+/)*(?!\\.\\.?$)[A-Za-z0-9._-]+$"
    }
  }
}
