{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cwwindex.today/data/supply_chain_graph.schema.json",
  "title": "CWW Public-Evidence Supply-Chain Graph",
  "description": "Contract for the bilingual, source-backed company relationship graph published with the CWW index site.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "published_at",
    "data_as_of",
    "methodology",
    "chains",
    "nodes",
    "edges",
    "relationship_types"
  ],
  "properties": {
    "schema_version": {
      "const": "1.0.0"
    },
    "published_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:Z|[+-]\\d{2}:\\d{2})$"
    },
    "data_as_of": {
      "$ref": "#/$defs/isoDate"
    },
    "methodology": {
      "$ref": "#/$defs/methodology"
    },
    "chains": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/chain"
      }
    },
    "nodes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/node"
      }
    },
    "edges": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/edge"
      }
    },
    "relationship_types": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/relationshipType"
      }
    }
  },
  "$defs": {
    "nonEmptyString": {
      "type": "string",
      "minLength": 1
    },
    "identifier": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:[-_][a-z0-9]+)*$"
    },
    "isoDate": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "relationshipDate": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}(?:-\\d{2})?$"
    },
    "publicHttpsUrl": {
      "type": "string",
      "pattern": "^https://[^\\s]+$"
    },
    "sourceType": {
      "type": "string",
      "enum": [
        "company_about_page",
        "company_press_release",
        "company_product_release",
        "government_announcement",
        "regulatory_filing"
      ]
    },
    "confidence": {
      "type": "string",
      "enum": [
        "high",
        "medium",
        "low"
      ]
    },
    "publishedEdgeConfidence": {
      "type": "string",
      "enum": [
        "high",
        "medium"
      ]
    },
    "relationshipTypeKey": {
      "type": "string",
      "enum": [
        "direct_supplier_customer_disclosure",
        "technology_or_product_validation",
        "joint_research_and_development",
        "strategic_cooperation",
        "intellectual_property_license",
        "corporate_control",
        "ecosystem_adjacency"
      ]
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "title_zh",
        "title_en",
        "source_title",
        "source_type",
        "published_at",
        "source_url",
        "locator",
        "confidence"
      ],
      "properties": {
        "title_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "title_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "source_title": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "source_type": {
          "$ref": "#/$defs/sourceType"
        },
        "published_at": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "source_url": {
          "$ref": "#/$defs/publicHttpsUrl"
        },
        "locator": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "confidence": {
          "$ref": "#/$defs/confidence"
        }
      }
    },
    "methodology": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "title_zh",
        "title_en",
        "scope_zh",
        "scope_en",
        "inclusion_rule_zh",
        "inclusion_rule_en",
        "direction_rule_zh",
        "direction_rule_en",
        "confidence_scale",
        "exclusions_zh",
        "exclusions_en",
        "update_policy_zh",
        "update_policy_en"
      ],
      "properties": {
        "title_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "title_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "scope_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "scope_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "inclusion_rule_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "inclusion_rule_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "direction_rule_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "direction_rule_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "confidence_scale": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "high_zh",
            "high_en",
            "medium_zh",
            "medium_en",
            "low_zh",
            "low_en"
          ],
          "properties": {
            "high_zh": {
              "$ref": "#/$defs/nonEmptyString"
            },
            "high_en": {
              "$ref": "#/$defs/nonEmptyString"
            },
            "medium_zh": {
              "$ref": "#/$defs/nonEmptyString"
            },
            "medium_en": {
              "$ref": "#/$defs/nonEmptyString"
            },
            "low_zh": {
              "$ref": "#/$defs/nonEmptyString"
            },
            "low_en": {
              "$ref": "#/$defs/nonEmptyString"
            }
          }
        },
        "exclusions_zh": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/nonEmptyString"
          }
        },
        "exclusions_en": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/nonEmptyString"
          }
        },
        "update_policy_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "update_policy_en": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    },
    "chain": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "key",
        "name_zh",
        "name_en",
        "description_zh",
        "description_en",
        "anchor_node_ids",
        "node_ids",
        "edge_ids"
      ],
      "properties": {
        "key": {
          "$ref": "#/$defs/identifier"
        },
        "name_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "name_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "description_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "description_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "anchor_node_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/identifier"
          }
        },
        "node_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/identifier"
          }
        },
        "edge_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/identifier"
          }
        }
      }
    },
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "ticker",
        "name_zh",
        "name_en",
        "market",
        "role",
        "stage",
        "technology_tags",
        "summary_zh",
        "summary_en",
        "evidence"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "ticker": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "name_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "name_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "market": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "role": {
          "$ref": "#/$defs/identifier"
        },
        "stage": {
          "type": "string",
          "enum": [
            "upstream",
            "anchor",
            "downstream",
            "ecosystem"
          ]
        },
        "technology_tags": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[A-Z0-9]+(?:_[A-Z0-9]+)*$"
          }
        },
        "summary_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "summary_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/evidence"
          }
        }
      }
    },
    "edge": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "source",
        "target",
        "type",
        "label_zh",
        "label_en",
        "as_of",
        "confidence",
        "direction_semantics",
        "evidence"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "source": {
          "$ref": "#/$defs/identifier"
        },
        "target": {
          "$ref": "#/$defs/identifier"
        },
        "type": {
          "$ref": "#/$defs/relationshipTypeKey"
        },
        "label_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "label_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "as_of": {
          "$ref": "#/$defs/relationshipDate"
        },
        "confidence": {
          "$ref": "#/$defs/publishedEdgeConfidence"
        },
        "direction_semantics": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/evidence"
          }
        }
      }
    },
    "relationshipType": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "key",
        "name_zh",
        "name_en",
        "definition_zh",
        "definition_en"
      ],
      "properties": {
        "key": {
          "$ref": "#/$defs/relationshipTypeKey"
        },
        "name_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "name_en": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "definition_zh": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "definition_en": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    }
  }
}
