{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://legalquants.com/schemas/timenarratives-conversation.schema.json",
  "title": "TimeNarratives conversation snapshot v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "conversationId",
    "origin",
    "scope",
    "coverage",
    "messages"
  ],
  "properties": {
    "schemaVersion": {
      "const": "timenarratives.conversation.v1"
    },
    "conversationId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$"
    },
    "origin": {
      "enum": ["current_context", "host_reader", "export", "summary"]
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["since", "until"],
      "properties": {
        "since": {
          "type": ["string", "null"],
          "format": "date-time"
        },
        "until": {
          "type": ["string", "null"],
          "format": "date-time"
        }
      }
    },
    "coverage": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["status", "gaps"],
          "properties": {
            "status": {
              "const": "complete"
            },
            "gaps": {
              "type": "array",
              "maxItems": 0,
              "items": {
                "type": "string"
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["status", "gaps"],
          "properties": {
            "status": {
              "const": "partial"
            },
            "gaps": {
              "type": "array",
              "minItems": 1,
              "maxItems": 30,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500,
                "pattern": "\\S"
              }
            }
          }
        }
      ]
    },
    "messages": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["messageId", "role", "author", "timestamp", "text"],
        "properties": {
          "messageId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$"
          },
          "role": {
            "enum": ["user", "assistant", "tool", "quoted", "unknown"]
          },
          "author": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 256,
                "pattern": "^(?=.*\\S)[^\\u0000-\\u001f\\u007f]+$"
              },
              {
                "type": "null"
              }
            ]
          },
          "timestamp": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "text": {
            "type": "string",
            "maxLength": 307200
          }
        }
      }
    }
  }
}
