{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "threads": {
      "type": "array",
      "items": {
        "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"]
          },
          "latestMessage": {
            "anyOf": [
              {
                "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"
                    }
                  }
                },
                "required": [
                  "id",
                  "date",
                  "direction",
                  "subject",
                  "from",
                  "to"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "thread",
          "subject",
          "lastActivityAt",
          "needsReply",
          "done",
          "replyStatus",
          "latestMessage"
        ],
        "additionalProperties": false
      }
    },
    "nextCursor": {
      "type": ["string", "null"]
    },
    "syncing": {
      "type": "boolean"
    },
    "incomplete": {
      "type": "boolean"
    }
  },
  "required": ["threads", "nextCursor", "syncing", "incomplete"],
  "additionalProperties": false
}
