{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.1/ingredient.schema.json",
  "title": "OGS Ingredient",
  "description": "An ingredient entity with sensory profile, category, and provenance metadata.",
  "type": "object",
  "required": ["id", "ogs_version", "name", "category"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:ingredient:[a-z0-9-]+$",
      "description": "OGS identifier in the format ogs:<namespace>:ingredient:<id>"
    },
    "ogs_version": {
      "type": "string",
      "const": "0.1.0",
      "description": "OGS specification version"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable ingredient name"
    },
    "description": {
      "type": "string",
      "description": "Longer description of the ingredient"
    },
    "category": {
      "type": "string",
      "enum": [
        "protein", "vegetable", "fruit", "grain", "dairy", "fat",
        "herb", "spice", "fungus", "legume", "nut", "seed",
        "sweetener", "acid", "salt", "other"
      ],
      "description": "Primary ingredient category"
    },
    "subcategory": {
      "type": "string",
      "description": "More specific classification within the category"
    },
    "sensory_profile": {
      "$ref": "#/$defs/sensory_profile"
    },
    "origin": {
      "type": "object",
      "properties": {
        "region": {
          "type": "string",
          "description": "Geographic origin"
        },
        "season": {
          "type": "string",
          "description": "Peak season or availability"
        },
        "terroir_notes": {
          "type": "string",
          "description": "Terroir-specific characteristics"
        }
      },
      "additionalProperties": true
    },
    "notes": {
      "type": "string",
      "description": "Additional notes about the ingredient"
    },
    "metadata": {
      "$ref": "#/$defs/metadata"
    }
  },
  "additionalProperties": true,
  "$defs": {
    "sensory_profile": {
      "type": "object",
      "description": "Complete sensory profile of the ingredient",
      "properties": {
        "basic_tastes": {
          "$ref": "#/$defs/basic_tastes"
        },
        "structural": {
          "$ref": "#/$defs/structural"
        },
        "aromatics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/aromatic_entry"
          }
        },
        "texture": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "finish_length": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        },
        "complexity": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        }
      },
      "additionalProperties": true
    },
    "basic_tastes": {
      "type": "object",
      "properties": {
        "sweet": { "$ref": "#/$defs/intensity_value" },
        "sour": { "$ref": "#/$defs/intensity_value" },
        "salty": { "$ref": "#/$defs/intensity_value" },
        "bitter": { "$ref": "#/$defs/intensity_value" },
        "umami": { "$ref": "#/$defs/intensity_value" }
      },
      "additionalProperties": false
    },
    "structural": {
      "type": "object",
      "properties": {
        "body": { "$ref": "#/$defs/intensity_value" },
        "acidity_perception": { "$ref": "#/$defs/intensity_value" },
        "tannin": { "$ref": "#/$defs/intensity_value" },
        "astringency": { "$ref": "#/$defs/intensity_value" },
        "alcohol_heat": { "$ref": "#/$defs/intensity_value" },
        "effervescence": { "$ref": "#/$defs/intensity_value" }
      },
      "additionalProperties": false
    },
    "intensity_value": {
      "type": "number",
      "minimum": 0,
      "maximum": 10,
      "description": "Intensity on the OGS 0-10 scale"
    },
    "aromatic_entry": {
      "type": "object",
      "required": ["family", "group", "item", "intensity"],
      "properties": {
        "family": {
          "type": "string",
          "enum": [
            "fruit", "floral", "herbal", "spice", "earth", "wood",
            "dairy", "savory", "confection", "vegetal", "marine"
          ]
        },
        "group": { "type": "string" },
        "item": { "type": "string" },
        "qualifier": {
          "type": "string",
          "enum": ["fresh", "dried", "cooked", "candied", "fermented", "zest", "overripe"]
        },
        "intensity": {
          "$ref": "#/$defs/intensity_value"
        }
      },
      "additionalProperties": false
    },
    "metadata": {
      "type": "object",
      "properties": {
        "created": { "type": "string", "format": "date-time" },
        "updated": { "type": "string", "format": "date-time" },
        "source": { "type": "string" },
        "license": { "type": "string" }
      },
      "additionalProperties": true
    }
  }
}
