{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://polls.thermals.app/developers/survey.schema.json",
  "title": "Polls survey (format 1)",
  "description": "A Polls survey as a file: polls: 1, a title and questions. Unknown keys are errors. See https://polls.thermals.app/developers#yaml",
  "type": "object",
  "required": [
    "polls",
    "title",
    "questions"
  ],
  "additionalProperties": false,
  "properties": {
    "polls": {
      "const": 1,
      "title": "Format version",
      "description": "The survey format version. Always 1."
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "title": "Title",
      "description": "The survey's title, 1 to 200 characters."
    },
    "slug": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[a-z0-9](?:[a-z0-9-]{1,48}[a-z0-9])$",
      "minLength": 3,
      "maxLength": 50,
      "title": "Slug",
      "description": "The public link, /s/<slug>: 3 to 50 of a-z, 0-9 and -, not starting or ending with -. Left out, Polls picks a random one."
    },
    "description": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 2000,
      "title": "Description",
      "description": "Shown on the welcome screen. Up to 2000 characters."
    },
    "settings": {
      "$ref": "#/$defs/settings"
    },
    "defaults": {
      "type": [
        "object",
        "null"
      ],
      "title": "Defaults",
      "description": "Values every question gets unless it says otherwise.",
      "additionalProperties": false,
      "properties": {
        "required": {
          "type": [
            "boolean",
            "null"
          ],
          "title": "Required by default",
          "description": "true to make every question required unless it says required: false."
        }
      }
    },
    "scales": {
      "type": [
        "object",
        "null"
      ],
      "title": "Scales",
      "description": "Named choice lists, written once and used by any number of questions as choices: <name>. Names are 1 to 40 of a-z, 0-9 and _.",
      "propertyNames": {
        "pattern": "^[a-z0-9_]{1,40}$"
      },
      "additionalProperties": {
        "type": "array",
        "minItems": 2,
        "maxItems": 500,
        "items": {
          "$ref": "#/$defs/choice"
        },
        "title": "Scale",
        "description": "A list of choices: labels, \"id: label\" pairs, or { id, label }."
      }
    },
    "questions": {
      "type": [
        "array",
        "null"
      ],
      "maxItems": 100,
      "items": {
        "$ref": "#/$defs/question"
      },
      "title": "Questions",
      "description": "The questions, in order: 0 to 100 (at least 1 to publish)."
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9_]{1,40}$",
      "title": "Id",
      "description": "1 to 40 of a-z, 0-9 and _."
    },
    "label": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "title": "Label",
      "description": "What the taker sees, 1 to 200 characters."
    },
    "placeholder": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 100,
      "title": "Placeholder",
      "description": "Grey example text shown in the empty box. Up to 100 characters."
    },
    "allowOther": {
      "type": [
        "boolean",
        "null"
      ],
      "default": false,
      "title": "Allow other",
      "description": "true to add an \"Other\" box where the taker writes their own answer. Default false."
    },
    "choice": {
      "title": "Choice",
      "description": "A label (its id is made from it: \"Great Britain\" becomes great_britain), an \"id: label\" pair, or { id, label }.",
      "anyOf": [
        {
          "$ref": "#/$defs/label"
        },
        {
          "type": "object",
          "title": "id: label",
          "description": "One pair: the choice id, then its label.",
          "minProperties": 1,
          "maxProperties": 1,
          "propertyNames": {
            "pattern": "^[a-z0-9_]{1,40}$"
          },
          "additionalProperties": {
            "$ref": "#/$defs/label"
          }
        },
        {
          "type": "object",
          "title": "{ id, label }",
          "description": "The long form.",
          "required": [
            "label"
          ],
          "additionalProperties": false,
          "properties": {
            "id": {
              "$ref": "#/$defs/id"
            },
            "label": {
              "$ref": "#/$defs/label"
            }
          }
        }
      ]
    },
    "settings": {
      "type": [
        "object",
        "null"
      ],
      "title": "Settings",
      "description": "How the survey looks and when it stops. Anything left out takes the default.",
      "additionalProperties": false,
      "properties": {
        "welcome": {
          "title": "Welcome screen",
          "description": "false turns the welcome screen off; true (the default) or a mapping turns it on.",
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "enabled": {
                  "type": [
                    "boolean",
                    "null"
                  ],
                  "default": true,
                  "title": "Enabled",
                  "description": "Show the welcome screen. Default true."
                },
                "buttonLabel": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "minLength": 1,
                  "maxLength": 24,
                  "default": "Start",
                  "title": "Button label",
                  "description": "The start button, 1 to 24 characters. Default \"Start\"."
                }
              }
            }
          ]
        },
        "thankYou": {
          "type": [
            "object",
            "null"
          ],
          "title": "Thank-you screen",
          "description": "Shown after the last answer.",
          "additionalProperties": false,
          "properties": {
            "title": {
              "type": [
                "string",
                "null"
              ],
              "minLength": 1,
              "maxLength": 200,
              "default": "Thank you!",
              "title": "Title",
              "description": "1 to 200 characters. Default \"Thank you!\"."
            },
            "message": {
              "type": [
                "string",
                "null"
              ],
              "maxLength": 2000,
              "default": "Your answers are in.",
              "title": "Message",
              "description": "Up to 2000 characters. Default \"Your answers are in.\"."
            }
          }
        },
        "theme": {
          "type": [
            "object",
            "null"
          ],
          "title": "Theme",
          "description": "The accent colour and light or dark mode.",
          "additionalProperties": false,
          "properties": {
            "accent": {
              "type": [
                "string",
                "null"
              ],
              "pattern": "^#[0-9A-Fa-f]{6}$",
              "default": "#3D5AFE",
              "title": "Accent colour",
              "description": "A colour like \"#3D5AFE\". Quote it: in YAML an unquoted # starts a comment."
            },
            "mode": {
              "enum": [
                "light",
                "dark",
                null
              ],
              "default": "light",
              "title": "Mode",
              "description": "light or dark. Default light."
            }
          }
        },
        "showProgress": {
          "type": [
            "boolean",
            "null"
          ],
          "default": true,
          "title": "Show progress",
          "description": "Show the progress bar. Default true."
        },
        "closesAt": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,9})?)?(Z|[+-]\\d{2}:\\d{2})$",
          "title": "Closes at",
          "description": "Stop taking answers at this time: ISO 8601 with a time zone, such as 2027-01-31T17:00:00Z."
        },
        "maxResponses": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "maximum": 1000000,
          "title": "Most responses",
          "description": "Stop after this many answers, 1 to 1000000."
        }
      }
    },
    "question": {
      "type": "object",
      "title": "Question",
      "description": "One question. type and title are required; the other keys depend on the type. See https://polls.thermals.app/developers#yaml",
      "required": [
        "type",
        "title"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/id",
          "title": "Question id",
          "description": "The id answers and CSV columns are keyed by: 1 to 40 of a-z, 0-9 and _, unique in the survey. Left out, it becomes q<position>. Set it if you will ever re-import or compare results."
        },
        "type": {
          "enum": [
            "short_text",
            "long_text",
            "email",
            "number",
            "single_choice",
            "multiple_choice",
            "dropdown",
            "yes_no",
            "rating",
            "opinion_scale",
            "date",
            "statement"
          ],
          "title": "Question type",
          "description": "short_text: A line of text.\nlong_text: A paragraph of text.\nemail: An email address.\nnumber: A number, optionally between min and max.\nsingle_choice: One choice from a list, or the taker's own text if allowOther.\nmultiple_choice: One or more choices from a list.\ndropdown: One choice from a (long) list shown as a dropdown.\nyes_no: Yes or no.\nrating: Stars, 1 to steps.\nopinion_scale: A number from start to end, such as 0 to 10.\ndate: A calendar date.\nstatement: A screen of text between questions; never answered."
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "title": "Question",
          "description": "The question itself, 1 to 500 characters."
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 1000,
          "title": "Description",
          "description": "Shown under the title. Up to 1000 characters."
        },
        "required": {
          "type": [
            "boolean",
            "null"
          ],
          "title": "Required",
          "description": "true if the taker must answer. Defaults to defaults.required, else false. Ignored for statement."
        },
        "maxLength": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "maximum": 10000,
          "title": "Maximum length",
          "description": "short_text: 1 to 1000 (default 255); long_text: 1 to 10000 (default 5000)."
        },
        "placeholder": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 100,
          "title": "Placeholder",
          "description": "Grey example text shown in the empty box. Up to 100 characters."
        },
        "min": {
          "type": [
            "number",
            "null"
          ],
          "title": "Minimum",
          "description": "The smallest number accepted. Left out, there is none."
        },
        "max": {
          "type": [
            "number",
            "null"
          ],
          "title": "Maximum",
          "description": "The largest number accepted. Left out, there is none."
        },
        "integerOnly": {
          "type": [
            "boolean",
            "null"
          ],
          "default": false,
          "title": "Whole numbers only",
          "description": "true to accept only whole numbers. Default false."
        },
        "choices": {
          "title": "Choices",
          "description": "single_choice and multiple_choice: a list of 2 to 50 choices; dropdown: 2 to 500; or the name of a scale.",
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[a-z0-9_]{1,40}$",
              "title": "Scale name",
              "description": "The name of a scale defined under scales."
            },
            {
              "type": "array",
              "minItems": 2,
              "maxItems": 500,
              "items": {
                "$ref": "#/$defs/choice"
              }
            }
          ]
        },
        "allowOther": {
          "$ref": "#/$defs/allowOther"
        },
        "minSelections": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "title": "Fewest selections",
          "description": "The fewest choices a taker must pick (Other counts as one). Left out, one is enough."
        },
        "maxSelections": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "title": "Most selections",
          "description": "The most choices a taker may pick (Other counts as one). Left out, there is no limit."
        },
        "steps": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 3,
          "maximum": 10,
          "default": 5,
          "title": "Steps",
          "description": "How many stars, 3 to 10. Default 5."
        },
        "start": {
          "enum": [
            0,
            1,
            null
          ],
          "default": 0,
          "title": "Start",
          "description": "The lowest number, 0 or 1. Default 0."
        },
        "end": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 5,
          "maximum": 10,
          "default": 10,
          "title": "End",
          "description": "The highest number, 5 to 10. Default 10."
        },
        "labels": {
          "type": [
            "object",
            "null"
          ],
          "title": "End labels",
          "description": "Words shown under either end of the scale.",
          "additionalProperties": false,
          "properties": {
            "left": {
              "type": [
                "string",
                "null"
              ],
              "maxLength": 40,
              "title": "Left label",
              "description": "Under the lowest number, such as \"Not likely\". Up to 40 characters."
            },
            "right": {
              "type": [
                "string",
                "null"
              ],
              "maxLength": 40,
              "title": "Right label",
              "description": "Under the highest number, such as \"Very likely\". Up to 40 characters."
            }
          }
        },
        "buttonLabel": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1,
          "maxLength": 24,
          "default": "Continue",
          "title": "Button label",
          "description": "The button that moves on, 1 to 24 characters. Default \"Continue\"."
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "const": "short_text"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A short_text question: A line of text.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "maxLength": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1,
                "maximum": 1000,
                "default": 255,
                "title": "Maximum length",
                "description": "The most characters a taker may type, 1 to 1000. Default 255."
              },
              "placeholder": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 100,
                "title": "Placeholder",
                "description": "Grey example text shown in the empty box. Up to 100 characters."
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "long_text"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A long_text question: A paragraph of text.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "maxLength": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1,
                "maximum": 10000,
                "default": 5000,
                "title": "Maximum length",
                "description": "The most characters a taker may type, 1 to 10000. Default 5000."
              },
              "placeholder": {
                "$ref": "#/$defs/placeholder"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "email"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A email question: An email address.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "placeholder": {
                "$ref": "#/$defs/placeholder"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "number"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A number question: A number, optionally between min and max.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "min": {
                "type": [
                  "number",
                  "null"
                ],
                "title": "Minimum",
                "description": "The smallest number accepted. Left out, there is none."
              },
              "max": {
                "type": [
                  "number",
                  "null"
                ],
                "title": "Maximum",
                "description": "The largest number accepted. Left out, there is none."
              },
              "integerOnly": {
                "type": [
                  "boolean",
                  "null"
                ],
                "default": false,
                "title": "Whole numbers only",
                "description": "true to accept only whole numbers. Default false."
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "single_choice"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A single_choice question: One choice from a list, or the taker's own text if allowOther.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "choices": {
                "title": "Choices",
                "description": "The choices: a list of 2 to 50 (each a label, an \"id: label\" pair, or { id, label }), or the name of a scale defined under scales.",
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,40}$",
                    "title": "Scale name",
                    "description": "The name of a scale defined under scales."
                  },
                  {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 50,
                    "items": {
                      "$ref": "#/$defs/choice"
                    }
                  }
                ]
              },
              "allowOther": {
                "$ref": "#/$defs/allowOther"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "multiple_choice"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A multiple_choice question: One or more choices from a list.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "choices": {
                "title": "Choices",
                "description": "The choices: a list of 2 to 50 (each a label, an \"id: label\" pair, or { id, label }), or the name of a scale defined under scales.",
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,40}$",
                    "title": "Scale name",
                    "description": "The name of a scale defined under scales."
                  },
                  {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 50,
                    "items": {
                      "$ref": "#/$defs/choice"
                    }
                  }
                ]
              },
              "allowOther": {
                "$ref": "#/$defs/allowOther"
              },
              "minSelections": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1,
                "title": "Fewest selections",
                "description": "The fewest choices a taker must pick (Other counts as one). Left out, one is enough."
              },
              "maxSelections": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1,
                "title": "Most selections",
                "description": "The most choices a taker may pick (Other counts as one). Left out, there is no limit."
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "dropdown"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A dropdown question: One choice from a (long) list shown as a dropdown.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "choices": {
                "title": "Choices",
                "description": "The choices: a list of 2 to 500 (each a label, an \"id: label\" pair, or { id, label }), or the name of a scale defined under scales.",
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[a-z0-9_]{1,40}$",
                    "title": "Scale name",
                    "description": "The name of a scale defined under scales."
                  },
                  {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 500,
                    "items": {
                      "$ref": "#/$defs/choice"
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "yes_no"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A yes_no question: Yes or no.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "rating"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A rating question: Stars, 1 to steps.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "steps": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 3,
                "maximum": 10,
                "default": 5,
                "title": "Steps",
                "description": "How many stars, 3 to 10. Default 5."
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "opinion_scale"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A opinion_scale question: A number from start to end, such as 0 to 10.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "start": {
                "enum": [
                  0,
                  1,
                  null
                ],
                "default": 0,
                "title": "Start",
                "description": "The lowest number, 0 or 1. Default 0."
              },
              "end": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 5,
                "maximum": 10,
                "default": 10,
                "title": "End",
                "description": "The highest number, 5 to 10. Default 10."
              },
              "labels": {
                "type": [
                  "object",
                  "null"
                ],
                "title": "End labels",
                "description": "Words shown under either end of the scale.",
                "additionalProperties": false,
                "properties": {
                  "left": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 40,
                    "title": "Left label",
                    "description": "Under the lowest number, such as \"Not likely\". Up to 40 characters."
                  },
                  "right": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 40,
                    "title": "Right label",
                    "description": "Under the highest number, such as \"Very likely\". Up to 40 characters."
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "date"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A date question: A calendar date.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "statement"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "description": "A statement question: A screen of text between questions; never answered.",
            "additionalProperties": false,
            "properties": {
              "id": true,
              "type": true,
              "title": true,
              "description": true,
              "required": true,
              "buttonLabel": {
                "type": [
                  "string",
                  "null"
                ],
                "minLength": 1,
                "maxLength": 24,
                "default": "Continue",
                "title": "Button label",
                "description": "The button that moves on, 1 to 24 characters. Default \"Continue\"."
              }
            }
          }
        }
      ]
    }
  }
}
