# EOAP Schemas (c) 2024
# 
# EOAP Schemas is licensed under
# Creative Commons Attribution-ShareAlike 4.0 International.
#
# You should have received a copy of the license along with this work.
# If not, see <https://creativecommons.org/licenses/by-sa/4.0/>.

$base: "https://stacspec.org/schema#"
$namespaces:
  geojson: "https://geojson.org/schema#"
$graph:
- $import: https://raw.githubusercontent.com/eoap/schemas/refs/heads/main/geojson.yaml

# STAC Catalog
# https://raw.githubusercontent.com/radiantearth/stac-api-spec/refs/tags/v1.0.0/stac-spec/catalog-spec/json-schema/catalog.json

- name: Link
  type: record
  doc: |
    ""
  fields:
    class:
      type: string
      doc: "Always 'Link"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    href:
      type: string
      doc: |
        "Link reference"
    rel:
      type: string
      doc: |
        "Link relation type"
    type:
      type: string
      doc: |
        "Link type"
    title:
      type: string
      doc: |
        "Link title"

- name: Catalog
  type: record
  documentRoot: true
  doc: |
    "This object represents Catalogs in a SpatioTemporal Asset Catalog"
  fields:
    class:
      type: string
      doc: "Always 'STAC Catalog'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    stac_version:
      type: string
      doc: |
        "STAC version"
    stac_extensions:
      type: string[]
      doc: |
        "STAC extensions"
    type:
      type: string
      doc: |
        "Type of STAC entity, `Catalog` as constant"
    id:
      type: string
      doc: |
        "Identifier"
    title:
      type: string
      doc: |
        "Title"
    description:
      type: string
      doc: |
        "Description"
    links:
      type: Link[]
      doc: |
        "Links"

# STAC Collection
# https://raw.githubusercontent.com/radiantearth/stac-api-spec/refs/tags/v1.0.0/stac-spec/collection-spec/json-schema/collection.json

- name: Role
  type: enum
  symbols:
  - "producer"
  - "licensor"
  - "processor"
  - "host"

- name: Provider
  type: record
  doc: |
    "STAC Collection"
  fields:
    class:
      type: string
      doc: "Always 'Provider'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    name:
      type: string
      doc: "Organization name"
    description:
      type: string
      doc: "Organization description"
    roles:
      type: Role[]
      doc: "Organization roles"
    url:
      type: string
      doc: "Organization homepage"

- name: Spatial
  type: record
  doc: |
    "Spatial extent object"
  fields:
    class:
      type: string
      doc: "Always 'Spatial'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    bbox:
      type: double[][]
      doc: "Spatial extents"

- name: Temporal
  type: record
  doc: "Temporal extent object"
  fields:
    class:
      type: string
      doc: "Always 'Temporal'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    interval:
      type: string[][]
      doc: "Temporal extents"

- name: Extents
  type: record
  doc: |
    "Extents"
  fields:
    class:
      type: string
      doc: "Always 'Extents'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    spatial:
      type: Spatial
      doc: "Spatial extent object"
    temporal:
      type: Temporal
      doc: "Temporal extent object"

- name: Asset
  type: record
  extends: [BasicDescriptiveFields, DateTime, Instrument, Licensing, Provider]
  doc: |
    "This object represents Collections in a SpatioTemporal Asset Catalog"
  fields:
    class:
      type: string
      doc: "Always 'Asset'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    href:
      type: string
      doc: |
        "Asset reference"
    type:
      type: string
      doc: |
        "Asset type"
    roles:
      type: string[]
      doc: |
        "Asset roles"

- name: Collection
  type: record
  documentRoot: true
  doc: |
    "This object represents Collections in a SpatioTemporal Asset Catalog"
  fields:
    class:
      type: string
      doc: "Always 'STAC Collection'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    stac_version:
      type: string
      doc: |
        "STAC version"
    stac_extensions:
      type: string[]
      doc: |
        "STAC extensions"
    type:
      type: string
      doc: |
        "Type of STAC entity, `Collection` as constant"
    id:
      type: string
      doc: |
        "Identifier"
    title:
      type: string
      doc: |
        "Title"
    description:
      type: string
      doc: |
        "Description"
    keywords:
      type: string[]
      doc: |
        "Keywords"
    license:
      type: string
      doc: |
        "Collection License Name"
    providers:
      type: Provider[]
      doc: |
        "$property.value.title"
    extent:
      type: Extents
      doc: |
        "Extents"
    assets:
      type: Asset[]
      doc: |
        "Links to assets"
    links:
      type: Link[]
      doc: |
        "Links"
    summaries:
      type:
        - string[]
        - Range
      doc: |
        "$property.value.title"

- name: Range
  type: record
  doc: |
    ""
  fields:
    class:
      type: string
      doc: "Always 'Range'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    minimum:
      type: [int, string]
      doc: |
        "Minimum value"
    maximum:
      type: [int, string]
      doc: |
        "Maximum value"

# STAC Item
# https://raw.githubusercontent.com/radiantearth/stac-api-spec/refs/tags/v1.0.0/stac-spec/item-spec/json-schema/item.json

- name: BasicDescriptiveFields
  type: record
  doc: |
    "Basic Descriptive Fields"
  fields:
    class:
      type: string
      doc: "Always 'BasicDescriptiveFields'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    title:
      type: string
      doc: |
        "A human-readable title describing the Item."
    description:
      type: string {
      "title": "Item Description"
      doc: |
        "Detailed multi-line description to fully explain the Item."

- name: DateTime
  type: record
  doc: |
    "Date and Time Fields"
  fields:
    class:
      type: string
      doc: "Always 'DateTime'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    datetime:
      type: string
      doc: |
        "The searchable date/time of the assets, in UTC (Formatted in RFC 3339)"
    start_datetime:
      type: string
      doc: |
        "The searchable start date/time of the assets, in UTC (Formatted in RFC 3339)"
    end_datetime:
      type: string
      doc: |
        "The searchable end date/time of the assets, in UTC (Formatted in RFC 3339)"
    created:
      type: string
      doc: |
        "Creation Time"
    updated:
      type: string
      doc: |
        "Last Update Time"

- name: Instrument
  type: record
  doc: |
    "Instrument Fields"
  fields:
    class:
      type: string
      doc: "Always 'Instrument'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    platform:
      type: string
      doc: |
        "Platform"
    instruments:
      type: string[]
      doc: |
        "Instruments"
    constellation:
      type: string
      doc: |
        "Constellation"
    mission:
      type: string
      doc: |
        "Mission"
    gsd:
      type: int
      doc: |
        "Ground Sample Distance"

- name: Licensing
  type: record
  doc: |
    "Licensing Fields"
  fields:
    class:
      type: string
      doc: "Always 'Licensing'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    license:
      type: string
      doc: |
        "License"

- name: Item
  type: record
  extends: [geojson:Feature, BasicDescriptiveFields, DateTime, Instrument, Licensing, Provider]
  documentRoot: true
  doc: |
    "This object represents the metadata for an item in a SpatioTemporal Asset Catalog"
  fields:
    class:
      type: string
      doc: "Always 'STAC Item'"
      jsonldPredicate:
        "_id": "@type"
        "_type": "@vocab"
    stac_version:
      type: string
      doc: |
        "STAC version"
    stac_extensions:
      type: string[]
      doc: |
        "STAC extensions"
    collection:
      type: string
      doc: |
        "The ID of the STAC Collection this Item references to."
    links:
      type: Link[]
      doc: |
        "Links"
    assets:
      type: Asset[]