{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://joinmultiplayer.ai/data/corpus-schema-v0.2.json",
  "title": "joinmultiplayer.ai unified public corpus",
  "description": "Public questions, traces, and append-only events. Private moderation and return-token data are excluded.",
  "type": "object",
  "required": ["schema", "schema_version", "license", "questions", "traces", "events"],
  "properties": {
    "schema": {
      "const": "https://joinmultiplayer.ai/data/corpus-schema-v0.2.json"
    },
    "schema_version": { "const": "0.2" },
    "license": { "type": "string", "format": "uri" },
    "questions": {
      "type": "array",
      "items": { "$ref": "#/$defs/question" }
    },
    "traces": {
      "type": "array",
      "items": { "$ref": "#/$defs/trace" }
    },
    "events": {
      "type": "array",
      "items": { "$ref": "#/$defs/event" }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "question": {
      "type": "object",
      "required": [
        "public_id",
        "payload",
        "author",
        "source_trace_id",
        "source_event_id",
        "relation",
        "object_type",
        "status",
        "created_at",
        "updated_at",
        "traces"
      ],
      "properties": {
        "public_id": { "type": "string", "pattern": "^Q[0-9]{4,}$" },
        "payload": {
          "type": "object",
          "required": [
            "question",
            "why_it_matters",
            "starting_point",
            "sources",
            "needed",
            "next_move",
            "language"
          ],
          "properties": {
            "question": { "type": "string" },
            "why_it_matters": { "type": "string" },
            "starting_point": { "type": "string" },
            "sources": { "type": "string" },
            "needed": { "type": "string" },
            "next_move": {
              "enum": ["answer", "source", "experiment", "expert"]
            },
            "language": { "enum": ["en", "ru", "und"] }
          },
          "additionalProperties": true
        },
        "author": { "type": "string" },
        "source_trace_id": { "type": "string", "pattern": "^T[0-9]{4,}$" },
        "source_event_id": { "type": "string", "pattern": "^E[0-9]{6,}$" },
        "relation": { "const": "derives_from" },
        "object_type": { "const": "question" },
        "status": {
          "description": "Public research status, never moderation status.",
          "enum": ["open", "answered", "disputed", "withdrawn"]
        },
        "created_at": { "type": "string", "format": "date-time" },
        "updated_at": { "type": "string", "format": "date-time" },
        "traces": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["public_id", "door", "author", "relation", "created_at"],
            "properties": {
              "public_id": { "type": "string", "pattern": "^T[0-9]{4,}$" },
              "door": { "type": "string" },
              "author": { "type": "string" },
              "relation": { "const": "answers" },
              "created_at": { "type": "string", "format": "date-time" }
            },
            "additionalProperties": true
          }
        }
      },
      "additionalProperties": true
    },
    "trace": {
      "type": "object",
      "required": [
        "public_id",
        "door",
        "payload",
        "author",
        "status",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "public_id": { "type": "string", "pattern": "^T[0-9]{4,}$" },
        "door": { "type": "string" },
        "payload": { "type": "object" },
        "author": { "type": "string" },
        "status": { "const": "public" },
        "parent_public_id": { "type": "string" },
        "relation": { "enum": ["", "continues", "answers"] },
        "created_at": { "type": "string", "format": "date-time" },
        "updated_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": true
    },
    "event": {
      "type": "object",
      "required": [
        "event_id",
        "event_type",
        "object_type",
        "object_id",
        "actor",
        "links",
        "payload",
        "created_at",
        "verified"
      ],
      "properties": {
        "event_id": { "type": "string", "pattern": "^E[0-9]{6,}$" },
        "event_type": { "type": "string" },
        "object_type": { "type": "string" },
        "object_id": { "type": "string" },
        "actor": { "type": "string" },
        "links": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["relation", "target_type", "target_id"],
            "properties": {
              "relation": { "type": "string" },
              "target_type": { "type": "string" },
              "target_id": { "type": "string" },
              "target_event_id": { "type": "string" }
            },
            "additionalProperties": true
          }
        },
        "payload": { "type": "object" },
        "created_at": { "type": "string", "format": "date-time" },
        "verified": { "type": "boolean" }
      },
      "additionalProperties": true
    }
  }
}
