{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://portolan-sdi.github.io/stac-iceberg-extension/v1.0.0/schema.json#",
  "title": "STAC Iceberg Extension",
  "description": "Extends STAC Collections with Apache Iceberg table access and versioning metadata.",
  "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": ["iceberg:catalog_type", "iceberg:table_id"]
            },
            {
              "$ref": "#/definitions/fields"
            }
          ]
        }
      ]
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": ["stac_extensions"],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://portolan-sdi.github.io/stac-iceberg-extension/v1.0.0/schema.json"
          }
        }
      }
    },
    "fields": {
      "type": "object",
      "properties": {
        "iceberg:catalog_type": {
          "type": "string",
          "enum": ["sql", "rest", "glue", "hive", "dynamodb"],
          "description": "Iceberg catalog backend type"
        },
        "iceberg:catalog_uri": {
          "type": "string",
          "description": "Connection URI for the Iceberg catalog"
        },
        "iceberg:table_id": {
          "type": "string",
          "description": "Fully qualified Iceberg table identifier (namespace.table)"
        },
        "iceberg:format_version": {
          "type": "integer",
          "enum": [1, 2],
          "description": "Iceberg format version"
        },
        "iceberg:current_snapshot_id": {
          "type": "integer",
          "description": "Current snapshot ID for reproducibility"
        },
        "iceberg:partition_spec": {
          "type": "array",
          "description": "Iceberg partition fields and transforms",
          "items": {
            "type": "object",
            "required": ["field", "transform"],
            "properties": {
              "field": {
                "type": "string",
                "description": "Source column name"
              },
              "transform": {
                "type": "string",
                "description": "Iceberg partition transform (identity, bucket, truncate, etc.)"
              }
            }
          }
        }
      }
    }
  }
}
