{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.4/common.schema.json",
  "title": "OGS Common Definitions",
  "description": "Shared definitions referenced by every OGS entity schema. Not a document type on its own. See spec/ogs-core.md and spec/ogs-sense.md.",
  "$defs": {
    "ogs_version": {
      "type": "string",
      "pattern": "^0\\.[1-4]\\.\\d+$",
      "description": "OGS specification version the document targets. v0.4 schemas accept 0.1.x to 0.4.x documents."
    },
    "bcp47_tag": {
      "$ref": "lstring.schema.json#/$defs/bcp47_tag"
    },
    "lstring": {
      "$ref": "lstring.schema.json",
      "description": "Localizable string (bare string, language map, or rich label array). See spec/ogs-i18n.md §5."
    },
    "primary_language": {
      "$ref": "#/$defs/bcp47_tag",
      "description": "Authoritative (endonym) language of this entity's human-readable fields. SHOULD be present (L2); MUST be present for L3."
    },
    "available_languages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/bcp47_tag"
      },
      "description": "Advisory list of languages covered by this entity's LString fields."
    },
    "provenance_method": {
      "type": "string",
      "enum": [
        "expert_panel",
        "instrumental",
        "computed",
        "estimated",
        "user_submitted"
      ],
      "description": "How a value was obtained. See spec/ogs-core.md §6."
    },
    "confidence": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "description": "Confidence from 0.0 (none) to 1.0 (certain)."
    },
    "provenance": {
      "type": "object",
      "description": "Provenance metadata (source, confidence, method). See spec/ogs-core.md §6.",
      "properties": {
        "source": {
          "type": "string",
          "minLength": 1,
          "description": "Origin of the data, e.g. 'WSET Diploma tasting panel, 2024'."
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        },
        "method": {
          "$ref": "#/$defs/provenance_method"
        }
      },
      "patternProperties": {
        "^x-": true
      },
      "additionalProperties": false
    },
    "intensity": {
      "type": "number",
      "minimum": 0,
      "maximum": 10,
      "description": "Intensity on the OGS 0-10 scale (0 absent, 2.5 low, 5 medium, 7.5 high, 10 extreme). See spec/ogs-sense.md §2."
    },
    "detailed_sensory_value": {
      "type": "object",
      "description": "Detailed sensory value: an intensity plus its own provenance. Fields given here override the enclosing profile's provenance. See spec/ogs-sense.md §7.",
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "$ref": "#/$defs/intensity"
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        },
        "method": {
          "$ref": "#/$defs/provenance_method"
        }
      },
      "patternProperties": {
        "^x-": true
      },
      "additionalProperties": false
    },
    "sensory_value": {
      "description": "A sensory intensity in simplified form (a number) or detailed form (an object with provenance).",
      "oneOf": [
        {
          "$ref": "#/$defs/intensity"
        },
        {
          "$ref": "#/$defs/detailed_sensory_value"
        }
      ]
    },
    "basic_tastes": {
      "type": "object",
      "description": "The five basic tastes. See spec/ogs-sense.md §3.",
      "properties": {
        "sweet": {
          "$ref": "#/$defs/sensory_value"
        },
        "sour": {
          "$ref": "#/$defs/sensory_value"
        },
        "salty": {
          "$ref": "#/$defs/sensory_value"
        },
        "bitter": {
          "$ref": "#/$defs/sensory_value"
        },
        "umami": {
          "$ref": "#/$defs/sensory_value"
        }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": true
      }
    },
    "structural": {
      "type": "object",
      "description": "Structural attributes. See spec/ogs-sense.md §4.",
      "properties": {
        "body": {
          "$ref": "#/$defs/sensory_value"
        },
        "acidity_perception": {
          "$ref": "#/$defs/sensory_value"
        },
        "tannin": {
          "$ref": "#/$defs/sensory_value"
        },
        "astringency": {
          "$ref": "#/$defs/sensory_value"
        },
        "alcohol_heat": {
          "$ref": "#/$defs/sensory_value"
        },
        "effervescence": {
          "$ref": "#/$defs/sensory_value"
        },
        "fat": {
          "$ref": "#/$defs/sensory_value",
          "description": "Perceived fat and oiliness: richness from butter, cream, marbling, oil (new in v0.4)."
        },
        "pungency": {
          "$ref": "#/$defs/sensory_value",
          "description": "Chemesthetic heat: chili, pepper, mustard, ginger, horseradish (new in v0.4). Distinct from alcohol_heat."
        }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": true
      }
    },
    "aromatic_entry": {
      "type": "object",
      "description": "One aroma in the family → group → item taxonomy. See spec/ogs-sense.md §5.",
      "required": [
        "family",
        "group",
        "item",
        "intensity"
      ],
      "properties": {
        "family": {
          "type": "string",
          "enum": [
            "fruit",
            "floral",
            "herbal",
            "spice",
            "earth",
            "wood",
            "dairy",
            "savory",
            "confection",
            "vegetal",
            "marine",
            "nut",
            "roast",
            "cereal"
          ],
          "description": "Aromatic family (vocab/aromatic_families.json)."
        },
        "group": {
          "type": "string",
          "minLength": 1,
          "description": "Aromatic group within the family (vocab/aromatic_families.json). From v0.4, checked at L2: snake_case and a group of its family."
        },
        "item": {
          "type": "string",
          "minLength": 1,
          "description": "Specific aroma. Open: items are not a closed list. From v0.4, snake_case is checked at L2."
        },
        "qualifier": {
          "type": "string",
          "enum": [
            "fresh",
            "dried",
            "cooked",
            "candied",
            "fermented",
            "zest",
            "overripe"
          ],
          "description": "How the aroma is expressed. See spec/ogs-sense.md §5.2."
        },
        "intensity": {
          "$ref": "#/$defs/sensory_value"
        }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": true
      }
    },
    "texture_term": {
      "type": "string",
      "pattern": "^[a-z][a-z_]*$",
      "description": "Texture descriptor. Controlled terms are listed in vocab/textures.json; membership is checked at conformance level L2."
    },
    "sensory_profile": {
      "type": "object",
      "description": "A sensory profile. See spec/ogs-sense.md §8.",
      "properties": {
        "basic_tastes": {
          "$ref": "#/$defs/basic_tastes"
        },
        "structural": {
          "$ref": "#/$defs/structural"
        },
        "aromatics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/aromatic_entry"
          }
        },
        "texture": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/texture_term"
          }
        },
        "finish_length": {
          "$ref": "#/$defs/sensory_value",
          "description": "How long flavors persist after swallowing, 0-10."
        },
        "complexity": {
          "$ref": "#/$defs/sensory_value",
          "description": "Number and integration of distinct flavor elements, 0-10."
        },
        "intensity": {
          "$ref": "#/$defs/sensory_value",
          "description": "Overall flavour intensity: how loud the whole profile is, 0-10 (new in v0.4). The basis of intensity matching."
        },
        "provenance": {
          "$ref": "#/$defs/provenance",
          "description": "Default provenance for every value in this profile (new in v0.3). A detailed value's own fields take precedence. See spec/ogs-sense.md §7.3."
        }
      },
      "additionalProperties": true
    },
    "explanation_code_id": {
      "type": "string",
      "pattern": "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$",
      "description": "Explanation code ID. Membership in vocab/explanation_codes.json is checked at conformance level L2."
    },
    "metadata": {
      "type": "object",
      "description": "Document metadata. See spec/ogs-core.md §8.",
      "properties": {
        "created": {
          "type": "string",
          "format": "date-time"
        },
        "updated": {
          "type": "string",
          "format": "date-time"
        },
        "source": {
          "type": "string"
        },
        "license": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "dietary": {
      "type": "object",
      "description": "Allergens and dietary suitability (optional module, new in v0.4). Informational; not a substitute for legally required labelling. See spec/ogs-diet.md.",
      "properties": {
        "contains": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/allergen_id"
          },
          "uniqueItems": true,
          "description": "Allergens present as an ingredient or processing aid (vocab/allergens.json)."
        },
        "may_contain": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/allergen_id"
          },
          "uniqueItems": true,
          "description": "Allergens possibly present through cross-contact."
        },
        "free_from": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/allergen_id"
          },
          "uniqueItems": true,
          "description": "Allergens positively declared absent."
        },
        "suitable_for": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/diet_id"
          },
          "uniqueItems": true,
          "description": "Diets the item is suitable for (vocab/diets.json)."
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        }
      },
      "patternProperties": {
        "^x-": true
      },
      "additionalProperties": false
    },
    "allergen_id": {
      "type": "string",
      "pattern": "^[a-z][a-z_]*$",
      "description": "Allergen ID (vocab/allergens.json); checked at L2."
    },
    "diet_id": {
      "type": "string",
      "pattern": "^[a-z][a-z_]*$",
      "description": "Diet ID (vocab/diets.json); checked at L2."
    }
  }
}
