{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://veydrin.codeberg.page/protocols/ohds/ohds-v1.0.schema.json",
  "title": "OHDS v1.0 — Open Hive Data Standard",
  "description": "Schema for beekeeping citizen science data exports. Builds on the VODS v1.0 envelope.",
  "type": "object",
  "required": ["vods_version", "export_id", "export_date", "export_mode", "ohds_version"],
  "anyOf": [
    { "required": ["inspections"] },
    { "required": ["apiary_summary"] }
  ],
  "properties": {
    "vods_version": { "type": "string", "pattern": "^1\\.[0-9]+$" },
    "export_id": { "type": "string", "format": "uuid" },
    "export_date": { "type": "string", "format": "date-time" },
    "export_mode": { "type": "string", "enum": ["anonymous", "tracked"] },
    "ohds_version": { "type": "string", "pattern": "^1\\.[0-9]+$" },
    "extensions": { "type": "object", "additionalProperties": { "type": "object" } },
    "inspections": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["inspection_date", "apiary_ref", "hive_ref", "colony_status"],
        "properties": {
          "inspection_date": { "type": "string", "format": "date" },
          "apiary_ref": { "type": "string" },
          "hive_ref": { "type": "string" },
          "colony_status": { "type": "string", "enum": ["alive", "dead", "absconded", "lost_queen", "split", "merged"] },
          "hive_type": { "type": "string", "enum": ["langstroth", "top_bar", "warre", "flow", "long", "skep", "other"] },
          "bee_race": { "type": "string", "enum": ["italian", "carniolan", "russian", "buckfast", "caucasian", "local_mutt", "africanized", "unknown", "other"] },
          "brood_pattern": { "type": "string", "enum": ["solid", "spotty", "none"] },
          "queen_seen": { "type": "boolean" },
          "queen_status": { "type": "string", "enum": ["present", "missing", "replaced", "supercedure", "unknown"] },
          "frames_of_bees": { "type": "number", "minimum": 0 },
          "frames_of_brood": { "type": "number", "minimum": 0 },
          "frames_of_honey": { "type": "number", "minimum": 0 },
          "varroa_count": { "type": "number", "minimum": 0 },
          "varroa_method": { "type": "string", "enum": ["alcohol_wash", "sugar_roll", "sticky_board", "drone_uncapping"] },
          "treatments": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["product", "method"],
              "properties": {
                "product": { "type": "string" },
                "method": { "type": "string", "enum": ["vaporization", "strip", "drizzle", "drench", "dusting", "fogger", "feed_additive", "other"] },
                "date_start": { "type": "string", "format": "date" },
                "date_end": { "type": "string", "format": "date" }
              },
              "additionalProperties": false
            }
          },
          "feeding": {
            "type": "object",
            "required": ["type", "quantity_kg"],
            "properties": {
              "type": { "type": "string", "enum": ["sugar_syrup_1:1", "sugar_syrup_2:1", "dry_sugar", "candy", "pollen_sub", "other"] },
              "quantity_kg": { "type": "number", "minimum": 0 }
            },
            "additionalProperties": false
          },
          "weight_kg": { "type": "number", "minimum": 0 },
          "temperature_c": { "type": "number" },
          "weather": { "type": "string", "enum": ["sunny", "partly_cloudy", "overcast", "rain", "wind"] },
          "notes": { "type": "string" },
          "coordinates": {
            "type": "object",
            "required": ["lat", "lon"],
            "properties": {
              "lat": { "type": "number", "minimum": -90, "maximum": 90 },
              "lon": { "type": "number", "minimum": -180, "maximum": 180 }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    },
    "apiary_summary": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["apiary_ref", "season", "year", "colonies_start", "colonies_end"],
        "properties": {
          "apiary_ref": { "type": "string" },
          "season": { "type": "string", "enum": ["winter", "spring", "summer", "fall", "annual"] },
          "year": { "type": "string" },
          "season_start": { "type": "string", "format": "date" },
          "season_end": { "type": "string", "format": "date" },
          "colonies_start": { "type": "integer", "minimum": 0 },
          "colonies_end": { "type": "integer", "minimum": 0 },
          "lost_dead": { "type": "integer", "minimum": 0 },
          "lost_queen": { "type": "integer", "minimum": 0 },
          "lost_disaster": { "type": "integer", "minimum": 0 },
          "new_purchased": { "type": "integer", "minimum": 0 },
          "new_splits": { "type": "integer", "minimum": 0 },
          "colonies_sold": { "type": "integer", "minimum": 0 },
          "perceived_loss_causes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": ["varroa", "nosema", "pesticides", "starvation", "weather", "ccd", "weak_fall", "queen_failure", "other", "unknown"]
            }
          },
          "operation_size": { "type": "string", "enum": ["backyard", "sideline", "commercial"] },
          "migratory": { "type": "boolean" },
          "region": { "type": "string" }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": true
}
