{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opendataproducts.org/odpv-v1.1/schema/odpv.profile.schema.json",
  "title": "Open Data Product Vocabulary Interoperability Profile",
  "description": "JSON Schema for a versioned ODPV interoperability profile. Profiles define reviewed semantic mappings, field bindings, and transformation rules; they do not redefine ODPV terms or the external standard.",
  "type": "object",
  "additionalProperties": false,
  "required": ["profileFormat", "id", "title", "version", "status", "vocabulary", "externalStandard", "purpose", "scope", "mappings"],
  "properties": {
    "profileFormat": {"type": "string", "const": "ODPV-Profile-1.0"},
    "id": {"type": "string", "pattern": "^ODPV-[A-Z0-9][A-Za-z0-9.-]*$"},
    "title": {"type": "string", "minLength": 1},
    "version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(-[A-Za-z0-9.-]+)?$"},
    "status": {"enum": ["draft", "stable", "deprecated", "retired"]},
    "vocabulary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "baseUri"],
      "properties": {
        "id": {"const": "ODPV"},
        "version": {"type": "string"},
        "baseUri": {"type": "string", "format": "uri"}
      }
    },
    "externalStandard": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "specification"],
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "version": {"type": "string", "minLength": 1},
        "specification": {"type": "string", "format": "uri"},
        "namespace": {"type": "string", "format": "uri"}
      }
    },
    "purpose": {"type": "string", "minLength": 1},
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["includes", "excludes"],
      "properties": {
        "includes": {"$ref": "#/$defs/stringArray"},
        "excludes": {"$ref": "#/$defs/stringArray"}
      }
    },
    "mappings": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/mapping"}
    }
  },
  "$defs": {
    "stringArray": {"type": "array", "minItems": 1, "items": {"type": "string", "minLength": 1}, "uniqueItems": true},
    "mapping": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "odpvTerm", "externalReference", "rationale", "evidence", "status"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z][a-z0-9-]*$"},
        "kind": {"enum": ["semanticMapping", "fieldBinding", "transformation"]},
        "odpvTerm": {"type": "string", "pattern": "^[A-Za-z][A-Za-z0-9]*$"},
        "externalReference": {"type": "string", "minLength": 1},
        "relation": {"enum": ["exactMatch", "closeMatch", "broadMatch", "narrowMatch", "relatedMatch"]},
        "direction": {"enum": ["bidirectional", "odpvToExternal", "externalToOdpv"]},
        "rationale": {"type": "string", "minLength": 1},
        "evidence": {"type": "string", "format": "uri"},
        "status": {"enum": ["draft", "reviewed", "deprecated"]},
        "implementationNotes": {"type": "string", "minLength": 1}
      },
      "allOf": [
        {"if": {"properties": {"kind": {"const": "semanticMapping"}}, "required": ["kind"]}, "then": {"required": ["relation", "direction"]}},
        {"if": {"properties": {"kind": {"const": "transformation"}}, "required": ["kind"]}, "then": {"required": ["direction", "implementationNotes"]}}
      ]
    }
  }
}
