{
  "$ref": "#/definitions/DecisionDAG",
  "definitions": {
    "DecisionDAG": {
      "type": "object",
      "properties": {
        "$schema_version": {
          "type": "string",
          "const": "1.0.0",
          "description": "Schema version pin — must be \"1.0.0\"."
        },
        "id": {
          "type": "string",
          "description": "Stable document UUID."
        },
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "locale": {
          "type": "string"
        },
        "mode": {
          "type": "string",
          "enum": [
            "decision",
            "elimination"
          ]
        },
        "entry": {
          "type": "string",
          "description": "ID of the starting question. Must be a key in `nodes`."
        },
        "questionOrder": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "outcomeOrder": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "image": {
          "type": "string",
          "description": "Hero image URL displayed above the tree title."
        },
        "description": {
          "type": "string",
          "description": "Short description displayed below the title."
        },
        "meta": {
          "type": "object",
          "properties": {
            "author": {
              "type": "string"
            },
            "created_at": {
              "type": "string"
            },
            "updated_at": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "tags": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "additionalProperties": false,
          "description": "Optional document metadata."
        },
        "nodes": {
          "type": "object",
          "additionalProperties": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string",
                    "const": "question"
                  },
                  "text": {
                    "type": "string"
                  },
                  "hint": {
                    "type": "string"
                  },
                  "input": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "binary",
                            "description": "Accepts exactly 'yes' or 'no'. Case-insensitive at runtime. Maps to yes/no edges on the question node."
                          },
                          "yes_label": {
                            "type": "string"
                          },
                          "no_label": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "type"
                        ],
                        "additionalProperties": false,
                        "description": "Yes/no question input."
                      },
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "choice",
                            "description": "Accepts one uppercase letter A–F corresponding to a defined option. The number of valid values equals the number of entries in the options array."
                          },
                          "options": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "value": {
                                  "type": "string"
                                },
                                "label": {
                                  "type": "string"
                                },
                                "description": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "value",
                                "label"
                              ],
                              "additionalProperties": false,
                              "description": "One option of a multiple-choice question."
                            }
                          }
                        },
                        "required": [
                          "type",
                          "options"
                        ],
                        "additionalProperties": false,
                        "description": "Multiple-choice question input (options A–F)."
                      }
                    ]
                  },
                  "edges": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "answer": {
                          "type": "string",
                          "description": "The answer value, e.g. 'yes', 'no', 'A'."
                        },
                        "next": {
                          "type": "string",
                          "description": "Target node ID — must match a key in the parent document's `nodes` map."
                        },
                        "label": {
                          "type": "string",
                          "description": "Display label for choice edges."
                        }
                      },
                      "required": [
                        "answer",
                        "next"
                      ],
                      "additionalProperties": false,
                      "description": "A single edge from a question to another node."
                    }
                  },
                  "routes": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "display": {
                    "type": "object",
                    "properties": {
                      "color": {
                        "type": "string"
                      },
                      "icon": {
                        "type": "string"
                      },
                      "position": {
                        "type": "object",
                        "properties": {
                          "x": {
                            "type": "number"
                          },
                          "y": {
                            "type": "number"
                          }
                        },
                        "required": [
                          "x",
                          "y"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "additionalProperties": false,
                    "description": "Optional rendering hints for visual representation."
                  },
                  "condition": {
                    "type": "object",
                    "properties": {
                      "questionId": {
                        "type": "string",
                        "description": "The question whose answer must match for this question to be shown."
                      },
                      "answer": {
                        "type": "string",
                        "description": "The specific answer value required (e.g. 'A', 'yes')."
                      }
                    },
                    "required": [
                      "questionId",
                      "answer"
                    ],
                    "additionalProperties": false,
                    "description": "Visibility predicate for a question (used in elimination mode)."
                  }
                },
                "required": [
                  "id",
                  "kind",
                  "text",
                  "input",
                  "edges"
                ],
                "additionalProperties": false,
                "description": "A question node — has user-visible text and outgoing edges."
              },
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string",
                    "const": "outcome"
                  },
                  "label": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string",
                    "description": "Machine-readable identifier."
                  },
                  "payload": {
                    "type": "object",
                    "additionalProperties": {}
                  },
                  "display": {
                    "$ref": "#/definitions/DecisionDAG/properties/nodes/additionalProperties/anyOf/0/properties/display",
                    "description": "Optional rendering hints for visual representation."
                  }
                },
                "required": [
                  "id",
                  "kind",
                  "label"
                ],
                "additionalProperties": false,
                "description": "A terminal outcome node — what the DAG resolves to."
              }
            ]
          },
          "description": "Map of node ID -> node definition."
        },
        "routes": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "question": {
                      "type": "string"
                    },
                    "answers": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "question",
                    "answers"
                  ],
                  "additionalProperties": false
                }
              },
              "outcomeId": {
                "type": "string"
              }
            },
            "required": [
              "path",
              "outcomeId"
            ],
            "additionalProperties": false,
            "description": "An explicit end-to-end path: a sequence of (question, answer) pairs that resolves to an outcome."
          },
          "description": "Optional documentation of explicit end-to-end paths through the tree. Informational only — the engine derives execution paths from question edges at runtime. Routes are not validated against edges and do not affect traversal."
        }
      },
      "required": [
        "$schema_version",
        "id",
        "entry",
        "nodes"
      ],
      "additionalProperties": false,
      "description": "A Decision DAG document — declarative description of a decision tree (questions, outcomes, and edges)."
    }
  },
  "$schema": "https://json-schema.org/draft/2019-09/schema#",
  "$id": "https://www.drawdecisiontree.com/decision-dag.schema.json",
  "title": "DecisionDAG",
  "x-execution": {
    "allow_cycles": false,
    "modes": {
      "decision": {
        "strategy": "single_path_deterministic",
        "traversal": "depth_first_from_entry",
        "stop_condition": "first_outcome_reached",
        "edge_resolution": "exact_answer_match"
      },
      "elimination": {
        "strategy": "progressive_set_reduction",
        "traversal": "all_eligible_questions",
        "stop_condition": "candidate_set_size_one_or_questions_exhausted",
        "edge_resolution": "answer_intersects_outcome_set",
        "conditional_visibility": "when_clause_on_prior_answer"
      }
    },
    "mode_field": "$.mode",
    "mode_default": "decision"
  }
}
