{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.3/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-3]\\.\\d+$",
      "description": "OGS specification version the document targets. v0.3 schemas accept 0.1.x, 0.2.x and 0.3.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
    },
    "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" }
      },
      "additionalProperties": false
    },
    "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"
          ],
          "description": "Aromatic family (vocab/aromatic_families.json)."
        },
        "group": { "type": "string", "minLength": 1, "description": "Aromatic group within the family, snake_case." },
        "item": { "type": "string", "minLength": 1, "description": "Specific aroma, snake_case." },
        "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
    },
    "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." },
        "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
    }
  }
}
