CREATE PROCEDURE dbo.ReceiveDeliveryReportSendmode @AMessageID VARCHAR(255), @ADateStamp DATETIME, @AStatus VARCHAR(100) AS
/*
  Created by Arne Munch, September 2022
  Receive a Delivery Report from the Sendmode REST API

  Changes:

*/

SET NOCOUNT ON

DECLARE
@LogState INT,
@Text VARCHAR(2000),
@Message VARCHAR(2000)

IF @AStatus = 'DELIVRD'
BEGIN
  SET @LogState = 3 -- sslsSuccessfulDelivery
  SET @Message = 'The message was delivered correctly'
  SET @Text = ''
END
ELSE
BEGIN
  SET @LogState = -5 -- sslsErrorDelivery
  SET @Message = 'The message could not be delivered'
  SET @Text = 'Status: ' + @AStatus
END

EXEC PostDeliveryReportAndNotification @AMessageID, @ADateStamp, @LogState, @Message, @Text
