{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://stac-extensions.github.io/order/v1.1.0/schema.json#",
  "title": "order Extension",
  "description": "STAC order Extension for STAC Items and STAC Collections.",
  "oneOf": [
    {
      "$comment": "This is the schema for STAC Items. Remove this object if this extension only applies to Collections.",
      "allOf": [
        {
          "$ref": "#/definitions/stac_extensions"
        },
        {
          "type": "object",
          "required": [
            "type",
            "properties",
            "assets"
          ],
          "properties": {
            "type": {
              "const": "Feature"
            },
            "properties": {
              "allOf": [
                {
                  "$comment": "Require fields here for Item Properties.",
                  "required": [
                    "order:status"
                  ]
                },
                {
                  "$ref": "#/definitions/fields"
                }
              ]
            },
            "assets": {
              "$comment": "This validates the fields in Item Assets, but does not require them.",
              "type": "object",
              "additionalProperties": {
                "$ref": "#/definitions/fields"
              }
            }
          }
        }
      ]
    },
    {
      "$comment": "This is the schema for STAC Collections.",
      "type": "object",
      "allOf": [
        {
          "required": [
            "type"
          ],
          "properties": {
            "type": {
              "const": "Collection"
            }
          }
        },
        {
          "$ref": "#/definitions/stac_extensions"
        }
      ],
      "anyOf": [
        {
          "$comment": "This is the schema for the top-level fields in a Collection. Remove this if this extension does not define top-level fields for Collections.",
          "allOf": [
            {
              "$comment": "Require fields here for Collections (top-level).",
              "required": [
                "order:status"
              ]
            },
            {
              "$ref": "#/definitions/fields"
            }
          ]
        },
        {
          "$comment": "This validates the fields in Collection Assets, but does not require them.",
          "required": [
            "assets"
          ],
          "properties": {
            "assets": {
              "type": "object",
              "not": {
                "additionalProperties": {
                  "not": {
                    "allOf": [
                      {
                        "$ref": "#/definitions/require_any_field"
                      },
                      {
                        "$ref": "#/definitions/fields"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "$comment": "This is the schema for the fields in Item Asset Definitions. It doesn't require any fields.",
          "required": [
            "item_assets"
          ],
          "properties": {
            "item_assets": {
              "type": "object",
              "not": {
                "additionalProperties": {
                  "not": {
                    "allOf": [
                      {
                        "$ref": "#/definitions/require_any_field"
                      },
                      {
                        "$ref": "#/definitions/fields"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "$comment": "This is the schema for the fields in Summaries. By default, only checks the existence of the properties, but not the schema of the summaries.",
          "required": [
            "summaries"
          ],
          "properties": {
            "summaries": {
              "$ref": "#/definitions/require_any_field"
            }
          }
        }
      ]
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": [
        "stac_extensions"
      ],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://stac-extensions.github.io/order/v1.1.0/schema.json"
          }
        }
      }
    },
    "require_any_field": {
      "$comment": "Please list all fields here so that we can force the existence of one of them in other parts of the schemas.",
      "anyOf": [
        {
          "required": [
            "order:status"
          ]
        }
      ]
    },
    "fields": {
      "$comment": "Add your new fields here. Don't require them here, do that above in the item schema.",
      "type": "object",
      "properties": {
        "order:status": {
          "type": "string"
        },
        "order:id": {
          "type": "string"
        },
        "order:date": {
          "type": "string",
          "format": "date-time",
          "pattern": "(\\+00:00|Z)$"
        },
        "order:expiration_date": {
          "type": "string",
          "format": "date-time",
          "pattern": "(\\+00:00|Z)$",
          "deprecated": true
        }
      },
      "patternProperties": {
        "^(?!order:)": {
          "$comment": "Above, change `order` to the prefix of this extension"
        }
      },
      "additionalProperties": false
    }
  }
}