{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "envelope-schema_1.0.2.json",
  "title": "Envelope",
  "description": "Defines a message envelope that specifies sender, recipients, referenced files, and optional message features.",
  "type": "object",
  "required": ["body", "messageId", "recipients", "sender", "title"],
  "additionalProperties": false,
  "properties": {
    "attachments": {
      "description": "List of attachments included in the message.",
      "type": "array",
      "maxItems": 20,
      "items": {
     "$ref": "#/$defs/file"
    }
    },
"body": {
      "description": "Main message body file.",
      "$ref": "#/$defs/file"
    },
    "deliverAt": {
      "description": "Scheduled delivery timestamp in RFC 3339 format. The message is processed immediately, but delivery is deferred until this time.",
      "$ref": "#/$defs/datetime"
  },
    "messageId": {
      "description": "Unique identifier for the message within the sender organization.",
      "type": "string",
      "maxLength": 71,
      "pattern": "^[a-zA-Z0-9/\\\\._-]+$"
    },
    "recipients": {
      "description": "List of message recipients.",
      "type": "array",
      "minItems": 1,
      "maxItems": 10,
      "items": {
     "$ref": "#/$defs/userRecipient"
      }
    },
    "requireOpenReceipt": {
      "description": "If true, an open receipt must be registered before the recipient can access the message content. Only supported for single recipient envelopes.",
      "type": "boolean",
      "default": false
    },
    "sender": {
      "description": "Details of the message sender, used for recipient display and feature authorization.",
      "$ref": "#/$defs/batchSender"
    },
    "title": {
      "description": "Title of the message shown to recipients. Do not include sensitive data.",
      "type": "string",
      "maxLength": 101
    }
  },
  "$defs": {
    "file": {
 "description": "References a file in object storage, with metadata used for validation and recipient display.",
      "type": "object",
      "required": ["name", "mimeType", "filename"],
      "additionalProperties": false,
      "properties": {
 "name": {
       "description": "Object key or internal file name referenced by the envelope.",
          "type": "string",
        "maxLength": 101
    },
        "title": {
      "description": "Display title of the file shown to recipients.",
          "type": "string",
          "maxLength": 101
        },
    "hash": {
          "description": "Hash value of the file for integrity verification.",
    "type": "string"
        },
        "mimeType": {
          "description": "Media type of the referenced file.",
  "$ref": "#/$defs/mediaType"
        },
        "filename": {
   "description": "The full file name presented to recipients, including the file extension.",
          "$ref": "#/$defs/filename"
      }
      }
    },

    "userRecipient": {
    "description": "Represents a recipient of the message.",
 "type": "object",
      "required": ["identity"],
  "additionalProperties": false,
      "properties": {
        "identity": {
          "description": "Key-value identity attributes used to resolve the recipient. Exactly one key-value pair is required.",
          "type": "object",
 "minProperties": 1,
          "maxProperties": 1,
          "propertyNames": {
      "type": "string",
        "minLength": 1,
  "maxLength": 50,
            "pattern": "^[a-zA-Z0-9/\\._-]{1,30}$"
          },
          "additionalProperties": {
     "type": "string",
            "minLength": 1
          }
        },
  "interim": {
   "description": "Interim message handling configuration for this recipient.",
          "$ref": "#/$defs/interim"
        }
      }
    },

    "interim": {
      "description": "Configuration for interim message handling when a recipient does not have an active mailbox.",
      "type": "object",
      "required": ["enable"],
      "additionalProperties": false,
      "properties": {
        "enable": {
          "description": "Indicates whether interim messaging is enabled for this recipient.",
          "type": "boolean"
        },
      "notificationEmail": {
   "description": "Email address to notify when a message is placed in the interim repository.",
          "$ref": "#/$defs/email"
        }
      }
    },

    "batchSender": {
      "description": "Specifies the sender organization and optional user context.",
      "type": "object",
      "required": ["organizationId", "senderId"],
      "additionalProperties": false,
      "properties": {
        "userId": {
          "description": "Identifier of the user sending the message.",
   "type": "integer",
    "format": "int64",
          "minimum": 2
        },
   "senderId": {
          "description": "Identifier of the sender.",
          "type": "integer",
     "format": "int64",
          "minimum": 1
        },
   "organizationId": {
          "description": "Identifier of the sender's organization.",
          "type": "integer",
       "format": "int64",
          "minimum": 2
        }
      }
    },

    "datetime": {
      "description": "RFC 3339 date-time string.",
      "type": "string",
      "format": "date-time"
    },

    "email": {
      "type": "string",
      "format": "email"
    },

    "mediaType": {
      "type": "string",
      "enum": [
        "application/pdf",
        "application/msword",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        "application/vnd.ms-excel",
     "application/vnd.ms-powerpoint",
     "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "application/vnd.openxmlformats-officedocument.presentationml.presentation",
      "application/vnd.oasis.opendocument.presentation",
        "application/vnd.oasis.opendocument.spreadsheet",
        "application/vnd.oasis.opendocument.text",
        "application/rtf",
        "text/html",
     "text/plain",
        "text/rtf",
        "image/png",
      "image/jpeg",
        "image/bmp",
  "image/gif",
        "image/tiff"
      ]
    },

    "filename": {
      "type": "string",
      "maxLength": 101,
      "pattern": "^[0-9a-zA-Z_\\-. ]+\\.(pdf|doc|docx|xls|ppt|xlsx|pptx|odp|ods|odt|rtf|html|htm|txt|png|jpeg|jpg|bmp|gif|tiff|tif)$"
    }
  }
}
