{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.21dayswonder.com/data/products.v2.schema.json",
  "title": "21 DAYS WONDER product fact source",
  "type": "object",
  "required": [
    "schemaVersion",
    "lastReviewed",
    "medicalBoundary",
    "sharedPackageWarnings",
    "sharedStorage",
    "ingredientNames",
    "products"
  ],
  "properties": {
    "schemaVersion": {"const": "2.1.0"},
    "lastReviewed": {"type": "string", "format": "date"},
    "products": {
      "type": "array",
      "minItems": 11,
      "maxItems": 11,
      "items": {"$ref": "#/$defs/product"}
    }
  },
  "$defs": {
    "localizedText": {
      "type": "object",
      "required": ["zh-CN", "zh-TW", "en"],
      "properties": {
        "zh-CN": {"type": "string", "minLength": 1},
        "zh-TW": {"type": "string", "minLength": 1},
        "en": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "localizedFaq": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["question", "answer"],
        "properties": {
          "question": {"$ref": "#/$defs/localizedText"},
          "answer": {"$ref": "#/$defs/localizedText"}
        },
        "additionalProperties": false
      }
    },
    "amount": {
      "type": "object",
      "required": ["value", "unit"],
      "properties": {
        "value": {"type": "number", "exclusiveMinimum": 0},
        "unit": {"type": "string", "minLength": 1},
        "equivalent": {"type": "string", "minLength": 1}
      },
      "additionalProperties": false
    },
    "ingredient": {
      "type": "object",
      "required": ["ingredientId", "name", "perUnit", "perPacket"],
      "properties": {
        "ingredientId": {"type": "string", "minLength": 1},
        "name": {"type": "string", "minLength": 1},
        "perUnit": {"$ref": "#/$defs/amount"},
        "perPacket": {"$ref": "#/$defs/amount"}
      },
      "additionalProperties": false
    },
    "npn": {
      "type": "object",
      "required": ["npnOnPack"],
      "properties": {
        "npnOnPack": {"type": "string", "pattern": "^[0-9]{8}$"}
      },
      "additionalProperties": false
    },
    "component": {
      "type": "object",
      "required": ["componentId", "name", "form", "unitsPerPacket", "ingredients", "npn"],
      "properties": {
        "componentId": {"type": "string", "minLength": 1},
        "name": {"type": "string", "minLength": 1},
        "form": {"type": "string", "minLength": 1},
        "unitsPerPacket": {"type": "integer", "minimum": 1},
        "ingredients": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/ingredient"}
        },
        "ingredientTotal": {"type": "object"},
        "npn": {"$ref": "#/$defs/npn"}
      },
      "additionalProperties": false
    },
    "product": {
      "type": "object",
      "required": [
        "id",
        "slug",
        "category",
        "label",
       "names",
       "summary",
        "geoAnswer",
        "geoCitationScope",
        "geoFaq",
        "coreIngredientExplanation",
       "audience",
        "components",
        "directions",
        "allergens",
        "relatedProducts"
      ],
      "properties": {
        "id": {"type": "string", "pattern": "^(0[1-9]|1[01])$"},
        "slug": {"type": "string", "pattern": "^(0[1-9]|1[01])-[a-z0-9-]+$"},
        "category": {"type": "string", "minLength": 1},
        "label": {"type": "string", "minLength": 1},
        "names": {
          "type": "object",
          "required": ["display", "alternate"],
          "properties": {
            "display": {"$ref": "#/$defs/localizedText"},
            "alternate": {"$ref": "#/$defs/localizedText"}
          },
          "additionalProperties": false
        },
       "summary": {"$ref": "#/$defs/localizedText"},
        "geoAnswer": {"$ref": "#/$defs/localizedText"},
        "geoCitationScope": {"$ref": "#/$defs/localizedText"},
        "geoFaq": {"$ref": "#/$defs/localizedFaq"},
        "coreIngredientExplanation": {"$ref": "#/$defs/localizedText"},
       "audience": {
          "type": "object",
          "required": ["zh-CN", "zh-TW", "en"]
        },
        "components": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/component"}
        },
        "directions": {
          "type": "object",
          "required": ["labelTextEn", "localized"]
        },
        "storageOverride": {"$ref": "#/$defs/localizedText"},
        "allergens": {"type": "array"},
        "relatedProducts": {
          "type": "array",
          "minItems": 3,
          "items": {"type": "string", "pattern": "^(0[1-9]|1[01])$"}
        }
      },
      "additionalProperties": false
    }
  }
}
