{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://pdssp.github.io/stacplanet/v1.0.0/schema.json",
  "title": "PDSSP Planetary Data Schema for STACPlanet Items and Collections",
  "description": "Profile defining PDSSP-specific constraints for planetary data products. Applies to both STAC Items and Collections. Required extensions on an Item depend on whether the product is located: a null geometry relaxes the projection and version requirements.",
  "type": "object",
  "allOf": [
    {
      "if": {
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "const": "Feature"
          }
        }
      },
      "then": {
        "$ref": "#/definitions/item"
      }
    },
    {
      "if": {
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "const": "Collection"
          }
        }
      },
      "then": {
        "$ref": "#/definitions/collection"
      }
    }
  ],
  "definitions": {
    "item": {
      "type": "object",
      "required": [
        "stac_extensions",
        "properties",
        "geometry"
      ],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "allOf": [
            {
              "contains": {
                "type": "string",
                "pattern": "stac-extensions\\.github\\.io/ssys/"
              }
            },
            {
              "contains": {
                "type": "string",
                "pattern": "stac-extensions\\.github\\.io/product/"
              }
            },
            {
              "contains": {
                "type": "string",
                "pattern": "stac-extensions\\.github\\.io/processing/"
              }
            }
          ]
        },
        "properties": {
          "type": "object",
          "required": [
            "ssys:targets",
            "ssys:target_class",
            "version",
            "product:type",
            "processing:level"
          ],
          "properties": {
            "ssys:targets": {
              "type": "array",
              "items": {
                "enum": [
                  "Mercury",
                  "Venus",
                  "Mars",
                  "Moon",
                  "Titan"
                ]
              },
              "minItems": 1,
              "description": "List of solar system targets covered by the data. At least one target is required."
            },
            "ssys:target_class": {
              "type": "string",
              "enum": [
                "planet",
                "satellite"
              ],
              "description": "Classification of the primary target (e.g. planet, satellite)."
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "description": "Version identifier for the data product. Mandatory for items."
            },
            "product:type": {
              "type": "string",
              "enum": [
                "Cube",
                "Spectrum",
                "Spectral Cube",
                "Image",
                "Map",
                "Volume",
                "Time Series",
                "Dynamic Spectrum",
                "Catalog",
                "Spatial Vector"
              ],
              "description": "Type of the data product. This field is mandatory."
            },
            "processing:level": {
              "type": "string",
              "enum": [
                "Ancillary",
                "Raw",
                "Calibrated",
                "Derived"
              ],
              "description": "Processing level of the data product. This field is mandatory."
            },
            "pdssp:solar_longitude": {
              "type": "number",
              "description": "Solar longitude of the target at the time of observation."
            },
            "pdssp:solar_distance": {
              "type": "number",
              "description": "Distance from the Sun to the target, in astronomical units."
            },
            "pdssp:map_resolution": {
              "type": "number",
              "description": "Spatial resolution of the map, in metres per pixel."
            },
            "pdssp:map_scale": {
              "type": "number",
              "description": "Scale of the map."
            }
          }
        },
        "geometry": {
          "type": [
            "object",
            "null"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "geometry"
            ],
            "properties": {
              "geometry": {
                "not": {
                  "type": "null"
                }
              }
            }
          },
          "then": {
            "properties": {
              "stac_extensions": {
                "allOf": [
                  {
                    "contains": {
                      "type": "string",
                      "pattern": "stac-extensions\\.github\\.io/projection/"
                    }
                  },
                  {
                    "contains": {
                      "type": "string",
                      "pattern": "stac-extensions\\.github\\.io/version/"
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "properties": {
                "required": [
                  "product:type"
                ],
                "properties": {
                  "product:type": {
                    "const": "Map"
                  }
                }
              }
            },
            "required": [
              "properties"
            ]
          },
          "then": {
            "properties": {
              "properties": {
                "required": [
                  "pdssp:map_resolution"
                ]
              }
            }
          }
        }
      ]
    },
    "collection": {
      "type": "object",
      "required": [
        "stac_extensions",
        "properties",
        "license"
      ],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "allOf": [
            {
              "contains": {
                "type": "string",
                "pattern": "stac-extensions\\.github\\.io/ssys/"
              }
            },
            {
              "contains": {
                "type": "string",
                "pattern": "stac-extensions\\.github\\.io/processing/"
              }
            },
            {
              "contains": {
                "type": "string",
                "pattern": "stac-extensions\\.github\\.io/product/"
              }
            }
          ]
        },
        "properties": {
          "type": "object",
          "required": [
            "ssys:targets",
            "ssys:target_class",
            "product:type",
            "processing:level"
          ],
          "properties": {
            "ssys:targets": {
              "type": "array",
              "items": {
                "enum": [
                  "Mercury",
                  "Venus",
                  "Mars",
                  "Moon",
                  "Titan"
                ]
              },
              "minItems": 1,
              "description": "List of solar system targets covered by the data. At least one target is required."
            },
            "ssys:target_class": {
              "type": "string",
              "enum": [
                "planet",
                "satellite"
              ],
              "description": "Classification of the primary target (e.g. planet, satellite)."
            },
            "product:type": {
              "type": "string",
              "enum": [
                "Cube",
                "Spectrum",
                "Spectral Cube",
                "Image",
                "Map",
                "Volume",
                "Time Series",
                "Dynamic Spectrum",
                "Catalog",
                "Spatial Vector"
              ],
              "description": "Type of the data product. This field is mandatory."
            },
            "processing:level": {
              "type": "string",
              "enum": [
                "Ancillary",
                "Raw",
                "Calibrated",
                "Derived"
              ],
              "description": "Processing level of the data product. This field is mandatory."
            }
          }
        },
        "license": {
          "type": "string",
          "description": "License under which the data is provided."
        }
      }
    }
  }
}