{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agrodt.github.io/agrotool-knowledge-portal/schemas/v1/person_relations.schema.json",
  "title": "PublicPersonRelations",
  "type": "array",
  "items": {
    "type": "object",
    "allOf": [
      { "$ref": "common.schema.json#/$defs/recordMetadata" },
      {
        "type": "object",
        "required": [
          "relation_id",
          "source_person_id",
          "target_person_id",
          "relation_type",
          "directed",
          "period",
          "work_ids",
          "topic_ids",
          "organization_ids",
          "evidence_summary_ids",
          "confidence",
          "status",
          "derivation_method",
          "derivation_version",
          "source_ids"
        ],
        "properties": {
          "relation_id": { "type": "string", "pattern": "^R[A-Z0-9_-]{3,63}$" },
          "source_person_id": {
            "type": "string",
            "pattern": "^P[A-Z0-9_-]{3,63}$"
          },
          "target_person_id": {
            "type": "string",
            "pattern": "^P[A-Z0-9_-]{3,63}$"
          },
          "relation_type": {
            "enum": [
              "coauthored_with",
              "supervised_by",
              "academic_descendant_of",
              "worked_on_component",
              "same_project_as",
              "affiliated_with",
              "continued_work_of",
              "related_by_topic"
            ]
          },
          "directed": { "type": "boolean" },
          "period": { "$ref": "common.schema.json#/$defs/period" },
          "work_ids": {
            "type": "array",
            "items": { "type": "string", "pattern": "^W[A-Z0-9_-]{3,63}$" },
            "uniqueItems": true
          },
          "topic_ids": {
            "type": "array",
            "items": { "type": "string", "pattern": "^T[A-Z0-9_-]{3,63}$" },
            "uniqueItems": true
          },
          "organization_ids": {
            "type": "array",
            "items": { "type": "string", "pattern": "^O[A-Z0-9_-]{3,63}$" },
            "uniqueItems": true
          },
          "evidence_summary_ids": {
            "$ref": "common.schema.json#/$defs/evidenceIds"
          },
          "confidence": { "enum": ["low", "medium", "high"] },
          "status": { "enum": ["algorithmic", "probable", "confirmed"] },
          "derivation_method": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$"
          },
          "derivation_version": { "type": "string", "minLength": 1 },
          "joint_work_count": { "type": "integer", "minimum": 1 },
          "fractional_weight": { "type": "number", "exclusiveMinimum": 0 },
          "layer_distribution": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "A_CORE": { "type": "integer", "minimum": 0 },
              "B_COMPONENT": { "type": "integer", "minimum": 0 },
              "C_ECOSYSTEM": { "type": "integer", "minimum": 0 },
              "D_CONTEXT": { "type": "integer", "minimum": 0 }
            }
          },
          "source_ids": { "$ref": "common.schema.json#/$defs/sourceIds" }
        }
      }
    ],
    "unevaluatedProperties": false
  }
}
