{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://product-information-graph.org/schema/2026-05-08/jsonld/anEntity.json",
  "title": "CASCaRA AnEntity Schema for JSON-LD",
  "description": "Validates <strong>entity instances</strong> with actual property values and target link references. Includes mandatory metadata: @type (reference to Entity class), cas:revision, dcterms:modified timestamp, optional cas:priorRevision and dcterms:creator. Properties can have direct values (@value) or reference enumeration values (@id) as defined by its class. Target links reference other entity or relationship instances. Must have either dcterms:title or dcterms:description (or both) to convey meaning.",
  "type": "object",
  "properties": {
    "@id": {
      "$ref": "#/$defs/idString"
    },
    "@type": {
      "$ref": "#/$defs/idString",
      "description": "Reference to the Entity class this instance belongs to"
    },
    "cas:itemType": {
      "type": "object",
      "required": [ "@id" ],
      "properties": {
        "@id": {
          "type": "string",
          "enum": [ "cas:anEntity" ],
          "description": "The CASCaRA metamodel item type for cas:anEntity"
        }
      },
      "additionalProperties": false
    },
    "cas:revision": {
      "type": "string",
      "description": "Revision identifier for version control"
    },
    "cas:priorRevision": {
      "type": "array",
      "description": "Array of prior revision identifiers",
      "maxItems": 2,
      "items": {
        "type": "string"
      }
    },
    "dcterms:modified": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of last modification"
    },
    "dcterms:creator": {
      "type": "string",
      "description": "Creator/author of this entity instance"
    },
    "dcterms:title": {
      "type": "array",
      "description": "Multi-language titles",
      "items": {
        "$ref": "#/$defs/languageValue"
      }
    },
    "dcterms:description": {
      "type": "array",
      "description": "Multi-language descriptions",
      "items": {
        "$ref": "#/$defs/languageValue"
      }
    }
  },
  "patternProperties": {
    "^(?!cas:itemType|cas:revision|cas:priorRevision|@id|@type|dcterms:modified|dcterms:creator|dcterms:title|dcterms:description)([A-Za-z_][A-Za-z0-9_-]*:[^:\\s]+|https?://[^\\s]+)$": {
      "type": "array",
      "description": "Configurable properties and links with namespaced keys",
      "items": {
        "type": "object",
        "properties": {
          "cas:itemType": {
            "type": "object",
            "required": [ "@id" ],
            "properties": {
              "@id": {
                "type": "string",
                "enum": [ "cas:aProperty", "cas:aTargetLink" ],
                "description": "Type of configurable item: property value or target link"
              }
            },
            "additionalProperties": false
          },
          "@value": {
            "type": "string",
            "description": "Direct property value (for aProperty)"
          },
          "@id": {
            "$ref": "#/$defs/idString",
            "description": "Reference to enumeration value or linked entity/relationship"
          }
        },
        "required": [ "cas:itemType" ],
        "oneOf": [
          {
            "type": "object",
            "description": "aProperty with direct value",
            "properties": {
              "cas:itemType": {
                "type": "object",
                "properties": {
                  "@id": {
                    "const": "cas:aProperty"
                  }
                }
              }
            },
            "required": [ "@value" ],
            "not": {
              "required": [ "@id" ]
            }
          },
          {
            "type": "object",
            "description": "aTargetLink to an enumeration, entity or relationship",
            "properties": {
              "cas:itemType": {
                "type": "object",
                "properties": {
                  "@id": {
                    "const": "cas:aTargetLink"
                  }
                }
              }
            },
            "required": [ "@id" ],
            "not": {
              "required": [ "@value" ]
            }
          }
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "@id",
    "@type",
    "cas:itemType",
    "dcterms:modified"
  ],
  "anyOf": [
    {
      "required": [ "dcterms:title" ],
      "properties": {
        "dcterms:title": {
          "type": "array",
          "minItems": 1
        }
      },
      "description": "Must have at least one title"
    },
    {
      "required": [ "dcterms:description" ],
      "properties": {
        "dcterms:description": {
          "type": "array",
          "minItems": 1
        }
      },
      "description": "Must have at least one description"
    }
  ],
  "additionalProperties": false,
  "$defs": {
    "idString": {
      "type": "string",
      "pattern": "^(?:[A-Za-z_][A-Za-z0-9_-]*:[^:\\s]+|https?://[^\\s]+)$",
      "description": "A valid ID string: either a namespaced identifier (prefix:name) or a URL"
    },
    "languageValue": {
      "type": "object",
      "required": [ "@value" ],
      "properties": {
        "@value": {
          "type": "string",
          "minLength": 1,
          "description": "The actual text content"
        },
        "@language": {
          "type": "string",
          "pattern": "^[a-z]{2}(-[A-Z]{2})?$",
          "description": "IETF language tag (e.g., 'en', 'de', 'en-US')"
        }
      },
      "additionalProperties": false,
      "description": "Multi-language text value with optional language tag"
    }
  }
}
