{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/nopaque-co-uk/json-schema/nopaque-co-uk-comment-thread-schema.json",
  "title": "CommentThread",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/nopaque-co-uk-comments-api-openapi.yml#/components/schemas/CommentThread",
  "type": "object",
  "required": [
    "threadId",
    "jobType",
    "targetKind",
    "targetId",
    "anchor",
    "createdAt",
    "lastActivityAt",
    "replyCount",
    "comments"
  ],
  "properties": {
    "threadId": {
      "type": "string"
    },
    "jobType": {
      "type": "string",
      "enum": [
        "mission",
        "standard",
        "mapping",
        "load",
        "sweep",
        "batch",
        "digital",
        "survey"
      ],
      "description": "The kind of job the thread is on. SMS surveys are `survey`."
    },
    "targetKind": {
      "type": "string",
      "enum": [
        "run",
        "config"
      ]
    },
    "targetId": {
      "type": "string",
      "description": "The run id, or the config id when `targetKind` is `config`."
    },
    "runId": {
      "type": "string"
    },
    "configId": {
      "type": "string"
    },
    "targetLabel": {
      "type": "string",
      "description": "The job's name when the thread was started."
    },
    "anchor": {
      "$ref": "#/$defs/CommentAnchor"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "lastActivityAt": {
      "type": "string",
      "format": "date-time",
      "description": "The newest comment's time. Recent is ordered by it."
    },
    "replyCount": {
      "type": "integer",
      "minimum": 0
    },
    "comments": {
      "type": "array",
      "description": "The first comment, then each reply in order. A Recent page carries the first only.",
      "items": {
        "$ref": "#/$defs/Comment"
      }
    }
  },
  "$defs": {
    "Comment": {
      "type": "object",
      "required": [
        "id",
        "body",
        "authorId",
        "createdAt"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "body": {
          "type": "string"
        },
        "authorId": {
          "type": "string",
          "description": "The author's user id."
        },
        "authorEmail": {
          "type": "string",
          "description": "For display. Absent when the author's token carried no email."
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "CommentAnchor": {
      "type": "object",
      "description": "What a thread is about. `job` is the run as a whole; `turn` is one turn of its\ntranscript; `selection` is text someone highlighted, copied at create (up to 500\ncharacters) so the comment still reads right if the transcript is re-processed.\n",
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "job",
            "turn",
            "selection"
          ]
        },
        "turnIndex": {
          "type": "integer",
          "minimum": 0,
          "description": "Zero-based. Required for `turn`, optional for `selection`."
        },
        "role": {
          "type": "string",
          "maxLength": 32,
          "description": "Who said the turn, as the page labels it."
        },
        "quote": {
          "type": "string",
          "maxLength": 500,
          "description": "Required for `selection`."
        }
      }
    }
  }
}