{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/domain-response.schema.json",
  "title": "Poll and Questionnaire local identifiers and keyed response values",
  "description": "Shared schema definitions. Descriptor ID uniqueness and domain eligibility are semantic checks; exactly $rb is reserved in these local ID positions.",
  "$defs": {
    "localId": {
      "allOf": [
        {"$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/text"},
        {"type": "string", "minLength": 1, "not": {"const": "$rb"}}
      ]
    },
    "pollOption": {
      "allOf": [{"$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"}],
      "type": "object",
      "properties": {"id": {"$ref": "#/$defs/localId"}, "label": {"type": "string"}},
      "required": ["id", "label"]
    },
    "question": {
      "allOf": [{"$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"}],
      "type": "object",
      "properties": {
        "id": {"$ref": "#/$defs/localId"},
        "label": {"type": "string"},
        "required": {"type": "boolean"},
        "type": {"enum": ["string", "number", "boolean", "array", "object", "null"]}
      },
      "required": ["id"]
    },
    "options": {"type": "array", "items": {"$ref": "#/$defs/pollOption"}},
    "questions": {"type": "array", "items": {"$ref": "#/$defs/question"}},
    "ratings": {
      "allOf": [{"$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"}],
      "type": "object",
      "propertyNames": {"$ref": "#/$defs/localId"},
      "additionalProperties": {"type": "number", "allOf": [{"if": {"type": "integer"}, "then": {"minimum": -9007199254740991, "maximum": 9007199254740991}}]}
    },
    "scores": {"$ref": "#/$defs/ratings"},
    "answers": {
      "allOf": [{"$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json#/$defs/map"}],
      "type": "object",
      "propertyNames": {"$ref": "#/$defs/localId"}
    }
  }
}
