{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.3/pairing.schema.json",
  "title": "OGS Pairing",
  "description": "A scored, explained match between one dish and one beverage. See spec/ogs-match.md.",
  "type": "object",
  "required": ["id", "ogs_version", "name", "dish_ref", "beverage_ref", "match_types", "overall_score", "grade", "explanation_codes", "confidence"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:pairing:[a-z0-9-]+$",
      "description": "OGS identifier: ogs:<namespace>:pairing:<id>."
    },
    "ogs_version": { "$ref": "common.schema.json#/$defs/ogs_version" },
    "primary_language": { "$ref": "common.schema.json#/$defs/primary_language" },
    "available_languages": { "$ref": "common.schema.json#/$defs/available_languages" },
    "name": { "$ref": "common.schema.json#/$defs/lstring", "description": "Human-readable pairing name." },
    "description": { "$ref": "common.schema.json#/$defs/lstring", "description": "Longer description of the pairing." },
    "dish_ref": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:dish:[a-z0-9-]+$",
      "description": "Reference to an OGS dish."
    },
    "beverage_ref": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:beverage:[a-z0-9-]+$",
      "description": "Reference to an OGS beverage."
    },
    "match_types": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/match_type_entry" },
      "description": "Sub-scores per match dimension. See spec/ogs-match.md §3."
    },
    "overall_score": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100,
      "description": "Composite pairing score, 0-100. See spec/ogs-match.md §4."
    },
    "grade": {
      "type": "string",
      "enum": ["A+", "A", "B+", "B", "C+", "C", "D", "F"],
      "description": "Letter grade. MUST match overall_score per spec/ogs-match.md §5."
    },
    "explanation_codes": {
      "type": "array",
      "items": { "$ref": "#/$defs/explanation_code_entry" },
      "description": "Why the pairing works or fails. See spec/ogs-match.md §6."
    },
    "risks": {
      "type": "array",
      "items": { "$ref": "#/$defs/risk_entry" },
      "description": "Potential negative interactions. See spec/ogs-match.md §7."
    },
    "confidence": { "$ref": "common.schema.json#/$defs/confidence", "description": "Overall confidence in the pairing score." },
    "evidence": { "$ref": "#/$defs/evidence" },
    "notes": { "$ref": "common.schema.json#/$defs/lstring" },
    "metadata": { "$ref": "common.schema.json#/$defs/metadata" }
  },
  "additionalProperties": true,
  "allOf": [
    { "if": { "properties": { "grade": { "const": "A+" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 95 } } } },
    { "if": { "properties": { "grade": { "const": "A" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 90, "maximum": 94 } } } },
    { "if": { "properties": { "grade": { "const": "B+" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 85, "maximum": 89 } } } },
    { "if": { "properties": { "grade": { "const": "B" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 80, "maximum": 84 } } } },
    { "if": { "properties": { "grade": { "const": "C+" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 75, "maximum": 79 } } } },
    { "if": { "properties": { "grade": { "const": "C" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 70, "maximum": 74 } } } },
    { "if": { "properties": { "grade": { "const": "D" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "minimum": 60, "maximum": 69 } } } },
    { "if": { "properties": { "grade": { "const": "F" } }, "required": ["grade"] }, "then": { "properties": { "overall_score": { "maximum": 59 } } } }
  ],
  "$defs": {
    "match_type_entry": {
      "type": "object",
      "required": ["type", "score"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["harmony", "contrast", "bridge", "intensity_alignment", "structural_balance", "refresh"],
          "description": "Match type (vocab/match_types.json)."
        },
        "score": { "type": "integer", "minimum": 0, "maximum": 100, "description": "Sub-score for this dimension." },
        "description": { "$ref": "common.schema.json#/$defs/lstring" },
        "primary": { "type": "boolean", "description": "Whether this is the dominant match type." }
      },
      "additionalProperties": false
    },
    "explanation_code_entry": {
      "type": "object",
      "required": ["code"],
      "properties": {
        "code": { "$ref": "common.schema.json#/$defs/explanation_code_id" },
        "weight": { "type": "number", "minimum": 0, "maximum": 1, "description": "Relevance weight, 0.0-1.0." },
        "detail": { "$ref": "common.schema.json#/$defs/lstring", "description": "Elaboration specific to this pairing." }
      },
      "additionalProperties": false
    },
    "risk_entry": {
      "type": "object",
      "required": ["code", "severity"],
      "properties": {
        "code": {
          "$ref": "common.schema.json#/$defs/explanation_code_id",
          "description": "A negative explanation code. Direction is checked at conformance level L2."
        },
        "severity": { "type": "string", "enum": ["low", "medium", "high"] },
        "description": { "$ref": "common.schema.json#/$defs/lstring" },
        "mitigation": { "$ref": "common.schema.json#/$defs/lstring" }
      },
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "description": "How the pairing was assessed. See spec/ogs-match.md §8.",
      "properties": {
        "method": { "$ref": "common.schema.json#/$defs/provenance_method" },
        "sources": { "type": "array", "items": { "type": "string" } },
        "notes": { "$ref": "common.schema.json#/$defs/lstring" }
      },
      "additionalProperties": true
    }
  }
}
