{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://veydrin.codeberg.page/protocols/opds/opds-v1.0.schema.json",
  "title": "OPDS v1.0 schema",
  "description": "Open Permaculture Data Standard, a VODS domain specialization. Every OPDS document is also a valid VODS document.",
  "allOf": [
    {
      "$ref": "https://veydrin.codeberg.page/protocols/vods/vods-v1.0.schema.json"
    },
    {
      "type": "object",
      "required": [
        "opds_version"
      ],
      "anyOf": [
        {
          "required": [
            "plantings"
          ]
        },
        {
          "required": [
            "observations"
          ]
        },
        {
          "required": [
            "harvests"
          ]
        },
        {
          "required": [
            "guilds"
          ]
        }
      ],
      "properties": {
        "opds_version": {
          "type": "string",
          "pattern": "^1\\.[0-9]+$"
        },
        "extensions": {
          "type": "object"
        },
        "plantings": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "planting_date",
              "species"
            ],
            "properties": {
              "planting_ref": {
                "type": "string"
              },
              "site_ref": {
                "type": "string"
              },
              "planting_date": {
                "type": "string",
                "format": "date"
              },
              "species": {
                "type": "string"
              },
              "common_name": {
                "type": "string"
              },
              "layer": {
                "type": "string",
                "enum": [
                  "canopy",
                  "understory",
                  "shrub",
                  "herbaceous",
                  "groundcover",
                  "root",
                  "vine",
                  "aquatic",
                  "fungal"
                ]
              },
              "guild_ref": {
                "type": "string"
              },
              "zone": {
                "type": "integer",
                "minimum": 0,
                "maximum": 5
              },
              "propagation": {
                "type": "string",
                "enum": [
                  "seed",
                  "seedling",
                  "cutting",
                  "division",
                  "graft",
                  "transplant",
                  "other"
                ]
              },
              "quantity": {
                "type": "integer",
                "minimum": 0
              },
              "coordinates": {
                "type": "object",
                "properties": {
                  "lat": {
                    "type": "number"
                  },
                  "lon": {
                    "type": "number"
                  }
                }
              },
              "region": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              }
            }
          }
        },
        "observations": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "observation_date"
            ],
            "properties": {
              "observation_date": {
                "type": "string",
                "format": "date"
              },
              "subject": {
                "type": "string",
                "enum": [
                  "guild",
                  "planting",
                  "system",
                  "wildlife",
                  "soil",
                  "water",
                  "other"
                ]
              },
              "guild_type": {
                "type": "string"
              },
              "layer": {
                "type": "string",
                "enum": [
                  "canopy",
                  "understory",
                  "shrub",
                  "herbaceous",
                  "groundcover",
                  "root",
                  "vine",
                  "aquatic",
                  "fungal"
                ]
              },
              "succession_state": {
                "type": "string",
                "enum": [
                  "bare_ground",
                  "pioneer",
                  "early_succession",
                  "mid_succession",
                  "late_succession",
                  "climax"
                ]
              },
              "functions_observed": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "health": {
                "type": "string",
                "enum": [
                  "thriving",
                  "healthy",
                  "stressed",
                  "declining",
                  "dead"
                ]
              },
              "planting_ref": {
                "type": "string"
              },
              "photo_ref": {
                "type": "string"
              },
              "coordinates": {
                "type": "object",
                "properties": {
                  "lat": {
                    "type": "number"
                  },
                  "lon": {
                    "type": "number"
                  }
                }
              },
              "region": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              }
            }
          }
        },
        "harvests": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "harvest_date",
              "crop",
              "quantity",
              "unit"
            ],
            "properties": {
              "harvest_date": {
                "type": "string",
                "format": "date"
              },
              "crop": {
                "type": "string"
              },
              "quantity": {
                "type": "number"
              },
              "unit": {
                "type": "string",
                "enum": [
                  "kg",
                  "lb",
                  "g",
                  "oz",
                  "litre",
                  "gallon",
                  "count",
                  "bunch"
                ]
              },
              "planting_ref": {
                "type": "string"
              },
              "guild_ref": {
                "type": "string"
              },
              "notes": {
                "type": "string"
              }
            }
          }
        },
        "guilds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "guild_id",
              "name"
            ],
            "properties": {
              "guild_id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "functions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "members": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "species"
                  ],
                  "properties": {
                    "species": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string"
                    },
                    "layer": {
                      "type": "string",
                      "enum": [
                        "canopy",
                        "understory",
                        "shrub",
                        "herbaceous",
                        "groundcover",
                        "root",
                        "vine",
                        "aquatic",
                        "fungal"
                      ]
                    }
                  }
                }
              },
              "notes": {
                "type": "string"
              }
            }
          }
        }
      },
      "additionalProperties": true
    }
  ]
}