{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/anjal-app/json-schema/anjal-app-message-schema.json",
  "title": "Message",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/anjal-app-openapi.yaml#/components/schemas/Message",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "direction": {
      "type": "string",
      "enum": [
        "inbound",
        "outbound"
      ]
    },
    "from": {
      "type": "string"
    },
    "to": {
      "type": "string"
    },
    "subject": {
      "type": "string"
    },
    "plainBody": {
      "type": [
        "string",
        "null"
      ]
    },
    "htmlBody": {
      "type": [
        "string",
        "null"
      ]
    },
    "isRead": {
      "type": "boolean"
    },
    "threadId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "messageIdHeader": {
      "type": [
        "string",
        "null"
      ]
    },
    "inReplyTo": {
      "type": [
        "string",
        "null"
      ]
    },
    "receivedAt": {
      "type": "string",
      "format": "date-time"
    },
    "labels": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Lowercase labels on this message."
    },
    "isSpam": {
      "type": "boolean",
      "description": "Flagged by the spam filter. Spam is left out of lists unless `includeSpam=true`."
    },
    "deliveryStatus": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "delivered",
        "bounced",
        "complained",
        "rejected",
        null
      ],
      "description": "Outbound only. `delivered` means the recipient's mail server\naccepted it (not a guarantee of inbox placement). Null until known.\n"
    },
    "deliveredAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When the recipient's mail server accepted the message (outbound only)."
    },
    "firstOpenedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Time of the first open (outbound sends with `trackOpens: true`\nonly). NULL until the first open. Opens are a hint, not proof:\nApple Mail Privacy Protection fetches images on delivery, and\nclients that block images never report an open.\n"
    },
    "lastOpenedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Most recent open event. Updates on every open."
    },
    "openCount": {
      "type": "integer",
      "default": 0,
      "description": "Total opens. Subject to the same caveats as the timestamps."
    },
    "firstClickedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Timestamp of the first recipient link-click. Reliable signal of\nengagement (unlike opens, click events are not Apple-MPP-poisoned).\nNULL until the first click.\n"
    },
    "lastClickedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "clickCount": {
      "type": "integer",
      "default": 0
    },
    "attachments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AttachmentMeta"
      }
    }
  },
  "$defs": {
    "AttachmentMeta": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "filename": {
          "type": "string"
        },
        "contentType": {
          "type": "string"
        },
        "sizeBytes": {
          "type": "integer"
        },
        "inline": {
          "type": "boolean",
          "description": "Present and true when `htmlBody` embedded this attachment as an inline\nimage and `?inlineImages=refs` replaced it with `attachment:<id>`.\n"
        }
      }
    }
  }
}