{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://webai.vwu.duckdns.org/schema/catalog.schema.json",
  "title": "WEBai building materials catalog",
  "description": "Schema v1.2. Technical properties carry status, origin, source, verification date, method and conditions. Unknown or undeclared performances remain explicit; values are not inferred.",
  "type": "object",
  "required": ["schema_version", "catalog", "language", "last_verified", "materials", "manufacturers"],
  "properties": {
    "schema_version": {"const": "1.2"},
    "catalog": {"type": "string"},
    "language": {"type": "string", "examples": ["pt-PT"]},
    "last_verified": {"type": "string", "format": "date"},
    "materials": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "manufacturer", "name", "source_url", "sources", "variants", "verification_date", "technical_properties", "general_technical_properties", "interpretations", "provenance"],
        "properties": {
          "id": {"type": "string"},
          "manufacturer": {"type": "string"},
          "name": {"type": "string"},
          "category": {"type": "string"},
          "source_url": {"type": "string", "format": "uri"},
          "sources": {"type": "array", "items": {"$ref": "#/$defs/source"}, "minItems": 1},
          "variants": {"type": "array", "items": {"$ref": "#/$defs/variant"}, "minItems": 1},
          "verification_date": {"type": "string", "format": "date"},
          "technical_properties": {"type": "array", "items": {"$ref": "#/$defs/technicalProperty"}, "minItems": 1},
          "general_technical_properties": {"type": "array", "items": {"$ref": "#/$defs/technicalProperty"}},
          "interpretations": {"type": "array", "items": {"$ref": "#/$defs/interpretation"}},
          "not_specified_in_consulted_source": {"type": "array", "items": {"type": "string"}},
          "commercial_information": {"type": "object", "additionalProperties": {"type": ["string", "number", "boolean", "null"]}},
          "provenance": {"type": "object"}
        },
        "additionalProperties": true
      }
    },
    "manufacturers": {"type": "array", "items": {"type": "object"}}
  },
  "$defs": {
    "source": {
      "type": "object",
      "required": ["id", "publisher", "title", "url", "retrieved_on"],
      "properties": {
        "id": {"type": "string"},
        "publisher": {"type": "string"},
        "title": {"type": "string"},
        "url": {"type": "string", "format": "uri"},
        "retrieved_on": {"type": "string", "format": "date"}
      },
      "additionalProperties": true
    },
    "variant": {
      "type": "object",
      "required": ["reference"],
      "properties": {
        "reference": {"type": "string"}
      },
      "additionalProperties": false
    },
    "technicalProperty": {
      "type": "object",
      "required": ["id", "name", "unit", "status", "origin", "source_id", "source_location", "determination_method", "conditions", "verification_date"],
      "properties": {
        "id": {"type": "string"},
        "name": {"type": "string"},
        "unit": {"type": ["string", "null"]},
        "display_unit": {"type": "string"},
        "status": {"enum": ["verified_in_document", "declared_but_not_verified", "not_found_in_consulted_documents", "performance_not_declared", "not_applicable", "calculated"]},
        "origin": {"enum": ["manufacturer", "standard", "calculation", "manufacturer_claim", null]},
        "source_id": {"type": ["string", "null"]},
        "source_location": {"type": ["string", "null"]},
        "determination_method": {"type": ["string", "null"]},
        "conditions": {"type": "string"},
        "verification_date": {"type": "string", "format": "date"},
        "value": {"type": ["number", "string", "boolean", "null"]},
        "values_by_variant": {"type": "object", "additionalProperties": {"type": "object", "required": ["value"], "properties": {"value": {"type": ["number", "string", "boolean", "null"]}, "source_text": {"type": "string"}}, "additionalProperties": true}},
        "operator": {"type": "string"},
        "minimum": {"type": "number"},
        "maximum": {"type": "number"}
      },
      "additionalProperties": true
    },
    "interpretation": {
      "type": "object",
      "required": ["property", "claim_type", "statement", "source_id", "basis"],
      "properties": {
        "property": {"type": "string"},
        "claim_type": {"const": "technical_interpretation"},
        "statement": {"type": "string"},
        "source_id": {"type": "string"},
        "basis": {"type": "string"}
      },
      "additionalProperties": false
    }
  }
}
