{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "Topology datatype for topo-features. Supports two reference styles: 'references' (array of string IDs) for simple positional references, and 'directed_references' (array of oriented object references with ref+orientation) for references where traversal direction matters. Exactly one of the two must be present.",
  "$defs": {
    "simpleRefs": {
      "description": "Plain string ID references (e.g. LineString referencing point nodes)",
      "properties": {
        "type": {
          "not": {
            "enum": [
              "Face",
              "Ring",
              "Shell",
              "Solid"
            ]
          },
          "x-jsonld-id": "@type"
        },
        "references": {
          "type": "array",
          "items": {
            "$ref": "https://opengeospatial.github.io/bblocks/annotated-schemas/ogc-utils/iri-or-curie/schema.json"
          },
          "x-jsonld-id": "https://purl.org/geojson/topo#relatedFeatures",
          "x-jsonld-type": "@id",
          "x-jsonld-container": "@list"
        }
      },
      "required": [
        "references"
      ],
      "not": {
        "required": [
          "directed_references"
        ]
      }
    },
    "nestedRefs": {
      "description": "Plain string ID references (e.g. LineString referencing point nodes)",
      "properties": {
        "type": {
          "enum": [
            "MultiLineString",
            "Polygon",
            "Polyhedron",
            "Solid"
          ],
          "x-jsonld-id": "@type"
        },
        "references": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "$ref": "https://opengeospatial.github.io/bblocks/annotated-schemas/ogc-utils/iri-or-curie/schema.json"
                },
                {
                  "description": "wont check contents deeper",
                  "type": "array"
                }
              ]
            }
          },
          "x-jsonld-id": "https://purl.org/geojson/topo#relatedFeatures",
          "x-jsonld-type": "@id",
          "x-jsonld-container": "@list"
        }
      },
      "required": [
        "references"
      ],
      "not": {
        "required": [
          "directed_references"
        ]
      }
    },
    "directedRefs": {
      "description": "Oriented (directed) references \u2014 each with 'ref' and 'orientation'. Used for Ring, Shell.",
      "properties": {
        "type": {
          "enum": [
            "Face",
            "Ring",
            "Shell",
            "Solid"
          ],
          "x-jsonld-id": "@type"
        },
        "directed_references": {
          "type": "array",
          "items": {
            "$ref": "https://ogcincubator.github.io/topo-feature/build/annotated/geo/topo/datatypes/oriented-ref/schema.json"
          },
          "x-jsonld-id": "https://purl.org/geojson/topo#directedReferences",
          "x-jsonld-container": "@list"
        }
      },
      "required": [
        "directed_references"
      ],
      "not": {
        "required": [
          "references"
        ]
      }
    }
  },
  "allOf": [
    {
      "oneOf": [
        {
          "$ref": "#/$defs/simpleRefs"
        },
        {
          "$ref": "#/$defs/nestedRefs"
        },
        {
          "$ref": "#/$defs/directedRefs"
        }
      ]
    },
    {
      "properties": {
        "type": {
          "type": "string",
          "x-jsonld-id": "@type"
        },
        "relationships": {
          "type": "array",
          "items": {
            "allOf": [
              {
                "$ref": "https://opengeospatial.github.io/bblocks/annotated-schemas/geo/json-fg/link-role/schema.json"
              },
              {
                "properties": {
                  "rel": {
                    "const": "topology"
                  }
                },
                "required": [
                  "rel"
                ]
              }
            ]
          },
          "x-jsonld-id": "https://purl.org/geojson/topo#relatedFeatures",
          "x-jsonld-type": "@id",
          "x-jsonld-container": "@list"
        }
      },
      "required": [
        "type"
      ]
    }
  ],
  "x-jsonld-extra-terms": {
    "LineString": "https://purl.org/geojson/vocab#LineString",
    "MultiLineString": "https://purl.org/geojson/vocab#MultiLineString",
    "MultiPolygon": "https://purl.org/geojson/vocab#MultiPolygon",
    "Polygon": "https://purl.org/geojson/vocab#Polygon",
    "Arc": "https://purl.org/geojson/vocab#Arc",
    "ArcWithCenter": "https://purl.org/geojson/vocab#ArcWithCenter",
    "ArcByChord": "https://purl.org/geojson/vocab#ArcByChord",
    "CircleByCenter": "https://purl.org/geojson/vocab#CircleByCenter",
    "CubicSpline": "https://purl.org/geojson/vocab#CubicSpline",
    "radius": "https://purl.org/geojson/vocab#radius",
    "arcLength": "https://purl.org/geojson/vocab#arcLength",
    "startTangentVector": "https://purl.org/geojson/vocab#startTangentVector",
    "endTangentVector": "https://purl.org/geojson/vocab#endTangentVector",
    "ref": {
      "x-jsonld-id": "https://purl.org/geojson/topo#ref"
    },
    "orientation": "https://purl.org/geojson/topo#orientation",
    "Edge": "https://purl.org/geojson/topo#Edge",
    "Face": "https://purl.org/geojson/topo#Face",
    "Ring": "https://purl.org/geojson/topo#Ring",
    "Shell": "https://purl.org/geojson/topo#Shell",
    "Solid": "https://purl.org/geojson/topo#Solid",
    "rings": {
      "x-jsonld-id": "https://purl.org/geojson/topo#rings",
      "x-jsonld-container": "@list"
    },
    "shells": {
      "x-jsonld-id": "https://purl.org/geojson/topo#shells",
      "x-jsonld-container": "@list"
    },
    "faces": {
      "x-jsonld-id": "https://purl.org/geojson/topo#faces",
      "x-jsonld-container": "@list"
    }
  },
  "x-jsonld-prefixes": {
    "geojson": "https://purl.org/geojson/vocab#",
    "topo": "https://purl.org/geojson/topo#",
    "dct": "http://purl.org/dc/terms/"
  }
}