{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.2/dish.schema.json",
  "title": "OGS Dish",
  "description": "A composed dish with components, cooking methods, and overall sensory profile.",
  "type": "object",
  "required": ["id", "ogs_version", "name", "components", "overall_sensory_profile"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:dish:[a-z0-9-]+$"
    },
    "ogs_version": {
      "type": "string",
      "pattern": "^0\\.(1|2)\\.\\d+$"
    },
    "primary_language": { "$ref": "#/$defs/bcp47_tag" },
    "available_languages": {
      "type": "array",
      "items": { "$ref": "#/$defs/bcp47_tag" }
    },
    "name": { "$ref": "#/$defs/lstring" },
    "description": { "$ref": "#/$defs/lstring" },
    "cuisine": {
      "type": "string",
      "description": "Free-text cuisine name (v0.1) OR a cuisine entity reference matching ogs:<ns>:cuisine:<id> (v0.2+)."
    },
    "course": {
      "type": "string",
      "enum": ["amuse", "appetizer", "soup", "salad", "fish", "main", "cheese", "dessert", "petit_four"]
    },
    "service_temperature": {
      "type": "string",
      "enum": ["frozen", "cold", "cool", "room", "warm", "hot", "very_hot"]
    },
    "components": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/component" }
    },
    "overall_sensory_profile": { "$ref": "#/$defs/sensory_profile" },
    "notes": { "$ref": "#/$defs/lstring" },
    "metadata": { "$ref": "#/$defs/metadata" }
  },
  "additionalProperties": true,
  "$defs": {
    "bcp47_tag": {
      "type": "string",
      "pattern": "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
    },
    "lstring": {
      "oneOf": [
        { "type": "string", "minLength": 1 },
        {
          "type": "object",
          "minProperties": 1,
          "patternProperties": {
            "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["labels"],
          "properties": {
            "primary_language": { "$ref": "#/$defs/bcp47_tag" },
            "labels": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["value", "language"],
                "properties": {
                  "value": { "type": "string", "minLength": 1 },
                  "language": { "$ref": "#/$defs/bcp47_tag" },
                  "script": { "type": "string", "pattern": "^[A-Z][a-z]{3}$" },
                  "role": {
                    "type": "string",
                    "enum": ["preferred", "alternate", "transliteration", "descriptive", "loan", "historical", "deprecated", "ipa"]
                  },
                  "transliteration_scheme": { "type": "string" },
                  "translation": { "type": "object", "additionalProperties": true }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "component": {
      "type": "object",
      "required": ["role", "ingredient_ref"],
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "main_protein", "main_vegetable", "starch", "sauce",
            "fat_component", "acid_component", "aromatic_garnish",
            "seasoning", "textural_element"
          ]
        },
        "ingredient_ref": {
          "type": "string",
          "pattern": "^ogs:[a-z0-9-]+:ingredient:[a-z0-9-]+$"
        },
        "cooking_method": {
          "type": "string",
          "enum": [
            "raw", "seared", "grilled", "roasted", "braised", "poached",
            "steamed", "fried", "confit", "smoked", "fermented", "cured",
            "pickled", "dehydrated", "sous_vide", "blanched", "sauteed",
            "baked", "charred", "emulsified"
          ]
        },
        "maillard_index": { "type": "integer", "minimum": 0, "maximum": 5 },
        "reduction_level": { "type": "integer", "minimum": 0, "maximum": 5 },
        "proportion": {
          "type": "string",
          "enum": ["dominant", "significant", "accent", "trace"]
        },
        "sensory_contribution": {
          "type": "object",
          "properties": {
            "basic_tastes": { "$ref": "#/$defs/basic_tastes" },
            "aromatics": {
              "type": "array",
              "items": { "$ref": "#/$defs/aromatic_entry" }
            },
            "texture": { "type": "array", "items": { "type": "string" } }
          },
          "additionalProperties": true
        },
        "notes": { "$ref": "#/$defs/lstring" }
      },
      "additionalProperties": true
    },
    "sensory_profile": {
      "type": "object",
      "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 },
    "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
    }
  }
}
