{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://spec.soustack.org/stacks/storage.schema.json",
  "title": "Storage Stack",
  "type": "object",
  "properties": {
    "storage": {
      "type": "object",
      "properties": {
        "roomTemp": { "$ref": "#/$defs/storageMethod" },
        "refrigerated": { "$ref": "#/$defs/storageMethod" },
        "frozen": { "$ref": "#/$defs/storageMethod" },
        "leftovers": { "$ref": "#/$defs/leftovers" },
        "metadata": { "type": "object", "additionalProperties": true }
      },
      "anyOf": [
        { "required": ["roomTemp"] },
        { "required": ["refrigerated"] },
        { "required": ["frozen"] }
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    }
  },
  "required": ["storage"],
  "$defs": {
    "storageMethod": {
      "type": "object",
      "properties": {
        "duration": { "$ref": "../defs/duration.schema.json#/properties/StorageDuration" },
        "notes": { "type": "string" },
        "metadata": { "type": "object", "additionalProperties": true }
      },
      "required": ["duration"],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    },
    "reheatDuration": {
      "type": "object",
      "properties": {
        "minMinutes": { "type": "integer", "minimum": 0 },
        "maxMinutes": { "type": "integer", "minimum": 0 }
      },
      "anyOf": [
        { "required": ["minMinutes"] },
        { "required": ["maxMinutes"] }
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    },
    "reheatInstruction": {
      "type": "object",
      "properties": {
        "method": { "type": "string", "minLength": 1 },
        "temp": {
          "type": "object",
          "properties": {
            "value": { "type": "number" },
            "unit": { "type": "string", "enum": ["F", "C"] }
          },
          "required": ["value", "unit"],
          "additionalProperties": false,
          "patternProperties": {
            "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
          }
        },
        "duration": { "$ref": "#/$defs/reheatDuration" },
        "notes": { "type": "string" }
      },
      "required": ["method"],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    },
    "portioning": {
      "type": "object",
      "properties": {
        "notes": { "type": "string" },
        "recommendedPortion": {
          "type": "object",
          "properties": {
            "quantity": { "type": "number" },
            "unit": { "type": "string" }
          },
          "required": ["quantity", "unit"],
          "additionalProperties": false,
          "patternProperties": {
            "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
          }
        }
      },
      "required": ["notes"],
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    },
    "leftovers": {
      "type": "object",
      "properties": {
        "notes": { "type": "string" },
        "reheat": {
          "oneOf": [
            {
              "type": "array",
              "items": { "type": "string" },
              "minItems": 1
            },
            {
              "type": "array",
              "items": { "$ref": "#/$defs/reheatInstruction" },
              "minItems": 1
            }
          ]
        },
        "portioning": { "$ref": "#/$defs/portioning" }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": { "$ref": "../defs/common.schema.json#/properties/extensionLaneValue" }
      }
    }
  },
  "additionalProperties": false
}
