{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jonashw.dev/alternatives/toolkit/requirements.schema.json",
  "title": "Requirements Elicitation Tool requirements set",
  "description": "A criteria set for https://jonashw.dev/alternatives/toolkit/requirements.html, pasted into 'Try it with your own criteria' or carried in a link as #data=<base64url of this JSON>. Three shapes: a plain list (title + criteria), one decision (add alternatives and scores), or a parent with parts (add parts). See toolkit/README.md, 'Try it with your own criteria'.",
  "type": "object",
  "required": ["title", "criteria"],
  "properties": {
    "title": { "$ref": "#/$defs/text", "description": "The page heading, such as \"Rank what matters for the team chat tool\"." },
    "key": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,39}$", "description": "Names where answers are saved in the viewer's browser. Give every real decision a key of its own and keep it each time the set is sent again (reworded, with requirements added, or with options and scores), so the owner's choices carry over. Without a key, answers are saved under a hash of the ids." },
    "question": { "$ref": "#/$defs/text", "description": "List only: the question on each pair. Default \"Which matters more to you?\"." },
    "more": { "$ref": "#/$defs/text", "description": "List only: as in \"Last time you said: X matters more\". Default \"matters more\"." },
    "noun": { "$ref": "#/$defs/text", "description": "List only: what the items are, plural. Default \"criteria\"." },
    "classify": { "const": true, "description": "For a list without alternatives: open with the Classify step (must-have, want, not sure, not needed) before any options exist. This is how a decision owner first meets draft requirements." },
    "sort": { "const": true, "description": "Older name for classify. Still read; write classify." },
    "questions": {
      "type": "array", "maxItems": 6, "description": "Optional. Other yes-or-no questions, asked in their own step on the Classify step, each answer saying what it does.",
      "items": { "type": "object", "required": ["id", "text", "a", "aMeans", "b", "bMeans"], "additionalProperties": false,
        "properties": { "id": { "$ref": "#/$defs/id" }, "text": { "$ref": "#/$defs/text" }, "a": { "$ref": "#/$defs/text" }, "aMeans": { "$ref": "#/$defs/text" }, "b": { "$ref": "#/$defs/text" }, "bMeans": { "$ref": "#/$defs/text" } } }
    },
    "criteria": {
      "type": "array", "minItems": 2, "maxItems": 40,
      "items": {
        "type": "object", "required": ["id", "name"],
        "properties": {
          "id": { "$ref": "#/$defs/id", "description": "A short stable code, such as COST. The copied record lists answers by it (COST > EASE)." },
          "name": { "$ref": "#/$defs/text", "description": "One plain sentence saying what good looks like, requirement number first: \"R2 Results reach the right person with no copy and paste\"." },
          "note": { "$ref": "#/$defs/text", "description": "Optional. Shown under the criterion, for example where the analyst is unsure." },
          "scores": { "$ref": "#/$defs/scores", "description": "One decision only: one score per alternative, in order, 0 to 5 (1 poor, 5 excellent)." },
          "director": { "const": true, "description": "Optional. Scored on the page with one tap per option instead of by scores." },
          "image": { "type": "string", "maxLength": 20000, "pattern": "^(https://\\S+|data:image/(png|jpeg|gif|webp|svg\\+xml);base64,[A-Za-z0-9+/=]+)$", "description": "Optional. A small picture shown on the requirement's row: an https address or a data:image URI." },
          "fall": { "$ref": "#/$defs/text", "description": "Optional. What falling short on this requirement means, in plain words, shown on the Classify step." },
          "deadline": { "const": true, "description": "Optional. The requirement is a date. As a must-have, the Classify step warns that a date can steer a long-term choice." },
          "floor": { "type": "integer", "minimum": 1, "maximum": 5, "description": "Optional. The score an option needs to pass this requirement as a must-have. Default 3; the owner can change it on the page." },
          "fromDraft": { "type": "string", "pattern": "^NEW[0-9]{1,3}$", "description": "Optional. The draft id (NEW1) the owner gave this requirement with Add requirement on the page; the draft's sorting and answers carry over to this id." }
        },
        "additionalProperties": false
      }
    },
    "alternatives": {
      "type": "array", "minItems": 2, "maxItems": 12, "items": { "$ref": "#/$defs/text" },
      "description": "One decision: the options, each starting with a short code (\"A Hosted chat service\"). Every criterion then needs scores, unless it is a director criterion."
    },
    "draftWeights": {
      "type": "object", "additionalProperties": { "type": "number", "minimum": 0 },
      "description": "Optional, with alternatives or parts: the analyst's draft weights by criterion id, such as {\"COST\": 30}. The page says whether they pick the same winner."
    },
    "mustHaves": {
      "type": "array", "maxItems": 12, "items": { "$ref": "#/$defs/mustHave" },
      "description": "Must-haves already settled, as pass or fail checks (before 2026-12-04 this field was called gates; that name is still read). One decision: each must-have also has pass, one 1 or 0 per alternative. Parent with parts: id and name here, results in each part's mustHaves."
    },
    "parts": {
      "type": "array", "minItems": 1, "maxItems": 12,
      "description": "A parent with parts: the criteria carry no scores; each part has its own options and scores.",
      "items": {
        "type": "object", "required": ["id", "name"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "name": { "$ref": "#/$defs/text" },
          "note": { "$ref": "#/$defs/text" },
          "twoWay": { "const": true, "description": "Not scored: shown as \"two-way door: prototype it\"." },
          "alternatives": { "type": "array", "minItems": 2, "maxItems": 12, "items": { "$ref": "#/$defs/text" } },
          "scores": { "type": "object", "additionalProperties": { "$ref": "#/$defs/scores" }, "description": "By criterion id; a part uses only the criteria it scores." },
          "mustHaves": { "type": "object", "additionalProperties": { "$ref": "#/$defs/passes" }, "description": "By must-have id: 1 pass, 0 fail, one per option." },
          "ownMustHaves": { "type": "array", "maxItems": 12, "items": { "$ref": "#/$defs/mustHave" } },
          "ownMustHaveResults": { "type": "object", "additionalProperties": { "$ref": "#/$defs/passes" } }
        },
        "additionalProperties": false
      }
    }
  },
  "not": { "required": ["alternatives", "parts"] },
  "$defs": {
    "id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,15}$", "not": { "enum": ["constructor", "toString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"] } },
    "text": { "type": "string", "minLength": 1, "maxLength": 300 },
    "scores": { "type": "array", "items": { "type": "number", "minimum": 0, "maximum": 5 } },
    "passes": { "type": "array", "items": { "enum": [0, 1] } },
    "mustHave": { "type": "object", "required": ["id", "name"], "properties": { "id": { "$ref": "#/$defs/id" }, "name": { "$ref": "#/$defs/text" }, "pass": { "$ref": "#/$defs/passes", "description": "One decision only: 1 pass, 0 fail, one per alternative, in order." } }, "additionalProperties": false }
  }
}
