{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/bicorder.schema.json",
  "title": "Protocol Bicorder",
  "description": "Schema for Protocol Bicorder diagnostic tool",
  "type": "object",
  "required": ["name", "version", "description", "author", "metadata", "diagnostic", "analysis"],
  "properties": {
    "name": {
      "type": "string",
      "description": "Name of the tool"
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "Semantic version number (major.minor.patch)"
    },
    "description": {
      "type": "string",
      "description": "Brief description of the tool"
    },
    "author": {
      "type": "string",
      "description": "Author of the tool"
    },
    "date_modified": {
      "type": ["string", "null"],
      "format": "date",
      "description": "Date when the document was last modified (ISO 8601 format: YYYY-MM-DD)"
    },
    "metadata": {
      "type": "object",
      "required": ["protocol", "analyst", "standpoint", "timestamp"],
      "properties": {
        "protocol": {
          "type": "string",
          "description": "Brief name of the protocol being analyzed"
        },
        "analyst": {
          "type": "string",
          "description": "Who is doing the analysis"
        },
        "standpoint": {
          "type": "string",
          "description": "The analyst's relationship to or perspective on the protocol"
        },
        "timestamp": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "Timestamp of the analysis (ISO 8601 format)"
        }
      }
    },
    "diagnostic": {
      "type": "array",
      "description": "Array of diagnostic sets",
      "items": {
        "type": "object",
        "required": ["set_name", "set_description", "gradients"],
        "properties": {
          "set_name": {
            "type": "string",
            "description": "Name of the diagnostic set"
          },
          "set_description": {
            "type": "string",
            "description": "Description of the diagnostic set"
          },
          "gradients": {
            "type": "array",
            "description": "Array of gradient measurements",
            "items": {
              "type": "object",
              "required": ["term_left", "term_left_description", "term_right", "term_right_description", "value", "citation"],
              "properties": {
                "term_left": {
                  "type": "string",
                  "description": "Left term of the gradient"
                },
                "term_left_description": {
                  "type": "string",
                  "description": "Description of the left term"
                },
                "term_right": {
                  "type": "string",
                  "description": "Right term of the gradient"
                },
                "term_right_description": {
                  "type": "string",
                  "description": "Description of the right term"
                },
                "value": {
                  "type": ["number", "null"],
                  "minimum": 1,
                  "maximum": 9,
                  "description": "Gradient value (1-9 scale, where 1 is left term and 9 is right term)"
                },
                "citation": {
                  "type": ["string", "null"],
                  "description": "Citation or evidence for better understanding this gradient"
                }
              }
            }
          }
        }
      }
    },
    "analysis": {
      "type": "array",
      "description": "Array of analytical measures derived from the diagnostics",
      "items": {
        "type": "object",
        "required": ["term_left", "term_left_description", "term_right", "term_right_description", "instructions", "value", "citation"],
        "properties": {
          "term_left": {
            "type": "string",
            "description": "Left term of the analytical gradient"
          },
          "term_left_description": {
            "type": "string",
            "description": "Description of the left term"
          },
          "term_right": {
            "type": "string",
            "description": "Right term of the analytical gradient"
          },
          "term_right_description": {
            "type": "string",
            "description": "Description of the right term"
          },
          "instructions": {
            "type": "string",
            "description": "Instructions for how to calculate this analytic"
          },
          "value": {
            "type": ["number", "null"],
            "description": "Calculated value of the analytic"
          },
          "citation": {
            "type": ["string", "null"],
            "description": "Citation or evidence for this analytic value"
          }
        }
      }
    }
  }
}
