{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://largepeoplemodel.com/organizational-intelligence.schema.json",
  "title": "Large People Model organizational intelligence",
  "description": "Validation schema for the complete LPM intelligence graph and its type-specific catalog envelopes.",
  "oneOf": [
    {
      "$ref": "#/$defs/graph"
    },
    {
      "$ref": "#/$defs/catalog"
    }
  ],
  "$defs": {
    "publisher": {
      "type": "object",
      "required": [
        "name",
        "brand",
        "url"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "brand": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      },
      "additionalProperties": false
    },
    "relationship": {
      "type": "object",
      "required": [
        "type",
        "targetId"
      ],
      "properties": {
        "type": {
          "enum": [
            "depends_on",
            "supports",
            "measures",
            "applies_to",
            "related_to",
            "supersedes",
            "evidenced_by"
          ]
        },
        "targetId": {
          "type": "string",
          "pattern": "^lpm:"
        }
      },
      "additionalProperties": false
    },
    "object": {
      "type": "object",
      "required": [
        "id",
        "type",
        "slug",
        "title",
        "canonicalUrl",
        "version",
        "status",
        "source",
        "publisher",
        "lastUpdated",
        "relationships",
        "content"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^lpm:"
        },
        "type": {
          "enum": [
            "layer",
            "law",
            "definition",
            "metric",
            "knowledge-object",
            "use-case",
            "article"
          ]
        },
        "slug": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "canonicalUrl": {
          "type": "string",
          "format": "uri"
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "canonical",
            "published"
          ]
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "publisher": {
          "type": "string",
          "minLength": 1
        },
        "lastUpdated": {
          "type": "string",
          "format": "date"
        },
        "relationships": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/relationship"
          }
        },
        "content": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    "releaseFields": {
      "type": "object",
      "required": [
        "schemaVersion",
        "releaseVersion",
        "releasedAt",
        "publisher"
      ],
      "properties": {
        "schemaVersion": {
          "type": "string"
        },
        "releaseVersion": {
          "type": "string"
        },
        "releasedAt": {
          "type": "string",
          "format": "date"
        },
        "publisher": {
          "$ref": "#/$defs/publisher"
        }
      }
    },
    "graph": {
      "allOf": [
        {
          "$ref": "#/$defs/releaseFields"
        },
        {
          "type": "object",
          "required": [
            "canon",
            "relationshipVocabulary",
            "counts",
            "objects"
          ],
          "properties": {
            "canon": {
              "type": "object"
            },
            "relationshipVocabulary": {
              "type": "array",
              "items": {
                "enum": [
                  "depends_on",
                  "supports",
                  "measures",
                  "applies_to",
                  "related_to",
                  "supersedes",
                  "evidenced_by"
                ]
              },
              "uniqueItems": true
            },
            "counts": {
              "type": "object"
            },
            "objects": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/object"
              }
            }
          }
        }
      ]
    },
    "catalog": {
      "allOf": [
        {
          "$ref": "#/$defs/releaseFields"
        },
        {
          "type": "object",
          "required": [
            "canonicalUrl",
            "canon",
            "objects"
          ],
          "properties": {
            "canonicalUrl": {
              "type": "string",
              "format": "uri"
            },
            "canon": {
              "type": "object"
            },
            "objects": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/object"
              }
            }
          }
        }
      ]
    }
  }
}
