{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/asap-cool/json-schema/asap-cool-email-detail-view-schema.json",
  "title": "EmailDetailView",
  "description": "A journal entry plus its delivery timeline.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/asap-cool-emails-api-openapi.yml#/components/schemas/EmailDetailView",
  "allOf": [
    {
      "$ref": "#/$defs/EmailMessageView",
      "description": "The entry itself."
    },
    {
      "type": "object",
      "required": [
        "events"
      ],
      "properties": {
        "events": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EmailEventView"
          },
          "description": "Delivery events, oldest first."
        }
      }
    }
  ],
  "$defs": {
    "EmailEventView": {
      "type": "object",
      "description": "One entry on a message's delivery timeline.\n\nThe raw provider payload is not exposed: it is kept for re-interpretation\non our side, and it repeats recipient data the view already carries.",
      "required": [
        "id",
        "kind",
        "occurred_at"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Event id."
        },
        "kind": {
          "type": "string",
          "description": "What happened (`delivered`, `opened`, `bounced`, …)."
        },
        "occurred_at": {
          "type": "string",
          "description": "When it happened, as reported by the provider, RFC 3339."
        }
      }
    },
    "EmailMessageView": {
      "type": "object",
      "description": "One journal entry, as served by the list and detail endpoints.\n\nThe rendered bodies are deliberately absent: they are large, they hold\nrecipient PII, and a listing has no use for them. `has_body` tells a client\nwhether `GET /v1/emails/{id}/preview` will return something.",
      "required": [
        "id",
        "template",
        "status",
        "to_email",
        "subject",
        "locale",
        "has_body",
        "created_at"
      ],
      "properties": {
        "booking_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Linked calendar booking."
        },
        "contact_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Linked contact."
        },
        "created_at": {
          "type": "string",
          "description": "When the entry was opened (the listing's sort key), RFC 3339."
        },
        "delivered_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "When the provider confirmed delivery, RFC 3339."
        },
        "document_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Linked invoice document."
        },
        "envelope_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Linked signature envelope."
        },
        "failure_reason": {
          "type": [
            "string",
            "null"
          ],
          "description": "Why the dispatch failed, when it did."
        },
        "has_body": {
          "type": "boolean",
          "description": "Whether the stored bodies are still available for preview (they are\ndropped by the retention purge)."
        },
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Journal entry id."
        },
        "locale": {
          "type": "string",
          "description": "Interface-chrome locale the message was rendered with."
        },
        "provider_message_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Provider message id — the support handle for a delivery investigation."
        },
        "reply_to": {
          "type": [
            "string",
            "null"
          ],
          "description": "`Reply-To`, when the send overrode it."
        },
        "sender_name": {
          "type": [
            "string",
            "null"
          ],
          "description": "`From` display name, when the send overrode it."
        },
        "sent_at": {
          "type": [
            "string",
            "null"
          ],
          "description": "When the provider accepted the message, RFC 3339."
        },
        "status": {
          "type": "string",
          "description": "Lifecycle status (`queued`/`sent`/`delivered`/`bounced`/…)."
        },
        "subject": {
          "type": "string",
          "description": "Rendered subject."
        },
        "template": {
          "type": "string",
          "description": "Render-template discriminator (`quote_sent`, `reminder`, …)."
        },
        "to_email": {
          "type": "string",
          "description": "Recipient address."
        }
      }
    }
  }
}