{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "$ref": "#/$defs/__schema0"
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "version": {
          "$ref": "#/$defs/__schema2"
        },
        "subject": {
          "$ref": "#/$defs/__schema3"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema4"
        },
        "provenance": {
          "$ref": "#/$defs/__schema6"
        },
        "links": {
          "$ref": "#/$defs/__schema11"
        },
        "extensions": {
          "$ref": "#/$defs/__schema13"
        },
        "kind": {
          "type": "string",
          "const": "nutrition.nutrient"
        },
        "schemaVersion": {
          "type": "string",
          "const": "0.0.0-local"
        },
        "names": {
          "$ref": "#/$defs/__schema16"
        },
        "definition": {
          "$ref": "#/$defs/__schema2"
        },
        "quantityKind": {
          "type": "string",
          "enum": [
            "mass",
            "energy",
            "activity",
            "fraction",
            "other"
          ]
        },
        "preferredUnit": {
          "$ref": "#/$defs/__schema2"
        },
        "externalCodes": {
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema19"
          }
        }
      },
      "required": [
        "id",
        "version",
        "kind",
        "names",
        "definition",
        "quantityKind",
        "preferredUnit",
        "externalCodes"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "revision": {
          "$ref": "#/$defs/__schema30"
        },
        "subject": {
          "$ref": "#/$defs/__schema31"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema32"
        },
        "provenance": {
          "$ref": "#/$defs/__schema33"
        },
        "links": {
          "$ref": "#/$defs/__schema34"
        },
        "extensions": {
          "$ref": "#/$defs/__schema35"
        },
        "kind": {
          "type": "string",
          "const": "nutrition.intake"
        },
        "schemaVersion": {
          "type": "string",
          "const": "0.0.0-local"
        },
        "time": {
          "$ref": "#/$defs/__schema36"
        },
        "source": {
          "$ref": "#/$defs/__schema20"
        },
        "meal": {
          "$ref": "#/$defs/__schema1"
        },
        "intake": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "food"
                },
                "snapshot": {
                  "$ref": "#/$defs/__schema0"
                },
                "compositionId": {
                  "$ref": "#/$defs/__schema2"
                },
                "consumed": {
                  "$ref": "#/$defs/__schema26"
                },
                "nutrition": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "calculated"
                        },
                        "method": {
                          "type": "string",
                          "const": "fitdata:food_scaling@1"
                        },
                        "resolvedAmount": {
                          "$ref": "#/$defs/__schema26"
                        },
                        "totals": {
                          "$ref": "#/$defs/__schema27"
                        }
                      },
                      "required": [
                        "kind",
                        "method",
                        "resolvedAmount",
                        "totals"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "reported"
                        },
                        "totals": {
                          "$ref": "#/$defs/__schema27"
                        },
                        "source": {
                          "$ref": "#/$defs/__schema20"
                        }
                      },
                      "required": [
                        "kind",
                        "totals",
                        "source"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "unavailable"
                        },
                        "reason": {
                          "$ref": "#/$defs/__schema1"
                        }
                      },
                      "required": [
                        "kind",
                        "reason"
                      ],
                      "additionalProperties": false
                    }
                  ]
                }
              },
              "required": [
                "kind",
                "snapshot",
                "compositionId",
                "consumed",
                "nutrition"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "nutrients"
                },
                "name": {
                  "$ref": "#/$defs/__schema2"
                },
                "totals": {
                  "$ref": "#/$defs/__schema27"
                }
              },
              "required": [
                "kind",
                "name",
                "totals"
              ],
              "additionalProperties": false
            }
          ]
        },
        "capture": {
          "type": "object",
          "properties": {
            "method": {
              "$ref": "#/$defs/__schema1"
            },
            "evidence": {
              "maxItems": 100,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema20"
              }
            },
            "algorithm": {
              "$ref": "#/$defs/__schema9"
            },
            "review": {
              "type": "string",
              "enum": [
                "unreviewed",
                "confirmed",
                "corrected"
              ]
            }
          },
          "required": [
            "method",
            "evidence",
            "review"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "id",
        "revision",
        "kind",
        "time",
        "intake"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "revision": {
          "$ref": "#/$defs/__schema30"
        },
        "subject": {
          "$ref": "#/$defs/__schema31"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema32"
        },
        "provenance": {
          "$ref": "#/$defs/__schema33"
        },
        "links": {
          "$ref": "#/$defs/__schema34"
        },
        "extensions": {
          "$ref": "#/$defs/__schema35"
        },
        "kind": {
          "type": "string",
          "const": "nutrition.meal"
        },
        "schemaVersion": {
          "type": "string",
          "const": "0.0.0-local"
        },
        "time": {
          "$ref": "#/$defs/__schema36"
        },
        "source": {
          "$ref": "#/$defs/__schema20"
        },
        "name": {
          "$ref": "#/$defs/__schema2"
        },
        "category": {
          "$ref": "#/$defs/__schema19"
        },
        "entries": {
          "minItems": 1,
          "maxItems": 1000,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema10"
          }
        }
      },
      "required": [
        "id",
        "revision",
        "kind",
        "time",
        "name",
        "entries"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "revision": {
          "$ref": "#/$defs/__schema30"
        },
        "subject": {
          "$ref": "#/$defs/__schema31"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema32"
        },
        "provenance": {
          "$ref": "#/$defs/__schema33"
        },
        "links": {
          "$ref": "#/$defs/__schema34"
        },
        "extensions": {
          "$ref": "#/$defs/__schema35"
        },
        "kind": {
          "type": "string",
          "const": "nutrition.goal"
        },
        "schemaVersion": {
          "type": "string",
          "const": "0.0.0-local"
        },
        "effectiveDate": {
          "type": "string",
          "format": "date",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
        },
        "timezone": {
          "$ref": "#/$defs/__schema2"
        },
        "targets": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema37"
          }
        }
      },
      "required": [
        "id",
        "revision",
        "kind",
        "effectiveDate",
        "targets"
      ],
      "additionalProperties": false
    }
  ],
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "version": {
          "$ref": "#/$defs/__schema2"
        },
        "subject": {
          "$ref": "#/$defs/__schema3"
        },
        "recordedAt": {
          "$ref": "#/$defs/__schema4"
        },
        "provenance": {
          "$ref": "#/$defs/__schema6"
        },
        "links": {
          "$ref": "#/$defs/__schema11"
        },
        "extensions": {
          "$ref": "#/$defs/__schema13"
        },
        "kind": {
          "type": "string",
          "const": "nutrition.food"
        },
        "schemaVersion": {
          "type": "string",
          "const": "0.0.0-local"
        },
        "names": {
          "$ref": "#/$defs/__schema16"
        },
        "foodType": {
          "type": "string",
          "enum": [
            "generic",
            "branded",
            "restaurant",
            "prepared_dish",
            "custom"
          ]
        },
        "brand": {
          "$ref": "#/$defs/__schema2"
        },
        "derivedFrom": {
          "$ref": "#/$defs/__schema18"
        },
        "identifiers": {
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema19"
          }
        },
        "sources": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema20"
          }
        },
        "servings": {
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema21"
          }
        },
        "compositions": {
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema25"
          }
        }
      },
      "required": [
        "id",
        "version",
        "kind",
        "names",
        "foodType",
        "identifiers",
        "sources",
        "servings",
        "compositions"
      ],
      "additionalProperties": false
    },
    "__schema1": {
      "type": "string",
      "maxLength": 256,
      "pattern": "^[a-z][a-z0-9.-]*:[A-Za-z0-9_.-]+$"
    },
    "__schema2": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512
    },
    "__schema3": {
      "$ref": "#/$defs/__schema2"
    },
    "__schema4": {
      "$ref": "#/$defs/__schema5"
    },
    "__schema5": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "__schema6": {
      "$ref": "#/$defs/__schema7"
    },
    "__schema7": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "manual"
            },
            "source": {
              "$ref": "#/$defs/__schema8"
            }
          },
          "required": [
            "kind",
            "source"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "sensor"
            },
            "source": {
              "$ref": "#/$defs/__schema8"
            }
          },
          "required": [
            "kind",
            "source"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "imported"
            },
            "source": {
              "$ref": "#/$defs/__schema8"
            },
            "mapper": {
              "$ref": "#/$defs/__schema9"
            }
          },
          "required": [
            "kind",
            "source",
            "mapper"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "derived"
            },
            "source": {
              "$ref": "#/$defs/__schema8"
            },
            "algorithm": {
              "$ref": "#/$defs/__schema9"
            },
            "inputs": {
              "minItems": 1,
              "maxItems": 1000,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema10"
              }
            }
          },
          "required": [
            "kind",
            "source",
            "algorithm",
            "inputs"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema8": {
      "type": "object",
      "properties": {
        "provider": {
          "$ref": "#/$defs/__schema2"
        },
        "externalId": {
          "$ref": "#/$defs/__schema2"
        },
        "device": {
          "$ref": "#/$defs/__schema2"
        },
        "originalSource": {
          "$ref": "#/$defs/__schema2"
        }
      },
      "required": [
        "provider"
      ],
      "additionalProperties": false
    },
    "__schema9": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "version": {
          "$ref": "#/$defs/__schema2"
        }
      },
      "required": [
        "id",
        "version"
      ],
      "additionalProperties": false
    },
    "__schema10": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "revision": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "id",
        "revision"
      ],
      "additionalProperties": false
    },
    "__schema11": {
      "maxItems": 1000,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema12"
      }
    },
    "__schema12": {
      "type": "object",
      "properties": {
        "relation": {
          "type": "string",
          "enum": [
            "part_of",
            "same_activity_as",
            "derived_from"
          ]
        },
        "target": {
          "$ref": "#/$defs/__schema10"
        }
      },
      "required": [
        "relation",
        "target"
      ],
      "additionalProperties": false
    },
    "__schema13": {
      "$ref": "#/$defs/__schema14"
    },
    "__schema14": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/__schema1"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema15"
      }
    },
    "__schema15": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema15"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema15"
          }
        }
      ]
    },
    "__schema16": {
      "minItems": 1,
      "maxItems": 100,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema17"
      }
    },
    "__schema17": {
      "type": "object",
      "properties": {
        "language": {
          "type": "string",
          "minLength": 2,
          "maxLength": 35
        },
        "text": {
          "$ref": "#/$defs/__schema2"
        }
      },
      "required": [
        "language",
        "text"
      ],
      "additionalProperties": false
    },
    "__schema18": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "version": {
          "$ref": "#/$defs/__schema2"
        }
      },
      "required": [
        "id",
        "version"
      ],
      "additionalProperties": false
    },
    "__schema19": {
      "type": "object",
      "properties": {
        "system": {
          "$ref": "#/$defs/__schema2"
        },
        "code": {
          "$ref": "#/$defs/__schema2"
        },
        "version": {
          "$ref": "#/$defs/__schema2"
        },
        "display": {
          "$ref": "#/$defs/__schema2"
        }
      },
      "required": [
        "system",
        "code"
      ],
      "additionalProperties": false
    },
    "__schema20": {
      "type": "object",
      "properties": {
        "system": {
          "$ref": "#/$defs/__schema2"
        },
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "version": {
          "$ref": "#/$defs/__schema2"
        },
        "retrievedAt": {
          "$ref": "#/$defs/__schema5"
        }
      },
      "required": [
        "system",
        "id"
      ],
      "additionalProperties": false
    },
    "__schema21": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "names": {
          "$ref": "#/$defs/__schema16"
        },
        "amount": {
          "$ref": "#/$defs/__schema22"
        },
        "compositionIds": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema2"
          }
        },
        "equivalent": {
          "oneOf": [
            {
              "$ref": "#/$defs/__schema23"
            },
            {
              "$ref": "#/$defs/__schema24"
            }
          ]
        }
      },
      "required": [
        "id",
        "names",
        "amount",
        "compositionIds"
      ],
      "additionalProperties": false
    },
    "__schema22": {
      "type": "number",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "__schema23": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "mass"
        },
        "amount": {
          "$ref": "#/$defs/__schema22"
        },
        "unit": {
          "type": "string",
          "enum": [
            "kg",
            "g",
            "mg",
            "ug",
            "[lb_av]",
            "[oz_av]"
          ]
        }
      },
      "required": [
        "kind",
        "amount",
        "unit"
      ],
      "additionalProperties": false
    },
    "__schema24": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "volume"
        },
        "amount": {
          "$ref": "#/$defs/__schema22"
        },
        "unit": {
          "type": "string",
          "enum": [
            "L",
            "mL",
            "[foz_us]",
            "[cup_us]",
            "[tbs_us]",
            "[tsp_us]",
            "[foz_br]",
            "[cup_m]",
            "[tbs_m]",
            "[tsp_m]"
          ]
        }
      },
      "required": [
        "kind",
        "amount",
        "unit"
      ],
      "additionalProperties": false
    },
    "__schema25": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema2"
        },
        "state": {
          "type": "string",
          "enum": [
            "raw",
            "cooked",
            "as_sold",
            "prepared",
            "unknown"
          ]
        },
        "basis": {
          "$ref": "#/$defs/__schema26"
        },
        "nutrients": {
          "$ref": "#/$defs/__schema27"
        },
        "massVolumeEquivalent": {
          "type": "object",
          "properties": {
            "mass": {
              "$ref": "#/$defs/__schema23"
            },
            "volume": {
              "$ref": "#/$defs/__schema24"
            },
            "source": {
              "$ref": "#/$defs/__schema20"
            }
          },
          "required": [
            "mass",
            "volume",
            "source"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "id",
        "state",
        "basis",
        "nutrients"
      ],
      "additionalProperties": false
    },
    "__schema26": {
      "oneOf": [
        {
          "$ref": "#/$defs/__schema23"
        },
        {
          "$ref": "#/$defs/__schema24"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "serving"
            },
            "amount": {
              "$ref": "#/$defs/__schema22"
            },
            "servingId": {
              "$ref": "#/$defs/__schema2"
            }
          },
          "required": [
            "kind",
            "amount",
            "servingId"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema27": {
      "maxItems": 500,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema28"
      }
    },
    "__schema28": {
      "type": "object",
      "properties": {
        "nutrient": {
          "$ref": "#/$defs/__schema18"
        },
        "value": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "quantity"
                },
                "comparator": {
                  "type": "string",
                  "enum": [
                    "=",
                    "<",
                    "<=",
                    ">",
                    ">="
                  ]
                },
                "value": {
                  "$ref": "#/$defs/__schema29"
                },
                "unit": {
                  "$ref": "#/$defs/__schema2"
                }
              },
              "required": [
                "kind",
                "comparator",
                "value",
                "unit"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "absent"
                },
                "reason": {
                  "$ref": "#/$defs/__schema1"
                }
              },
              "required": [
                "kind",
                "reason"
              ],
              "additionalProperties": false
            }
          ]
        },
        "method": {
          "type": "string",
          "enum": [
            "analytical",
            "label",
            "calculated",
            "estimated",
            "imported",
            "unknown"
          ]
        },
        "source": {
          "$ref": "#/$defs/__schema20"
        }
      },
      "required": [
        "nutrient",
        "value",
        "method"
      ],
      "additionalProperties": false
    },
    "__schema29": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "string",
          "maxLength": 100,
          "pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?$"
        }
      ]
    },
    "__schema30": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "__schema31": {
      "$ref": "#/$defs/__schema2"
    },
    "__schema32": {
      "$ref": "#/$defs/__schema5"
    },
    "__schema33": {
      "$ref": "#/$defs/__schema7"
    },
    "__schema34": {
      "maxItems": 1000,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema12"
      }
    },
    "__schema35": {
      "$ref": "#/$defs/__schema14"
    },
    "__schema36": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "instant"
            },
            "at": {
              "$ref": "#/$defs/__schema5"
            }
          },
          "required": [
            "kind",
            "at"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "interval"
            },
            "start": {
              "$ref": "#/$defs/__schema5"
            },
            "durationSeconds": {
              "type": "number",
              "minimum": 0,
              "maximum": 31536000
            }
          },
          "required": [
            "kind",
            "start",
            "durationSeconds"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "date"
            },
            "date": {
              "type": "string",
              "format": "date",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
            },
            "timezone": {
              "$ref": "#/$defs/__schema2"
            }
          },
          "required": [
            "kind",
            "date"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema37": {
      "type": "object",
      "properties": {
        "metric": {
          "$ref": "#/$defs/__schema1"
        },
        "value": {
          "$ref": "#/$defs/__schema29"
        },
        "unit": {
          "$ref": "#/$defs/__schema2"
        }
      },
      "required": [
        "metric",
        "value",
        "unit"
      ],
      "additionalProperties": false
    }
  },
  "title": "FitData nutrition schema",
  "description": "Structural schema for FitData domain records. Also run semantic and document reference validation."
}
