{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://axlibiza.com/interview-packet.schema.json",
  "title": "Interview Evidence Packet",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "roleId",
    "title",
    "revision",
    "snapshotAt",
    "criteria",
    "events",
    "stateHash",
    "limitations"
  ],
  "$defs": {
    "criterion": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "required",
        "state",
        "evidenceIds",
        "contextualNodeIds",
        "rationale",
        "searchedScope",
        "nextEvidenceNeeded",
        "humanLock"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "required": { "type": "boolean" },
        "state": {
          "type": "string",
          "enum": ["SUPPORTED", "CONTRADICTED", "NOT_ESTABLISHED", "OUT_OF_SCOPE"]
        },
        "evidenceIds": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
        "contextualNodeIds": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
        "rationale": { "type": "string" },
        "searchedScope": { "type": "array", "items": { "type": "string" } },
        "nextEvidenceNeeded": { "type": "array", "items": { "type": "string" } },
        "humanLock": { "type": "boolean" }
      }
    },
    "createCommand": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action", "roleId", "title", "criterionIds"],
      "properties": {
        "action": { "const": "CREATE" },
        "roleId": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "criterionIds": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true }
      }
    },
    "addCriterionCommand": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action", "criterionId", "required", "reason"],
      "properties": {
        "action": { "const": "ADD_CRITERION" },
        "criterionId": { "type": "string", "minLength": 1 },
        "required": { "type": "boolean" },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "evidenceCommand": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action", "criterionId", "evidenceId", "reason"],
      "properties": {
        "action": { "enum": ["ADD_EVIDENCE", "REMOVE_EVIDENCE"] },
        "criterionId": { "type": "string", "minLength": 1 },
        "evidenceId": { "type": "string", "minLength": 1 },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "qualifyCommand": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action", "criterionId", "rationale", "reason"],
      "properties": {
        "action": { "const": "QUALIFY" },
        "criterionId": { "type": "string", "minLength": 1 },
        "rationale": { "type": "string", "minLength": 1 },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "restoreCommand": {
      "type": "object",
      "additionalProperties": false,
      "required": ["action", "criterionId", "reason"],
      "properties": {
        "action": { "const": "RESTORE" },
        "criterionId": { "type": "string", "minLength": 1 },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "command": {
      "oneOf": [
        { "$ref": "#/$defs/createCommand" },
        { "$ref": "#/$defs/addCriterionCommand" },
        { "$ref": "#/$defs/evidenceCommand" },
        { "$ref": "#/$defs/qualifyCommand" },
        { "$ref": "#/$defs/restoreCommand" }
      ]
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "eventSchemaVersion",
        "id",
        "actor",
        "expectedRevision",
        "resultingRevision",
        "command",
        "before",
        "after",
        "beforePacketHash",
        "resultingPacketHash",
        "occurredAt"
      ],
      "properties": {
        "eventSchemaVersion": { "const": "1.0.0" },
        "id": { "type": "string", "minLength": 1 },
        "actor": { "enum": ["human", "agent"] },
        "expectedRevision": { "type": "integer", "minimum": 1 },
        "resultingRevision": { "type": "integer", "minimum": 2 },
        "command": { "$ref": "#/$defs/command" },
        "before": { "anyOf": [{ "$ref": "#/$defs/criterion" }, { "type": "null" }] },
        "after": { "anyOf": [{ "$ref": "#/$defs/criterion" }, { "type": "null" }] },
        "beforePacketHash": { "type": ["string", "null"] },
        "resultingPacketHash": { "type": "string", "minLength": 1 },
        "occurredAt": { "type": "string", "format": "date-time" }
      }
    }
  },
  "properties": {
    "schemaVersion": { "const": "2.0.0" },
    "id": { "type": "string", "minLength": 1 },
    "roleId": { "type": "string", "minLength": 1 },
    "title": { "type": "string", "minLength": 1 },
    "revision": { "type": "integer", "minimum": 1 },
    "snapshotAt": { "type": "string", "format": "date-time" },
    "criteria": { "type": "array", "items": { "$ref": "#/$defs/criterion" }, "minItems": 1 },
    "events": { "type": "array", "items": { "$ref": "#/$defs/event" } },
    "stateHash": { "type": "string", "minLength": 1 },
    "limitations": { "type": "array", "items": { "type": "string" } }
  }
}
