{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://stac-extensions.github.io/eo/v1.0.0/schema.json#",
  "title": "EO Extension",
  "description": "STAC EO Extension for STAC Items.",
  "oneOf": [
    {
      "$comment": "This is the schema for STAC Items.",
      "allOf": [
        {
          "type": "object",
          "required": [
            "type",
            "properties",
            "assets"
          ],
          "properties": {
            "type": {
              "const": "Feature"
            },
            "properties": {
              "$ref": "#/definitions/fields"
            },
            "assets": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/definitions/fields"
              }
            }
          },
          "$comment": "The if-then-else below checks whether the eo:bands is given in assets or not. If yes, allows eo:bands in properties (else), otherwise, disallows eo:bands in properties (then).",
          "if": {
            "required": [
              "assets"
            ],
            "properties": {
              "assets": {
                "type": "object",
                "additionalProperties": {
                  "properties": {
                    "eo:bands": false
                  }
                }
              }
            }
          },
          "then": {
            "properties": {
              "properties": {
                "properties": {
                  "eo:bands": false
                }
              }
            }
          },
          "else": {
            "properties": {
              "properties": {
                "properties": {
                  "eo:bands": {
                    "$ref": "#/definitions/bands"
                  }
                }
              }
            }
          }
        },
        {
          "$ref": "#/definitions/stac_extensions"
        }
      ]
    },
    {
      "$comment": "This is the schema for STAC Collections.",
      "allOf": [
        {
          "type": "object",
          "required": [
            "type"
          ],
          "properties": {
            "type": {
              "const": "Collection"
            },
            "assets": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/definitions/fields"
              }
            },
            "item_assets": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/definitions/fields"
              }
            }
          }
        },
        {
          "$ref": "#/definitions/stac_extensions"
        }
      ]
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": [
        "stac_extensions"
      ],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://stac-extensions.github.io/eo/v1.0.0/schema.json"
          }
        }
      }
    },
    "fields": {
      "type": "object",
      "properties": {
        "eo:cloud_cover": {
          "title": "Cloud Cover",
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "eo:bands": {
          "$ref": "#/definitions/bands"
        }
      },
      "patternProperties": {
        "^(?!eo:)": {}
      },
      "additionalProperties": false
    },
    "bands": {
      "title": "Bands",
      "type": "array",
      "minItems": 1,
      "items": {
        "title": "Band",
        "type": "object",
        "minProperties": 1,
        "properties": {
          "name": {
            "title": "Name of the band",
            "type": "string"
          },
          "common_name": {
            "title": "Common Name of the band",
            "type": "string",
            "enum": [
              "coastal",
              "blue",
              "green",
              "red",
              "rededge",
              "yellow",
              "pan",
              "nir",
              "nir08",
              "nir09",
              "cirrus",
              "swir16",
              "swir22",
              "lwir",
              "lwir11",
              "lwir12"
            ]
          },
          "center_wavelength": {
            "title": "Center Wavelength",
            "type": "number"
          },
          "full_width_half_max": {
            "title": "Full Width Half Max (FWHM)",
            "type": "number"
          }
        }
      }
    }
  }
}