{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "CephalometricTracing",
  "type": "object",
  "required": ["imageId", "gender", "landmarks", "analysisGroups"],
  "properties": {
    "imageId": {
      "type": "string"
    },
    "gender": {
      "type": "string",
      "enum": ["male", "female", "other"]
    },
    "landmarks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "label", "x", "y"],
        "properties": {
          "id": { "type": "string" },
          "label": { "type": "string" },
          "x": { "type": "number" },
          "y": { "type": "number" }
        }
      }
    },
    "analysisGroups": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "description", "analyses", "curves"],
        "properties": {
          "name": { "type": "string" },
          "description": { "type": "string" },
          "analyses": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["id", "type", "description", "points", "value", "unit", "norm"],
              "properties": {
                "id": { "type": "string" },
                "type": { "type": "string", "enum": ["angle", "length", "ratio"] },
                "description": { "type": "string" },
                "points": {
                  "type": "array",
                  "items": { "type": "string" },
                  "minItems": 2
                },
                "vertex": { "type": "string" },
                "arms": {
                  "type": "array",
                  "items": { "type": "string" },
                  "minItems": 2,
                  "maxItems": 2
                },
                "value": { "type": "number" },
                "unit": { "type": "string" },
                "norm": {
                  "type": "object",
                  "required": ["reference", "mean", "std_dev", "range", "unit", "interpretation"],
                  "properties": {
                    "reference": { "type": "string" },
                    "mean": { "type": "number" },
                    "std_dev": { "type": "number" },
                    "range": {
                      "type": "array",
                      "items": { "type": "number" },
                      "minItems": 2,
                      "maxItems": 2
                    },
                    "unit": { "type": "string" },
                    "interpretation": { "type": "string" }
                  }
                }
              }
            }
          },
          "curves": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["id", "description", "type", "algorithm", "closed", "points"],
              "properties": {
                "id": { "type": "string" },
                "description": { "type": "string" },
                "type": { "type": "string", "enum": ["curve"] },
                "algorithm": { "type": "string", "enum": ["spline", "bezier", "linear"] },
                "closed": { "type": "boolean" },
                "points": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "string" },
                      "x": { "type": "number" },
                      "y": { "type": "number" }
                    },
                    "oneOf": [
                      { "required": ["id"] },
                      { "required": ["x", "y"] }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
