{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://veydrin.codeberg.page/protocols/oceads/oceads-v1.0.schema.json",
  "title": "OCEADS v1.0, Open Controlled Environment Agriculture Data Standard",
  "description": "Schema for soilless cultivation data exports. Builds on the VODS v1.0 envelope.",
  "allOf": [
    {
      "$ref": "https://veydrin.codeberg.page/protocols/vods/vods-v1.0.schema.json"
    },
    {
      "type": "object",
      "required": [
        "oceads_version"
      ],
      "anyOf": [
        {
          "required": [
            "grow_cycles"
          ]
        },
        {
          "required": [
            "environment_logs"
          ]
        },
        {
          "required": [
            "nutrient_logs"
          ]
        },
        {
          "required": [
            "harvests"
          ]
        }
      ],
      "properties": {
        "oceads_version": {
          "type": "string",
          "pattern": "^1\\.[0-9]+$"
        },
        "extensions": {
          "type": "object",
          "additionalProperties": {
            "type": "object"
          }
        },
        "grow_cycles": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "cycle_ref",
              "system_ref",
              "system_type",
              "start_date",
              "cultivar"
            ],
            "properties": {
              "cycle_ref": {
                "type": "string"
              },
              "system_ref": {
                "type": "string"
              },
              "system_type": {
                "type": "string",
                "enum": [
                  "hydroponic",
                  "aeroponic",
                  "fogponic",
                  "kratky",
                  "aquaponic",
                  "bio_integrated",
                  "hybrid"
                ]
              },
              "start_date": {
                "type": "string",
                "format": "date"
              },
              "end_date": {
                "type": "string",
                "format": "date"
              },
              "cultivar": {
                "type": "string"
              },
              "substrate": {
                "type": "string",
                "enum": [
                  "rockwool",
                  "clay_pebbles",
                  "coco_coir",
                  "perlite",
                  "vermiculite",
                  "nutrient_film",
                  "deep_water",
                  "air",
                  "other"
                ]
              },
              "grow_area_sqcm": {
                "type": "number",
                "minimum": 0
              },
              "plant_count": {
                "type": "integer",
                "minimum": 0
              },
              "photoperiod_hours": {
                "type": "number",
                "minimum": 0,
                "maximum": 24
              },
              "light_spectrum": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "light_intensity_umol": {
                "type": "number",
                "minimum": 0
              },
              "cycle_notes": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "environment_logs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "cycle_ref",
              "logged_at"
            ],
            "properties": {
              "cycle_ref": {
                "type": "string"
              },
              "logged_at": {
                "type": "string",
                "format": "date-time"
              },
              "air_temp_c": {
                "type": "number"
              },
              "humidity_rh": {
                "type": "number",
                "minimum": 0,
                "maximum": 100
              },
              "co2_ppm": {
                "type": "number",
                "minimum": 0
              },
              "vpd_kpa": {
                "type": "number",
                "minimum": 0
              },
              "par_umol": {
                "type": "number",
                "minimum": 0
              },
              "dli_mol": {
                "type": "number",
                "minimum": 0
              },
              "root_zone_temp_c": {
                "type": "number"
              },
              "substrate_moisture_pct": {
                "type": "number",
                "minimum": 0,
                "maximum": 100
              },
              "canopy_photosynthesis_umol": {
                "type": "number"
              },
              "o2_ppm": {
                "type": "number",
                "minimum": 0
              },
              "water_consumption_ml": {
                "type": "number",
                "minimum": 0
              }
            },
            "additionalProperties": false
          }
        },
        "nutrient_logs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "cycle_ref",
              "logged_at"
            ],
            "properties": {
              "cycle_ref": {
                "type": "string"
              },
              "logged_at": {
                "type": "string",
                "format": "date-time"
              },
              "ec_ms": {
                "type": "number",
                "minimum": 0
              },
              "ph": {
                "type": "number",
                "minimum": 0,
                "maximum": 14
              },
              "tds_ppm": {
                "type": "number",
                "minimum": 0
              },
              "water_temp_c": {
                "type": "number"
              },
              "do_mg_l": {
                "type": "number",
                "minimum": 0
              },
              "reservoir_volume_l": {
                "type": "number",
                "minimum": 0
              },
              "top_off_volume_l": {
                "type": "number",
                "minimum": 0
              },
              "nutrient_brand": {
                "type": "string"
              },
              "nutrient_ratio": {
                "type": "string"
              },
              "adjustment_action": {
                "type": "string",
                "enum": [
                  "ph_up",
                  "ph_down",
                  "nutrient_add",
                  "water_add",
                  "reservoir_change",
                  "flush",
                  "none"
                ]
              },
              "nitrogen_ppm": {
                "type": "number",
                "minimum": 0
              },
              "phosphorus_ppm": {
                "type": "number",
                "minimum": 0
              },
              "potassium_ppm": {
                "type": "number",
                "minimum": 0
              },
              "calcium_ppm": {
                "type": "number",
                "minimum": 0
              },
              "log_notes": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "harvests": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "cycle_ref",
              "harvest_date",
              "harvest_type"
            ],
            "properties": {
              "cycle_ref": {
                "type": "string"
              },
              "harvest_date": {
                "type": "string",
                "format": "date"
              },
              "harvest_type": {
                "type": "string",
                "enum": [
                  "full",
                  "partial",
                  "cut_and_come_again",
                  "thinning"
                ]
              },
              "fresh_weight_g": {
                "type": "number",
                "minimum": 0
              },
              "dry_weight_g": {
                "type": "number",
                "minimum": 0
              },
              "yield_per_sqcm_g": {
                "type": "number",
                "minimum": 0
              },
              "days_to_harvest": {
                "type": "integer",
                "minimum": 0
              },
              "quality_rating": {
                "type": "string",
                "enum": [
                  "excellent",
                  "good",
                  "fair",
                  "poor"
                ]
              },
              "flavor_rating": {
                "type": "integer",
                "minimum": 1,
                "maximum": 5
              },
              "texture_rating": {
                "type": "integer",
                "minimum": 1,
                "maximum": 5
              },
              "microbial_test": {
                "type": "string",
                "enum": [
                  "pass",
                  "fail",
                  "not_tested"
                ]
              },
              "harvest_notes": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "aquatic_module": {
          "type": "object",
          "required": [
            "system_ref",
            "species"
          ],
          "properties": {
            "system_ref": {
              "type": "string"
            },
            "species": {
              "type": "string"
            },
            "stocking_density_kg_m3": {
              "type": "number",
              "minimum": 0
            },
            "tank_volume_l": {
              "type": "number",
              "minimum": 0
            },
            "tank_logs": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "logged_at"
                ],
                "properties": {
                  "logged_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "water_temp_c": {
                    "type": "number"
                  },
                  "ph": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 14
                  },
                  "do_mg_l": {
                    "type": "number",
                    "minimum": 0
                  },
                  "ammonia_ppm": {
                    "type": "number",
                    "minimum": 0
                  },
                  "nitrite_ppm": {
                    "type": "number",
                    "minimum": 0
                  },
                  "nitrate_ppm": {
                    "type": "number",
                    "minimum": 0
                  },
                  "fish_count": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "feed_g": {
                    "type": "number",
                    "minimum": 0
                  }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": true
    }
  ]
}
