{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengastronomy.org/schema/v0.1/pairing.schema.json",
  "title": "OGS Pairing",
  "description": "A scored, explained pairing between a dish and a beverage.",
  "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 in the format ogs:<namespace>:pairing:<id>"
    },
    "ogs_version": {
      "type": "string",
      "const": "0.1.0",
      "description": "OGS specification version"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable pairing name"
    },
    "description": {
      "type": "string",
      "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 entity"
    },
    "beverage_ref": {
      "type": "string",
      "pattern": "^ogs:[a-z0-9-]+:beverage:[a-z0-9-]+$",
      "description": "Reference to an OGS beverage entity"
    },
    "match_types": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/match_type_entry"
      },
      "description": "Array of match type evaluations"
    },
    "overall_score": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100,
      "description": "Composite pairing score, 0-100"
    },
    "grade": {
      "type": "string",
      "enum": ["A+", "A", "B+", "B", "C+", "C", "D", "F"],
      "description": "Letter grade derived from overall score"
    },
    "explanation_codes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/explanation_code_entry"
      },
      "description": "Array of explanation codes articulating why the pairing works"
    },
    "risks": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/risk_entry"
      },
      "description": "Array of risk factors for the pairing"
    },
    "confidence": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "description": "Overall confidence in the pairing score, 0.0-1.0"
    },
    "evidence": {
      "$ref": "#/$defs/evidence",
      "description": "Evidence and methodology behind the pairing assessment"
    },
    "notes": {
      "type": "string",
      "description": "Additional notes about the pairing"
    },
    "metadata": {
      "$ref": "#/$defs/metadata"
    }
  },
  "additionalProperties": true,
  "$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 from controlled vocabulary"
        },
        "score": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100,
          "description": "Sub-score for this match dimension"
        },
        "description": {
          "type": "string",
          "description": "Human-readable explanation of this match type's contribution"
        },
        "primary": {
          "type": "boolean",
          "description": "Whether this is the dominant match type"
        }
      },
      "additionalProperties": false
    },
    "explanation_code_entry": {
      "type": "object",
      "required": ["code"],
      "properties": {
        "code": {
          "type": "string",
          "description": "Reference to an explanation code ID from explanation_codes.json"
        },
        "weight": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Relevance weight, 0.0-1.0"
        },
        "detail": {
          "type": "string",
          "description": "Human-readable elaboration specific to this pairing"
        }
      },
      "additionalProperties": false
    },
    "risk_entry": {
      "type": "object",
      "required": ["code", "severity"],
      "properties": {
        "code": {
          "type": "string",
          "description": "Reference to a negative explanation code ID"
        },
        "severity": {
          "type": "string",
          "enum": ["low", "medium", "high"],
          "description": "Risk severity level"
        },
        "description": {
          "type": "string",
          "description": "Human-readable description of the risk"
        },
        "mitigation": {
          "type": "string",
          "description": "Suggested action to reduce the risk"
        }
      },
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "properties": {
        "method": {
          "type": "string",
          "enum": ["expert_panel", "instrumental", "computed", "estimated"],
          "description": "Assessment methodology"
        },
        "sources": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Evidence sources"
        },
        "notes": {
          "type": "string",
          "description": "Additional context on the assessment"
        }
      },
      "additionalProperties": true
    },
    "metadata": {
      "type": "object",
      "properties": {
        "created": { "type": "string", "format": "date-time" },
        "updated": { "type": "string", "format": "date-time" },
        "source": { "type": "string" },
        "license": { "type": "string" }
      },
      "additionalProperties": true
    }
  }
}
