{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nsta1.github.io/Orleans.Lattice/docs/agents/schemas/deployment.schema.json",
  "schema": "lattice.agents/json-schema/v1",
  "title": "Orleans.Lattice deployment specification",
  "description": "Reference topologies and the options configuration schema, including environment-variable bound options.",
  "type": "object",
  "required": [
    "schema",
    "topologies",
    "configuration_schema"
  ],
  "properties": {
    "schema": {
      "const": "lattice.agents/deployment/v1"
    },
    "topologies": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "silos",
          "regions",
          "packages",
          "trees",
          "replication_mode",
          "storage",
          "sources"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "silos": {
            "type": "string",
            "minLength": 1
          },
          "regions": {
            "type": "string",
            "minLength": 1
          },
          "packages": {
            "$ref": "#/$defs/packages"
          },
          "trees": {
            "type": "string",
            "minLength": 1
          },
          "replication_mode": {
            "type": "string",
            "minLength": 1
          },
          "storage": {
            "type": "string",
            "minLength": 1
          },
          "sources": {
            "$ref": "#/$defs/sources"
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "configuration_schema": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "type",
          "package",
          "registration",
          "properties"
        ],
        "properties": {
          "type": {
            "type": "string",
            "minLength": 1
          },
          "package": {
            "$ref": "#/$defs/package"
          },
          "registration": {
            "type": "object",
            "required": [
              "value",
              "source"
            ],
            "properties": {
              "value": {
                "type": "string",
                "minLength": 1
              },
              "source": {
                "$ref": "#/$defs/source"
              }
            },
            "additionalProperties": false
          },
          "properties": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "type",
                "default",
                "source"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1
                },
                "type": {
                  "type": "string",
                  "minLength": 1
                },
                "default": {
                  "type": "string"
                },
                "source": {
                  "$ref": "#/$defs/source"
                },
                "validation": {
                  "type": "string",
                  "minLength": 1
                },
                "environment_variable": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "additionalProperties": false
            }
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    }
  },
  "additionalProperties": false,
  "$defs": {
    "claim": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "statement",
            "source"
          ],
          "properties": {
            "statement": {
              "type": "string",
              "minLength": 1
            },
            "source": {
              "$ref": "#/$defs/source"
            }
          },
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/uncertain"
        }
      ]
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "package": {
      "type": "string",
      "pattern": "^Orleans\\.Lattice(\\.[A-Z][A-Za-z0-9]*)*$"
    },
    "packages": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^Orleans\\.Lattice(\\.[A-Z][A-Za-z0-9]*)*$"
      }
    },
    "source": {
      "type": "string",
      "pattern": "^((src|docs|test|samples|spec|tools|benchmark|reference-architecture|\\.github)/[A-Za-z0-9_./\\-]+|FEATURES\\.md|PACKAGES\\.md|README\\.md|reference-architecture\\.md)(#[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)?$"
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^((src|docs|test|samples|spec|tools|benchmark|reference-architecture|\\.github)/[A-Za-z0-9_./\\-]+|FEATURES\\.md|PACKAGES\\.md|README\\.md|reference-architecture\\.md)(#[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)?$"
      }
    },
    "text": {
      "type": "string",
      "minLength": 1
    },
    "uncertain": {
      "type": "object",
      "required": [
        "status",
        "reason",
        "required_source"
      ],
      "properties": {
        "status": {
          "const": "uncertain"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "required_source": {
          "type": "string",
          "minLength": 1
        },
        "issue": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    }
  }
}
