{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.portolan-sdi.org/incubating/partition/v1.0.0/schema.json#",
  "title": "STAC Partition Extension",
  "description": "Extends STAC Collections with Hive-style partition metadata for efficient querying of partitioned datasets.",
  "oneOf": [
    {
      "$comment": "This is the schema for STAC Collections.",
      "type": "object",
      "allOf": [
        {
          "required": ["type"],
          "properties": {
            "type": {
              "const": "Collection"
            }
          }
        },
        {
          "$ref": "#/definitions/stac_extensions"
        }
      ],
      "anyOf": [
        {
          "$comment": "Top-level fields in a Collection.",
          "allOf": [
            {
              "required": ["partition:scheme", "partition:keys", "partition:glob"]
            },
            {
              "$ref": "#/definitions/fields"
            }
          ]
        }
      ]
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": ["stac_extensions"],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://schemas.portolan-sdi.org/incubating/partition/v1.0.0/schema.json"
          }
        }
      }
    },
    "fields": {
      "type": "object",
      "properties": {
        "partition:scheme": {
          "type": "string",
          "enum": ["hive", "directory"],
          "description": "Partitioning scheme. 'hive' uses key=value directory naming; 'directory' uses plain subdirectories."
        },
        "partition:strategy": {
          "type": "string",
          "enum": ["kdtree", "h3", "s2", "quadkey", "a5", "temporal", "attribute"],
          "description": "Algorithm or method used to determine partition boundaries."
        },
        "partition:keys": {
          "type": "array",
          "minItems": 1,
          "description": "Partition key definitions in hierarchical order.",
          "items": {
            "type": "object",
            "required": ["name", "type"],
            "properties": {
              "name": {
                "type": "string",
                "description": "Column name used as partition key."
              },
              "type": {
                "type": "string",
                "enum": ["string", "int32", "int64", "date", "timestamp"],
                "description": "Data type of the partition key."
              },
              "description": {
                "type": "string",
                "description": "Human-readable description of the partition key."
              }
            }
          }
        },
        "partition:file_count": {
          "type": "integer",
          "minimum": 1,
          "description": "Total number of data files across all partitions."
        },
        "partition:glob": {
          "type": "string",
          "minLength": 1,
          "description": "Glob pattern for bulk access to all partition data files (e.g., https://example.org/collection/*/*.parquet or s3://bucket/collection/key=*/*.parquet)."
        }
      }
    }
  }
}
