{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "thread": {
      "type": "object",
      "properties": {
        "account_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "thread_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "provider": {
          "type": "string",
          "enum": ["gmail", "outlook", "instantly"]
        }
      },
      "required": ["account_id", "thread_id", "provider"],
      "additionalProperties": false
    },
    "subject": {
      "type": "string"
    },
    "lastActivityAt": {
      "type": "string"
    },
    "needsReply": {
      "type": ["boolean", "null"]
    },
    "done": {
      "type": "boolean"
    },
    "replyStatus": {
      "type": ["string", "null"]
    },
    "messageCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "latestReceivedAt": {
      "type": ["string", "null"]
    },
    "latestSentAt": {
      "type": ["string", "null"]
    },
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "date": {
            "type": "string"
          },
          "direction": {
            "type": "string",
            "enum": ["incoming", "outgoing", "unknown"]
          },
          "subject": {
            "type": "string"
          },
          "from": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "email": {
                "type": "string"
              }
            },
            "required": ["name", "email"],
            "additionalProperties": false
          },
          "to": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "email": {
                  "type": "string"
                }
              },
              "required": ["name", "email"],
              "additionalProperties": false
            }
          },
          "labels": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "text": {
            "type": "string"
          },
          "textIncomplete": {
            "type": "boolean"
          },
          "attachments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "mimeType": {
                  "type": "string"
                },
                "size": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              },
              "required": ["id", "name", "mimeType", "size"],
              "additionalProperties": false
            }
          }
        },
        "required": ["id", "date", "direction", "subject", "from", "to"],
        "additionalProperties": false
      }
    },
    "nextBefore": {
      "type": ["string", "null"]
    }
  },
  "required": [
    "thread",
    "subject",
    "lastActivityAt",
    "needsReply",
    "done",
    "replyStatus",
    "messageCount",
    "latestReceivedAt",
    "latestSentAt",
    "messages",
    "nextBefore"
  ],
  "additionalProperties": false
}
