{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/bettermenu/json-schema/bettermenu-reference-food-schema.json",
  "title": "ReferenceFood",
  "description": "A food the member opened, with its Saved and Recent state.",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/bettermenu-studio-api-openapi.yml#/components/schemas/ReferenceFood",
  "properties": {
    "food_id": {
      "type": "string",
      "title": "Food Id",
      "description": "Identifier of the food in the food database."
    },
    "name": {
      "type": "string",
      "title": "Name",
      "description": "The food's name as last shown."
    },
    "brand": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Brand",
      "description": "The brand, for a branded food."
    },
    "source": {
      "$ref": "#/$defs/ReferenceFoodSource",
      "description": "`generic` for a general food, `branded` for a branded product."
    },
    "saved": {
      "type": "boolean",
      "title": "Saved",
      "description": "Whether the member saved this food."
    },
    "saved_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "title": "Saved At",
      "description": "When the member saved it; `null` while it is not saved."
    },
    "first_viewed_at": {
      "type": "string",
      "format": "date-time",
      "title": "First Viewed At",
      "description": "When the member first opened it."
    },
    "last_viewed_at": {
      "type": "string",
      "format": "date-time",
      "title": "Last Viewed At",
      "description": "When the member last opened it or changed its portion."
    },
    "view_count": {
      "type": "integer",
      "title": "View Count",
      "description": "How many times the member opened it."
    },
    "last_portion": {
      "anyOf": [
        {
          "$ref": "#/$defs/ReferenceFoodPortion"
        },
        {
          "type": "null"
        }
      ],
      "description": "The portion the member last looked at, if any."
    },
    "per_100g": {
      "$ref": "#/$defs/ReferenceFoodPer100g",
      "description": "The headline nutrients per 100 g, as last shown."
    },
    "data_version": {
      "type": "string",
      "title": "Data Version",
      "description": "Version of the food data the member was last shown."
    }
  },
  "type": "object",
  "required": [
    "food_id",
    "name",
    "brand",
    "source",
    "saved",
    "saved_at",
    "first_viewed_at",
    "last_viewed_at",
    "view_count",
    "last_portion",
    "per_100g",
    "data_version"
  ],
  "$defs": {
    "ReferenceFoodPer100g": {
      "properties": {
        "calories": {
          "anyOf": [
            {
              "type": "number",
              "maximum": 100000.0,
              "minimum": 0.0
            },
            {
              "type": "null"
            }
          ],
          "title": "Calories",
          "description": "Energy in kilocalories per 100 g. Zero, or from 0.000001 to 100000."
        },
        "total_fat": {
          "anyOf": [
            {
              "type": "number",
              "maximum": 100000.0,
              "minimum": 0.0
            },
            {
              "type": "null"
            }
          ],
          "title": "Total Fat",
          "description": "Total fat in grams per 100 g. Zero, or from 0.000001 to 100000."
        },
        "total_carbohydrate": {
          "anyOf": [
            {
              "type": "number",
              "maximum": 100000.0,
              "minimum": 0.0
            },
            {
              "type": "null"
            }
          ],
          "title": "Total Carbohydrate",
          "description": "Total carbohydrate in grams per 100 g. Zero, or from 0.000001 to 100000."
        },
        "protein": {
          "anyOf": [
            {
              "type": "number",
              "maximum": 100000.0,
              "minimum": 0.0
            },
            {
              "type": "null"
            }
          ],
          "title": "Protein",
          "description": "Protein in grams per 100 g. Zero, or from 0.000001 to 100000."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "title": "ReferenceFoodPer100g",
      "description": "Headline nutrients per 100 g of the food. Each is `null` when unknown."
    },
    "ReferenceFoodPortion": {
      "properties": {
        "label": {
          "type": "string",
          "maxLength": 100,
          "minLength": 1,
          "title": "Label",
          "description": "The portion as shown, e.g. `1 cup` or `100 g`."
        },
        "grams": {
          "type": "number",
          "maximum": 100000.0,
          "minimum": 0.001,
          "title": "Grams",
          "description": "The weight of the portion in grams, from 0.001 to 100000."
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "label",
        "grams"
      ],
      "title": "ReferenceFoodPortion",
      "description": "An amount of the food, as shown to the member."
    },
    "ReferenceFoodSource": {
      "type": "string",
      "enum": [
        "generic",
        "branded"
      ],
      "title": "ReferenceFoodSource",
      "description": "Which part of the food database a food comes from."
    }
  }
}