{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://baxly.brc.com/survey-definition/schema.json",
  "title": "Baxly Survey Definition (baxly-survey/1.0)",
  "description": "A complete survey for Baxly (baxly.brc.com). The rule book at https://baxly.brc.com/survey-definition/rulebook.md is the authority; this schema covers shapes and ranges, and the Baxly validator also checks references, ordering, plan limits and text safety.",
  "type": "object",
  "required": [
    "format",
    "survey",
    "pages"
  ],
  "properties": {
    "format": {
      "const": "baxly-survey/1.0"
    },
    "notes": {
      "type": "string",
      "description": "For the person reviewing the file. Not shown to respondents."
    },
    "review": {
      "type": "object",
      "description": "Optional notes for the person reviewing the draft, shown on the import screen. applied: short plain-language lines on what you set up (max 12, 300 characters each). check: items to look at, each optionally pinned to a question or page key so Baxly can open it (max 12).",
      "additionalProperties": false,
      "properties": {
        "applied": {
          "type": "array",
          "maxItems": 12,
          "items": {
            "type": "string",
            "maxLength": 300
          }
        },
        "check": {
          "type": "array",
          "maxItems": 12,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "note"
            ],
            "properties": {
              "note": {
                "type": "string",
                "maxLength": 300
              },
              "question": {
                "type": "string"
              },
              "page": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "survey": {
      "$ref": "#/$defs/survey"
    },
    "lists": {
      "type": "array",
      "maxItems": 20,
      "items": {
        "$ref": "#/$defs/list"
      }
    },
    "pages": {
      "type": "array",
      "minItems": 1,
      "maxItems": 60,
      "items": {
        "$ref": "#/$defs/page"
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "survey": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "intro": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "headline": {
              "type": "string",
              "maxLength": 200
            },
            "body": {
              "type": "string",
              "maxLength": 20000,
              "description": "Text. Allowed HTML only (see the rule book, section 2)."
            },
            "minutes": {
              "type": "integer",
              "minimum": 0,
              "maximum": 20
            },
            "button_text": {
              "type": "string",
              "maxLength": 50
            },
            "image_url": {
              "type": "string",
              "pattern": "^https://",
              "maxLength": 500
            },
            "consent": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "required": [
                    "text"
                  ],
                  "properties": {
                    "text": {
                      "type": "string",
                      "maxLength": 20000,
                      "description": "Text. Allowed HTML only (see the rule book, section 2)."
                    },
                    "enabled": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false
                }
              ]
            }
          },
          "additionalProperties": false
        },
        "variables": {
          "type": "array",
          "maxItems": 50,
          "items": {
            "type": "object",
            "required": [
              "name",
              "value"
            ],
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[A-Za-z0-9 _-]{1,50}$"
              },
              "value": {
                "type": "string",
                "maxLength": 500,
                "description": "Text. Allowed HTML only (see the rule book, section 2)."
              }
            },
            "additionalProperties": false
          }
        },
        "variable_rules": {
          "type": "array",
          "maxItems": 30,
          "items": {
            "type": "object",
            "required": [
              "name",
              "value",
              "when"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "value": {
                "type": "string",
                "maxLength": 500,
                "description": "Text. Allowed HTML only (see the rule book, section 2)."
              },
              "when": {
                "$ref": "#/$defs/condition"
              }
            },
            "additionalProperties": false
          }
        },
        "experiment": {
          "type": "object",
          "required": [
            "variants"
          ],
          "properties": {
            "variants": {
              "type": "array",
              "minItems": 2,
              "maxItems": 4,
              "items": {
                "type": "object",
                "required": [
                  "key"
                ],
                "properties": {
                  "key": {
                    "enum": [
                      "a",
                      "b",
                      "c",
                      "d"
                    ]
                  },
                  "label": {
                    "type": "string",
                    "maxLength": 60
                  }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        },
        "theme": {
          "type": "object",
          "properties": {
            "style": {
              "enum": [
                "cards",
                "sharp",
                "airy",
                "compact",
                "pills"
              ]
            },
            "font": {
              "enum": [
                "system",
                "arial",
                "verdana",
                "georgia",
                "trebuchet"
              ]
            },
            "instructions": {
              "enum": [
                "auto",
                "all",
                "off"
              ]
            },
            "width": {
              "enum": [
                "compact",
                "standard",
                "wide",
                "xwide"
              ]
            },
            "guide": {
              "enum": [
                "subtle",
                "bold",
                "spotlight",
                "minimal"
              ]
            },
            "topbar": {
              "enum": [
                "full",
                "bar",
                "title",
                "off"
              ]
            },
            "primary": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "primaryStrong": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "primary600": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "accent": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "desk": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "deep": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "done": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "matrixDone": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            },
            "matrixAlt": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{6}$"
            }
          },
          "additionalProperties": false
        },
        "show_page_titles": {
          "type": "boolean"
        },
        "layout": {
          "enum": [
            "default",
            "navigator"
          ]
        },
        "completion_form": {
          "type": "object",
          "required": [
            "fields"
          ],
          "properties": {
            "heading": {
              "type": "string",
              "maxLength": 200
            },
            "note": {
              "type": "string",
              "maxLength": 2000,
              "description": "Text. Allowed HTML only (see the rule book, section 2)."
            },
            "button": {
              "type": "string",
              "maxLength": 50
            },
            "fields": {
              "type": "array",
              "minItems": 1,
              "maxItems": 12,
              "items": {
                "$ref": "#/$defs/field"
              }
            }
          },
          "additionalProperties": false
        },
        "incentive": {
          "type": "object",
          "required": [
            "description"
          ],
          "properties": {
            "type": {
              "enum": [
                "contest",
                "guaranteed"
              ]
            },
            "description": {
              "type": "string",
              "maxLength": 300
            },
            "amount": {
              "type": "number",
              "minimum": 0,
              "maximum": 100000
            },
            "cap": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000000
            },
            "rules": {
              "type": "string",
              "maxLength": 200000,
              "description": "Text. Allowed HTML only (see the rule book, section 2)."
            }
          },
          "additionalProperties": false
        },
        "quotas": {
          "type": "array",
          "maxItems": 30,
          "items": {
            "type": "object",
            "required": [
              "name",
              "limit",
              "when"
            ],
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 200
              },
              "limit": {
                "type": "integer",
                "minimum": 1,
                "maximum": 1000000
              },
              "when": {
                "$ref": "#/$defs/condition"
              },
              "on_full": {
                "enum": [
                  "end",
                  "none"
                ]
              }
            },
            "additionalProperties": false
          }
        },
        "ai_target_responses": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "hide_branding": {
          "type": "boolean"
        },
        "logo_url": {
          "type": "string",
          "description": "Ignored: logos are uploaded in the builder."
        }
      },
      "additionalProperties": false
    },
    "list": {
      "type": "object",
      "required": [
        "name",
        "columns",
        "items"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[A-Za-z0-9 _-]{1,200}$"
        },
        "columns": {
          "type": "array",
          "minItems": 1,
          "maxItems": 12,
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9 _-]{1,50}$"
          }
        },
        "items": {
          "type": "array",
          "maxItems": 500,
          "items": {
            "type": "object",
            "additionalProperties": {
              "type": [
                "string",
                "number"
              ]
            }
          }
        }
      },
      "additionalProperties": false
    },
    "page": {
      "type": "object",
      "required": [
        "questions"
      ],
      "properties": {
        "key": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,39}$"
        },
        "title": {
          "type": "string",
          "maxLength": 400
        },
        "intro": {
          "type": "string",
          "maxLength": 20000,
          "description": "Text. Allowed HTML only (see the rule book, section 2)."
        },
        "questions": {
          "type": "array",
          "maxItems": 60,
          "items": {
            "$ref": "#/$defs/question"
          }
        },
        "loop": {
          "$ref": "#/$defs/loop"
        },
        "side_media": {
          "type": "object",
          "required": [
            "image"
          ],
          "properties": {
            "image": {
              "type": "string",
              "maxLength": 500
            },
            "position": {
              "enum": [
                "left",
                "right"
              ]
            },
            "caption": {
              "type": "string",
              "maxLength": 500,
              "description": "Text. Allowed HTML only (see the rule book, section 2)."
            },
            "zoom": {
              "type": "boolean"
            },
            "max_h": {
              "type": "integer",
              "minimum": 80,
              "maximum": 800
            }
          },
          "additionalProperties": false
        },
        "show_when": {
          "oneOf": [
            {
              "$ref": "#/$defs/condition"
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "items": {
                "$ref": "#/$defs/condition"
              }
            }
          ]
        },
        "hide_when": {
          "oneOf": [
            {
              "$ref": "#/$defs/condition"
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "items": {
                "$ref": "#/$defs/condition"
              }
            }
          ]
        },
        "end_when": {
          "oneOf": [
            {
              "$ref": "#/$defs/condition"
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 10,
              "items": {
                "$ref": "#/$defs/condition"
              }
            }
          ]
        },
        "end_message": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "object",
              "properties": {
                "headline": {
                  "type": "string",
                  "maxLength": 200
                },
                "body": {
                  "type": "string",
                  "maxLength": 4000,
                  "description": "Text. Allowed HTML only (see the rule book, section 2)."
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "complete_rule": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "when"
              ],
              "properties": {
                "when": {
                  "const": "any_answer"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "when",
                "condition"
              ],
              "properties": {
                "when": {
                  "const": "condition"
                },
                "condition": {
                  "$ref": "#/$defs/condition"
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "builder_note": {
          "type": "string",
          "maxLength": 4000
        }
      },
      "additionalProperties": false
    },
    "question": {
      "type": "object",
      "required": [
        "key",
        "type",
        "text"
      ],
      "properties": {
        "key": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,39}$"
        },
        "type": {
          "enum": [
            "select_one",
            "multi_select",
            "dropdown",
            "yes_no",
            "open_text",
            "email_capture",
            "number",
            "date",
            "scale",
            "nps",
            "star_rating",
            "note",
            "matrix",
            "ranking",
            "constant_sum",
            "percentage_sum",
            "image_choice",
            "heatmap",
            "slider",
            "contact_form",
            "file_upload",
            "ai_conversation",
            "maxdiff",
            "bestof"
          ]
        },
        "text": {
          "type": "string",
          "maxLength": 20000,
          "description": "Text. Allowed HTML only (see the rule book, section 2)."
        },
        "required": {
          "type": "boolean"
        },
        "code": {
          "type": "string",
          "maxLength": 100
        },
        "settings": {
          "type": "object",
          "description": "Per-type allowlist: the if/then branches under this question schema (allOf) list the settings each type accepts; the rule book section 7 explains them."
        },
        "choices": {
          "type": "array",
          "maxItems": 200,
          "items": {
            "$ref": "#/$defs/choice"
          }
        },
        "rows": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "string",
            "maxLength": 1000
          }
        },
        "choices_from": {
          "$ref": "#/$defs/listRef"
        },
        "rows_from": {
          "$ref": "#/$defs/listRef"
        },
        "links": {
          "type": "array",
          "maxItems": 50,
          "items": {
            "type": "object",
            "required": [
              "choice",
              "question"
            ],
            "properties": {
              "when": {
                "enum": [
                  "selected",
                  "deselected"
                ]
              },
              "choice": {
                "type": "string"
              },
              "action": {
                "enum": [
                  "select",
                  "clear"
                ]
              },
              "question": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,39}$"
              },
              "target_choice": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "loop": {
          "$ref": "#/$defs/loop"
        },
        "ai_followup": {
          "type": "object",
          "properties": {
            "goal": {
              "type": "string",
              "maxLength": 500
            },
            "max": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10
            },
            "min": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10
            }
          },
          "additionalProperties": false
        },
        "show_when": {
          "oneOf": [
            {
              "$ref": "#/$defs/condition"
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "items": {
                "$ref": "#/$defs/condition"
              }
            }
          ]
        },
        "hide_when": {
          "oneOf": [
            {
              "$ref": "#/$defs/condition"
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "items": {
                "$ref": "#/$defs/condition"
              }
            }
          ]
        },
        "fields": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "items": {
            "$ref": "#/$defs/field"
          }
        },
        "carry_forward": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "question"
              ],
              "additionalProperties": false,
              "properties": {
                "question": {
                  "type": "string"
                },
                "columns": {
                  "type": "array",
                  "minItems": 1,
                  "items": {
                    "type": "string"
                  }
                }
              }
            },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 6,
              "items": {
                "type": "object",
                "required": [
                  "question"
                ],
                "additionalProperties": false,
                "properties": {
                  "question": {
                    "type": "string"
                  },
                  "columns": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          ],
          "description": "Carried-in choices: this question's choices are the rows (marked with one of `columns`) or choices the respondent marked in the named earlier question(s), in that question's wording; a pick is recorded against the same item. Do not repeat those rows or choices here: `choices` holds only extras such as a \"None of these\" or an \"Other\" write-in, and may be omitted."
        }
      },
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "const": "select_one"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "randomize": {
                    "type": "boolean"
                  },
                  "ad_grid": {
                    "type": "boolean"
                  },
                  "zoom_image": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "tile_wide": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "tile_img_max_h": {
                    "type": "integer",
                    "minimum": 80,
                    "maximum": 800
                  },
                  "grid_scroll_rows": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "row_grid": {
                    "type": "boolean"
                  },
                  "image_mode": {
                    "enum": [
                      "zoom",
                      "show"
                    ]
                  },
                  "image_size": {
                    "enum": [
                      "small",
                      "medium",
                      "large"
                    ]
                  },
                  "image_position": {
                    "enum": [
                      "before",
                      "after"
                    ]
                  },
                  "layout": {
                    "enum": [
                      "gallery"
                    ]
                  },
                  "tools": {
                    "enum": [
                      "auto",
                      "on",
                      "off"
                    ]
                  },
                  "sort": {
                    "type": "string",
                    "maxLength": 50
                  },
                  "check_label": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "priority_from": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "priority_label": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "gallery_img_h": {
                    "type": "integer",
                    "minimum": 80,
                    "maximum": 600
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "multi_select"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "randomize": {
                    "type": "boolean"
                  },
                  "min_selections": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200
                  },
                  "max_selections": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200
                  },
                  "select_all": {
                    "type": "boolean"
                  },
                  "ad_grid": {
                    "type": "boolean"
                  },
                  "zoom_image": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "tile_wide": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "tile_img_max_h": {
                    "type": "integer",
                    "minimum": 80,
                    "maximum": 800
                  },
                  "grid_scroll_rows": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "image_mode": {
                    "enum": [
                      "zoom",
                      "show"
                    ]
                  },
                  "image_size": {
                    "enum": [
                      "small",
                      "medium",
                      "large"
                    ]
                  },
                  "image_position": {
                    "enum": [
                      "before",
                      "after"
                    ]
                  },
                  "layout": {
                    "enum": [
                      "gallery"
                    ]
                  },
                  "tools": {
                    "enum": [
                      "auto",
                      "on",
                      "off"
                    ]
                  },
                  "sort": {
                    "type": "string",
                    "maxLength": 50
                  },
                  "check_label": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "priority_from": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "priority_label": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "gallery_img_h": {
                    "type": "integer",
                    "minimum": 80,
                    "maximum": 600
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "dropdown"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "randomize": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "yes_no"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "yes_label": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "no_label": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "open_text"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "placeholder": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "multiline": {
                    "type": "boolean"
                  },
                  "validation": {
                    "enum": [
                      "phone",
                      "zip",
                      "email"
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "email_capture"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "number"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "min": {
                    "type": "number"
                  },
                  "max": {
                    "type": "number"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "date"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "scale"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "min": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "max": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100
                  },
                  "min_label": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "max_label": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "style": {
                    "enum": [
                      "smiley"
                    ]
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "slider"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "min": {
                    "type": "number"
                  },
                  "max": {
                    "type": "number"
                  },
                  "min_label": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "max_label": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "nps"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "min_label": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "max_label": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "star_rating"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "max": {
                    "type": "integer",
                    "minimum": 3,
                    "maximum": 10
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "note"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "hold": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "matrix"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "mode": {
                    "enum": [
                      "select_one",
                      "multi_select",
                      "number",
                      "text"
                    ]
                  },
                  "matrix_label_width": {
                    "type": "integer",
                    "minimum": 15,
                    "maximum": 60
                  },
                  "matrix_label_header": {
                    "type": "string",
                    "maxLength": 60
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "ranking"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "rank_count": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200
                  },
                  "randomize": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "constant_sum"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "total": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1000000
                  },
                  "randomize": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "percentage_sum"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "image_choice"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "multi": {
                    "type": "boolean"
                  },
                  "max_selections": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 200
                  },
                  "randomize": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "heatmap"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "image_url": {
                    "type": "string",
                    "pattern": "^https://",
                    "maxLength": 500
                  },
                  "max_clicks": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 20
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "contact_form"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "file_upload"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "ai_conversation"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "maxdiff"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "exposures": {
                    "type": "integer",
                    "minimum": 2,
                    "maximum": 5
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "bestof"
              }
            }
          },
          "then": {
            "properties": {
              "settings": {
                "type": "object",
                "properties": {
                  "instruction": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "helper_text": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "max_categories": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 12
                  },
                  "max_picks": {
                    "type": "integer",
                    "minimum": 2,
                    "maximum": 10
                  },
                  "min_picks": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "stage2": {
                    "enum": [
                      "auto",
                      "rank",
                      "maxdiff"
                    ]
                  },
                  "gate": {
                    "enum": [
                      "experience",
                      "none"
                    ]
                  },
                  "gate_text": {
                    "type": "string",
                    "maxLength": 300
                  },
                  "allow_other": {
                    "type": "boolean"
                  },
                  "browse": {
                    "type": "boolean"
                  },
                  "missed": {
                    "type": "boolean"
                  },
                  "missed_text": {
                    "type": "string",
                    "maxLength": 300
                  },
                  "why": {
                    "type": "boolean"
                  },
                  "why_text": {
                    "type": "string",
                    "maxLength": 300
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      ]
    },
    "choice": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        {
          "type": "object",
          "required": [
            "text"
          ],
          "properties": {
            "text": {
              "type": "string",
              "maxLength": 1000,
              "description": "Text. Allowed HTML only (see the rule book, section 2)."
            },
            "key": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,39}$"
            },
            "is_other": {
              "type": "boolean"
            },
            "placeholder": {
              "type": "string",
              "maxLength": 100
            },
            "exclusive": {
              "type": "boolean"
            },
            "select_all": {
              "type": "boolean"
            },
            "image_url": {
              "type": "string",
              "pattern": "^https://",
              "maxLength": 500
            },
            "image_mode": {
              "enum": [
                "zoom",
                "show"
              ]
            },
            "image_size": {
              "enum": [
                "small",
                "medium",
                "large"
              ]
            },
            "image_position": {
              "enum": [
                "before",
                "after"
              ]
            },
            "value": {
              "type": "string",
              "maxLength": 200
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "listRef": {
      "type": "object",
      "properties": {
        "list": {
          "type": "string"
        },
        "from_loop": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,39}$"
        },
        "label": {
          "type": "string"
        },
        "image": {
          "type": "string"
        },
        "wide": {
          "type": "string"
        },
        "page": {
          "type": "string"
        },
        "group": {
          "type": "string"
        },
        "columns": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "maxItems": 4
        }
      },
      "additionalProperties": false
    },
    "loop": {
      "type": "object",
      "properties": {
        "list": {
          "type": "string"
        },
        "from_loop": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,39}$"
        },
        "from_answers": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,39}$"
        },
        "sample": {
          "type": "object",
          "properties": {
            "mode": {
              "enum": [
                "all",
                "random",
                "balanced"
              ]
            },
            "count": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            },
            "by": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "order": {
          "enum": [
            "list",
            "list_reverse",
            "shuffle",
            "same"
          ]
        },
        "max": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200
        },
        "skip": {
          "type": "integer",
          "minimum": 0,
          "maximum": 200
        },
        "per_page": {
          "oneOf": [
            {
              "const": "all"
            },
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          ]
        },
        "per_page_variants": {
          "type": "object",
          "additionalProperties": {
            "oneOf": [
              {
                "const": "all"
              },
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 50
              }
            ]
          }
        },
        "reveal": {
          "type": "object",
          "required": [
            "batch"
          ],
          "properties": {
            "batch": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            },
            "label": {
              "type": "string"
            },
            "button": {
              "type": "string"
            },
            "nudge": {
              "type": "boolean"
            },
            "nudge_text": {
              "type": "string"
            },
            "mode": {
              "enum": [
                "button"
              ]
            }
          },
          "additionalProperties": false
        },
        "pin": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Accepted and ignored with a warning; pin items in the builder."
        }
      },
      "additionalProperties": false
    },
    "condition": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "all"
          ],
          "properties": {
            "all": {
              "type": "array",
              "minItems": 1,
              "maxItems": 20,
              "items": {
                "$ref": "#/$defs/test"
              }
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "any"
          ],
          "properties": {
            "any": {
              "type": "array",
              "minItems": 1,
              "maxItems": 20,
              "items": {
                "$ref": "#/$defs/test"
              }
            }
          },
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/test"
        }
      ]
    },
    "test": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "question",
            "selected"
          ],
          "properties": {
            "question": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,39}$"
            },
            "selected": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "question",
            "not_selected"
          ],
          "properties": {
            "question": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,39}$"
            },
            "not_selected": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "question",
            "not_answered"
          ],
          "properties": {
            "question": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,39}$"
            },
            "not_answered": {
              "const": true
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "question",
            "picked_more_than"
          ],
          "properties": {
            "question": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,39}$"
            },
            "picked_more_than": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "variable",
            "equals"
          ],
          "properties": {
            "variable": {
              "type": "string"
            },
            "equals": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "variable",
            "not_equals"
          ],
          "properties": {
            "variable": {
              "type": "string"
            },
            "not_equals": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "variant"
          ],
          "properties": {
            "variant": {
              "enum": [
                "a",
                "b",
                "c",
                "d"
              ]
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "variant_not"
          ],
          "properties": {
            "variant_not": {
              "enum": [
                "a",
                "b",
                "c",
                "d"
              ]
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "field": {
      "type": "object",
      "required": [
        "label"
      ],
      "properties": {
        "label": {
          "type": "string",
          "maxLength": 200
        },
        "type": {
          "enum": [
            "select",
            "checkbox"
          ]
        },
        "width": {
          "enum": [
            "half",
            "full"
          ]
        },
        "options": {
          "oneOf": [
            {
              "const": "countries"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              },
              "maxItems": 100
            }
          ]
        },
        "validation": {
          "enum": [
            "email",
            "phone",
            "zip",
            "match_prev"
          ]
        },
        "required": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    }
  },
  "x-limits": {
    "fileBytes": 2097152,
    "pages": 60,
    "questionsPerPage": 60,
    "questionsTotal": 400,
    "choices": 200,
    "rows": 100,
    "lists": 20,
    "listItems": 500,
    "listColumns": 12,
    "text": 20000,
    "choiceText": 1000,
    "rowText": 1000,
    "title": 400,
    "intro": 20000,
    "name": 300,
    "code": 100,
    "key": 40,
    "variables": 50,
    "varRules": 30,
    "quotas": 30,
    "conditions": 20,
    "logicRules": 20,
    "links": 50,
    "endRules": 10,
    "contactFields": 8,
    "completionFields": 12,
    "variants": 4
  }
}
