{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.vik.guru/collaboration-skills/0.1.0/collaboration-skill.schema.json",
  "title": "Collaboration skill projection",
  "description": "A typed exchange projection of a portable skill contract or one task-bound projection. The referenced SKILL.md remains semantic authority.",
  "type": "object",
  "required": [
    "schemaVersion",
    "id",
    "kind",
    "name",
    "description",
    "semanticAuthorityRef",
    "contract",
    "receivingUse",
    "standing",
    "evidence",
    "transferBoundary"
  ],
  "properties": {
    "schemaVersion": {
      "const": "0.1.0"
    },
    "id": {
      "type": "string",
      "format": "uri"
    },
    "kind": {
      "enum": [
        "portable_skill_contract",
        "task_bound_skill_projection"
      ]
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "semanticAuthorityRef": {
      "type": "string",
      "minLength": 1
    },
    "sourceRef": {
      "type": "string",
      "minLength": 1
    },
    "contract": {
      "$ref": "#/$defs/contract"
    },
    "receivingUse": {
      "$ref": "#/$defs/receivingUse"
    },
    "standing": {
      "$ref": "#/$defs/standing"
    },
    "evidence": {
      "$ref": "#/$defs/evidence"
    },
    "transferBoundary": {
      "type": "string",
      "minLength": 1
    },
    "projection": {
      "$ref": "#/$defs/projection"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "task_bound_skill_projection"
          }
        },
        "required": [
          "kind"
        ]
      },
      "then": {
        "properties": {
          "projection": {}
        },
        "required": [
          "projection"
        ]
      },
      "else": {
        "not": {
          "properties": {
            "projection": {}
          },
          "required": [
            "projection"
          ]
        }
      }
    }
  ],
  "$defs": {
    "contract": {
      "type": "object",
      "required": [
        "what",
        "when",
        "boundaries",
        "result"
      ],
      "properties": {
        "what": {
          "type": "string",
          "minLength": 1
        },
        "when": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "boundaries": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "result": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "receivingUse": {
      "type": "object",
      "required": [
        "job",
        "materialResult",
        "completion"
      ],
      "properties": {
        "job": {
          "type": "string",
          "minLength": 1
        },
        "materialResult": {
          "type": "string",
          "minLength": 1
        },
        "completion": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "standing": {
      "type": "object",
      "required": [
        "routingStatus",
        "contractVersionStatus",
        "evidenceMaturity",
        "wakeTrigger"
      ],
      "properties": {
        "routingStatus": {
          "enum": [
            "candidate",
            "routable",
            "resting",
            "retired"
          ]
        },
        "contractVersionStatus": {
          "enum": [
            "draft",
            "published",
            "superseded",
            "withdrawn"
          ]
        },
        "evidenceMaturity": {
          "type": "string",
          "minLength": 1
        },
        "wakeTrigger": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "required": [
        "band",
        "sourceRefs"
      ],
      "properties": {
        "band": {
          "enum": [
            "observed",
            "human_declared",
            "source_supported",
            "inferred",
            "open"
          ]
        },
        "sourceRefs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "additionalProperties": false
    },
    "projection": {
      "type": "object",
      "required": [
        "sourceContractRef",
        "selectedBehavior",
        "receivingTask",
        "platformAndTools",
        "authorityScope",
        "projectionDepth",
        "lifetime",
        "exitEvent",
        "defaultDisposition",
        "upstreamReturn",
        "routingState"
      ],
      "properties": {
        "sourceContractRef": {
          "type": "string",
          "minLength": 1
        },
        "selectedBehavior": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "receivingTask": {
          "type": "string",
          "minLength": 1
        },
        "platformAndTools": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "authorityScope": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "projectionDepth": {
          "const": 1
        },
        "lifetime": {
          "type": "string",
          "minLength": 1
        },
        "exitEvent": {
          "type": "string",
          "minLength": 1
        },
        "defaultDisposition": {
          "enum": [
            "retire",
            "fold_to_source_reference",
            "review_for_portable_contract"
          ]
        },
        "upstreamReturn": {
          "type": "string",
          "minLength": 1
        },
        "routingState": {
          "enum": [
            "active",
            "retired"
          ]
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
