{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jarvis.local/schemas/health-risk-snapshot.schema.json",
  "title": "Health Risk Snapshot",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "generated_at", "overall_status", "domains", "data_freshness"],
  "properties": {
    "schema_version": { "const": "1.0" },
    "generated_at": { "type": "string", "format": "date-time" },
    "overall_status": { "$ref": "#/$defs/risk_status" },
    "domains": {
      "type": "array",
      "minItems": 6,
      "maxItems": 6,
      "prefixItems": [
        { "$ref": "#/$defs/behcet_activity" },
        { "$ref": "#/$defs/eye_risk" },
        { "$ref": "#/$defs/vascular_thrombosis_risk" },
        { "$ref": "#/$defs/inflammation_lab_trend" },
        { "$ref": "#/$defs/medication_safety" },
        { "$ref": "#/$defs/controls_data_status" }
      ],
      "items": false
    },
    "data_freshness": {
      "type": "object",
      "additionalProperties": false,
      "required": ["labs", "duplex", "eye_check", "dashboard"],
      "properties": {
        "labs": { "$ref": "#/$defs/freshness" },
        "duplex": { "$ref": "#/$defs/freshness" },
        "eye_check": { "$ref": "#/$defs/freshness" },
        "dashboard": { "enum": ["available", "missing", "unknown"] }
      }
    }
  },
  "$defs": {
    "risk_status": { "enum": ["green", "yellow", "red", "unknown"] },
    "action": { "enum": ["none", "watch", "contact_doctor", "urgent"] },
    "freshness": { "enum": ["fresh", "stale", "missing", "unknown"] },
    "domain_base": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "status", "reason", "action"],
      "properties": {
        "id": { "type": "string" },
        "label": { "type": "string" },
        "status": { "$ref": "#/$defs/risk_status" },
        "reason": { "type": "string", "maxLength": 48, "pattern": "^[A-Za-zÄÖÜäöüß0-9 _./:-]+$" },
        "action": { "$ref": "#/$defs/action" }
      }
    },
    "behcet_activity": { "allOf": [{ "$ref": "#/$defs/domain_base" }, { "properties": { "id": { "const": "behcet_activity" }, "label": { "const": "Behçet-Aktivität" } } }] },
    "eye_risk": { "allOf": [{ "$ref": "#/$defs/domain_base" }, { "properties": { "id": { "const": "eye_risk" }, "label": { "const": "Augen-Risiko" } } }] },
    "vascular_thrombosis_risk": { "allOf": [{ "$ref": "#/$defs/domain_base" }, { "properties": { "id": { "const": "vascular_thrombosis_risk" }, "label": { "const": "Gefässe/Thrombose" } } }] },
    "inflammation_lab_trend": { "allOf": [{ "$ref": "#/$defs/domain_base" }, { "properties": { "id": { "const": "inflammation_lab_trend" }, "label": { "const": "Entzündung/Labortrend" } } }] },
    "medication_safety": { "allOf": [{ "$ref": "#/$defs/domain_base" }, { "properties": { "id": { "const": "medication_safety" }, "label": { "const": "Medikamenten-Sicherheit" } } }] },
    "controls_data_status": { "allOf": [{ "$ref": "#/$defs/domain_base" }, { "properties": { "id": { "const": "controls_data_status" }, "label": { "const": "Kontrollen & Datenstatus" } } }] }
  }
}
