{
  "$schema": "<https://json-schema.org/draft/2020-12/schema>",
  "$id": "<https://gluex.org/schemas/rucio-dataset-metadata.json>",
  "title": "GlueX Rucio Dataset Metadata Schema",
  "type": "object",
  "additionalProperties": false,
  "required": ["data_tier", "run_period", "datatype"],
  "properties": {
    "data_tier": {
      "type": "string",
      "enum": ["raw", "recon", "analysis"]
    },
    "run_period": {
      "type": "string",
      "pattern": "^RunPeriod-[0-9]{4}-[0-9]{2}$"
    },
    "run_number": {
      "type": "integer",
      "minimum": 0
    },
    "datatype": {
      "type": "string",
      "enum": ["evio", "hddm", "root"]
    },
    "production_tag": {
      "type": "string",
      "pattern": "^ver[0-9]{2}$",
      "description": "Version tag used for reconstructed data (e.g., ver01)"
    },
    "analysis": {
      "type": "object",
      "additionalProperties": false,
      "required": ["analysis_channel"],
      "properties": {
        "analysis_channel": { "type": "string" },
        "reaction": { "type": "string" },
        "analysis_level": {
          "type": "string",
          "enum": ["merged", "skim", "ntuple", "hist"]
        }
      }
    }
  },
  "allOf": [
    {
      "if": { "properties": { "data_tier": { "const": "recon" } } },
      "then": { "required": ["production_tag"] }
    },
    {
      "if": { "properties": { "data_tier": { "const": "analysis" } } },
      "then": { "required": ["analysis", "production_tag"] }
    }
  ]
}