{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nsta1.github.io/Orleans.Lattice/docs/agents/schemas/concepts.schema.json",
  "schema": "lattice.agents/json-schema/v1",
  "title": "Orleans.Lattice concept graph",
  "description": "Concepts with definitions, capability boundaries and operational limits, and typed relationships between them.",
  "type": "object",
  "required": [
    "schema",
    "concepts",
    "relationships"
  ],
  "properties": {
    "schema": {
      "const": "lattice.agents/concepts/v1"
    },
    "concepts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "name",
          "category",
          "definition",
          "packages",
          "capability_boundary",
          "operational_envelope",
          "sources"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "category": {
            "type": "string",
            "minLength": 1
          },
          "definition": {
            "type": "string",
            "minLength": 1
          },
          "packages": {
            "$ref": "#/$defs/packages"
          },
          "capability_boundary": {
            "type": "object",
            "required": [
              "in_scope",
              "out_of_scope"
            ],
            "properties": {
              "in_scope": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/claim"
                }
              },
              "out_of_scope": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/claim"
                }
              }
            },
            "additionalProperties": false
          },
          "operational_envelope": {
            "type": "object",
            "required": [
              "limits"
            ],
            "properties": {
              "limits": {
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "name",
                        "value",
                        "unit",
                        "source"
                      ],
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1
                        },
                        "value": {
                          "type": [
                            "number",
                            "boolean",
                            "string"
                          ]
                        },
                        "unit": {
                          "type": "string",
                          "minLength": 1
                        },
                        "source": {
                          "$ref": "#/$defs/source"
                        }
                      },
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "required": [
                        "statement",
                        "source"
                      ],
                      "properties": {
                        "statement": {
                          "type": "string",
                          "minLength": 1
                        },
                        "source": {
                          "$ref": "#/$defs/source"
                        }
                      },
                      "additionalProperties": false
                    }
                  ]
                }
              }
            },
            "additionalProperties": false
          },
          "sources": {
            "$ref": "#/$defs/sources"
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "relationships": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "from",
          "relation",
          "to",
          "sources"
        ],
        "properties": {
          "from": {
            "$ref": "#/$defs/id"
          },
          "relation": {
            "enum": [
              "configures",
              "consumes",
              "depends-on",
              "extends",
              "guards",
              "implements",
              "observes",
              "part-of",
              "produces",
              "replicates",
              "stores"
            ]
          },
          "to": {
            "$ref": "#/$defs/id"
          },
          "sources": {
            "$ref": "#/$defs/sources"
          }
        },
        "additionalProperties": false
      }
    }
  },
  "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
    }
  }
}
