CREATE PROCEDURE dbo.ReceiveDeliveryNotification @AMessageID VARCHAR(255), @ADateStamp DATETIME, @AStatus VARCHAR(100), @AStatusCode VARCHAR(100), @AReason VARCHAR(100), @ADateSent DATETIME AS
/*
  Created by Arne Munch, March 2020
  Receive a Delivery Notification from the LINK Mobility Copycat API

  Changes:

*/

SET NOCOUNT ON

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

IF @AStatus = 'received'
BEGIN
  SET @LogState = 3 -- sslsSuccessfulDelivery
  SET @Message = 'The message was delivered correctly'
  SET @Text = 'The message was delivered to recipient at ' + CONVERT(VARCHAR, @ADateSent, 112)
END
ELSE
BEGIN
  SET @LogState = -5 -- sslsErrorDelivery
  SET @Message = 'The message could not be delivered'
  SET @Text = 'Status: ' + @AStatus + ', Statuscode: ' + @AStatusCode + ', Reason: ' + @AReason
END

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