{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schema.whispir.com/sparx-message-transactions/sms-1.0.0",
  "title": "Sparx Message Transactions sms events",
  "description": "A schema for a sparx sms message transaction events",
  "type": "object",
  "properties": {
    "schema": {
      "type": "string"
    },
    "metadata": {
      "$ref": "../event-0.0.0#/$defs/metadata"
    },
    "source": {
      "$ref": "../event-0.0.0#/$defs/appDetails"
    },
    "event": {
      "type": "object",
      "properties": {
        "eventType": {
          "type": "string",
          "enum": [
            "MESSAGE_TRANSACTION_SMS",
            "MESSAGE_TRANSACTION_SMS_REPLY",
            "MESSAGE_TRANSACTION_SMS_STATUS_SENT",
            "MESSAGE_TRANSACTION_SMS_STATUS_DELIVERED",
            "MESSAGE_TRANSACTION_SMS_STATUS_UNDELIVERED"
          ]
        },
        "message": {
          "type": "object",
          "properties": {
            "messageId": {
              "type": "string"
            },
            "companyId": {
              "type": "string"
            },
            "workspaceId": {
              "type": "string"
            },
            "templateId": {
              "type": "string"
            },
            "parts": {
              "type": "number"
            },
            "recipient": {
              "contactId": {
                "type": "string"
              },
              "recipientId": {
                "type": "string"
              },
              "identifier": {
                "type": "string"
              },
              "required": ["contactId", "recipientId", "identifier"]
            },
            "messageRequestId": {
              "type": "string"
            }
          },
          "if": {
            "properties": { "eventType": { "const": "MESSAGE_TRANSACTION_SMS_REPLY" } }
          },
          "then": {
            "properties": {
              "poolNumber": {
                "type": "string"
              },
              "responseBody": {
                "type": "string"
              }
            }
          },
          "else": {
            "properties": {
              "subject": {
                "type": "string"
              }
            }
          },
          "required": [
            "messageId",
            "companyId",
            "workspaceId",
            "templateId",
            "recipient",
            "messageRequestId"
          ],
          "oneOf": [{ "required": ["subject"] }, { "required": ["poolNumber", "responseBody"] }]
        }
      },
      "required": ["eventType", "message"]
    }
  }
}
