{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://spec.soustack.org/stacks/quantified.schema.json",
  "title": "Quantified Stack",
  "type": "object",
  "properties": {
    "ingredients": {
      "type": "array",
      "items": {
        "anyOf": [
          { "$ref": "#/$defs/ingredient" },
          { "$ref": "#/$defs/ingredientSection" }
        ]
      }
    }
  },
  "required": ["ingredients"],
  "$defs": {
    "ingredient": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" },
        "quantity": { "$ref": "../defs/quantity.schema.json" },
        "temperature": { "$ref": "../defs/temperature.schema.json" },
        "notes": { "type": "string" },
        "prep": {
          "oneOf": [
            { "type": "string", "minLength": 1 },
            {
              "type": "array",
              "minItems": 1,
              "items": {
                "anyOf": [
                  { "type": "string", "minLength": 1 },
                  { "$ref": "../stacks/prep.schema.json#/$defs/prepItem" }
                ]
              }
            }
          ]
        },
        "metadata": { "type": "object", "additionalProperties": true },
        "scaling": { "$ref": "../defs/scalingRule.schema.json" }
      },
      "required": ["id", "name", "quantity"],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    },
    "ingredientSection": {
      "type": "object",
      "properties": {
        "section": { "type": "string" },
        "ingredients": {
          "type": "array",
          "items": {
            "anyOf": [
              { "$ref": "#/$defs/ingredient" },
              { "$ref": "#/$defs/ingredientSection" }
            ]
          }
        },
        "metadata": { "type": "object", "additionalProperties": true }
      },
      "required": ["section", "ingredients"],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    }
  },
  "additionalProperties": false
}
