{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://stac.linz.govt.nz/v0.0.15/scanning/schema.json",
  "title": "Scanning Extension",
  "description": "STAC Scanning Extension for STAC Items, and Collection Summaries.",
  "allOf": [
    {
      "$ref": "#/definitions/stac_extensions"
    },
    {
      "if": {
        "type": "object",
        "properties": {
          "type": {
            "const": "Feature"
          }
        }
      },
      "then": {
        "$comment": "This is the schema for STAC Items.",
        "allOf": [
          {
            "type": "object",
            "required": ["type", "properties", "assets"],
            "properties": {
              "properties": {
                "$ref": "#/definitions/fields"
              },
              "assets": {
                "type": "object",
                "additionalProperties": {
                  "$ref": "#/definitions/fields"
                }
              }
            }
          }
        ]
      },
      "else": {
        "if": {
          "type": "object",
          "properties": {
            "type": {
              "const": "Collection"
            }
          }
        },
        "then": {
          "$comment": "This is the schema for STAC Collections. This extension requires this for Collection summaries.",
          "type": "object",
          "allOf": [
            {
              "required": ["type"]
            },
            {
              "$ref": "#/definitions/fields"
            }
          ]
        },
        "else": false
      }
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": ["stac_extensions"],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://stac.linz.govt.nz/v0.0.15/scanning/schema.json"
          }
        }
      }
    },
    "fields": {
      "type": "object",
      "properties": {
        "scan:is_original": {
          "title": "Original Negative",
          "type": "boolean"
        },
        "scan:scanned": {
          "title": "Scanned Date",
          "type": "string",
          "format": "date-time",
          "pattern": "(\\+00:00|Z)$"
        },
        "summaries": {
          "type": "object",
          "properties": {
            "scan:is_original": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "boolean"
              }
            },
            "scan:scanned": {
              "type": "object",
              "required": ["minimum", "maximum"],
              "properties": {
                "minimum": {
                  "title": "Earliest date",
                  "type": "string",
                  "format": "date-time",
                  "pattern": "(\\+00:00|Z)$"
                },
                "maximum": {
                  "title": "Most recent date",
                  "type": "string",
                  "format": "date-time",
                  "pattern": "(\\+00:00|Z)$"
                }
              }
            }
          }
        }
      },
      "patternProperties": {
        "^(?!scan:)": {}
      },
      "additionalProperties": false
    }
  }
}
