{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Pinpoint.Types.EndpointMessageResult
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Pinpoint.Types.EndpointMessageResult where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.DeliveryStatus
import qualified Amazonka.Prelude as Prelude

-- | Provides information about the delivery status and results of sending a
-- message directly to an endpoint.
--
-- /See:/ 'newEndpointMessageResult' smart constructor.
data EndpointMessageResult = EndpointMessageResult'
  { -- | The endpoint address that the message was delivered to.
    EndpointMessageResult -> Maybe Text
address :: Prelude.Maybe Prelude.Text,
    -- | The status message for delivering the message.
    EndpointMessageResult -> Maybe Text
statusMessage :: Prelude.Maybe Prelude.Text,
    -- | For push notifications that are sent through the GCM channel, specifies
    -- whether the endpoint\'s device registration token was updated as part of
    -- delivering the message.
    EndpointMessageResult -> Maybe Text
updatedToken :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier for the message that was sent.
    EndpointMessageResult -> Maybe Text
messageId :: Prelude.Maybe Prelude.Text,
    -- | The delivery status of the message. Possible values are:
    --
    -- -   DUPLICATE - The endpoint address is a duplicate of another endpoint
    --     address. Amazon Pinpoint won\'t attempt to send the message again.
    --
    -- -   OPT_OUT - The user who\'s associated with the endpoint has opted out
    --     of receiving messages from you. Amazon Pinpoint won\'t attempt to
    --     send the message again.
    --
    -- -   PERMANENT_FAILURE - An error occurred when delivering the message to
    --     the endpoint. Amazon Pinpoint won\'t attempt to send the message
    --     again.
    --
    -- -   SUCCESSFUL - The message was successfully delivered to the endpoint.
    --
    -- -   TEMPORARY_FAILURE - A temporary error occurred. Amazon Pinpoint
    --     won\'t attempt to send the message again.
    --
    -- -   THROTTLED - Amazon Pinpoint throttled the operation to send the
    --     message to the endpoint.
    --
    -- -   TIMEOUT - The message couldn\'t be sent within the timeout period.
    --
    -- -   UNKNOWN_FAILURE - An unknown error occurred.
    EndpointMessageResult -> DeliveryStatus
deliveryStatus :: DeliveryStatus,
    -- | The downstream service status code for delivering the message.
    EndpointMessageResult -> Int
statusCode :: Prelude.Int
  }
  deriving (EndpointMessageResult -> EndpointMessageResult -> Bool
(EndpointMessageResult -> EndpointMessageResult -> Bool)
-> (EndpointMessageResult -> EndpointMessageResult -> Bool)
-> Eq EndpointMessageResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EndpointMessageResult -> EndpointMessageResult -> Bool
$c/= :: EndpointMessageResult -> EndpointMessageResult -> Bool
== :: EndpointMessageResult -> EndpointMessageResult -> Bool
$c== :: EndpointMessageResult -> EndpointMessageResult -> Bool
Prelude.Eq, ReadPrec [EndpointMessageResult]
ReadPrec EndpointMessageResult
Int -> ReadS EndpointMessageResult
ReadS [EndpointMessageResult]
(Int -> ReadS EndpointMessageResult)
-> ReadS [EndpointMessageResult]
-> ReadPrec EndpointMessageResult
-> ReadPrec [EndpointMessageResult]
-> Read EndpointMessageResult
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EndpointMessageResult]
$creadListPrec :: ReadPrec [EndpointMessageResult]
readPrec :: ReadPrec EndpointMessageResult
$creadPrec :: ReadPrec EndpointMessageResult
readList :: ReadS [EndpointMessageResult]
$creadList :: ReadS [EndpointMessageResult]
readsPrec :: Int -> ReadS EndpointMessageResult
$creadsPrec :: Int -> ReadS EndpointMessageResult
Prelude.Read, Int -> EndpointMessageResult -> ShowS
[EndpointMessageResult] -> ShowS
EndpointMessageResult -> String
(Int -> EndpointMessageResult -> ShowS)
-> (EndpointMessageResult -> String)
-> ([EndpointMessageResult] -> ShowS)
-> Show EndpointMessageResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EndpointMessageResult] -> ShowS
$cshowList :: [EndpointMessageResult] -> ShowS
show :: EndpointMessageResult -> String
$cshow :: EndpointMessageResult -> String
showsPrec :: Int -> EndpointMessageResult -> ShowS
$cshowsPrec :: Int -> EndpointMessageResult -> ShowS
Prelude.Show, (forall x. EndpointMessageResult -> Rep EndpointMessageResult x)
-> (forall x. Rep EndpointMessageResult x -> EndpointMessageResult)
-> Generic EndpointMessageResult
forall x. Rep EndpointMessageResult x -> EndpointMessageResult
forall x. EndpointMessageResult -> Rep EndpointMessageResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EndpointMessageResult x -> EndpointMessageResult
$cfrom :: forall x. EndpointMessageResult -> Rep EndpointMessageResult x
Prelude.Generic)

-- |
-- Create a value of 'EndpointMessageResult' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'address', 'endpointMessageResult_address' - The endpoint address that the message was delivered to.
--
-- 'statusMessage', 'endpointMessageResult_statusMessage' - The status message for delivering the message.
--
-- 'updatedToken', 'endpointMessageResult_updatedToken' - For push notifications that are sent through the GCM channel, specifies
-- whether the endpoint\'s device registration token was updated as part of
-- delivering the message.
--
-- 'messageId', 'endpointMessageResult_messageId' - The unique identifier for the message that was sent.
--
-- 'deliveryStatus', 'endpointMessageResult_deliveryStatus' - The delivery status of the message. Possible values are:
--
-- -   DUPLICATE - The endpoint address is a duplicate of another endpoint
--     address. Amazon Pinpoint won\'t attempt to send the message again.
--
-- -   OPT_OUT - The user who\'s associated with the endpoint has opted out
--     of receiving messages from you. Amazon Pinpoint won\'t attempt to
--     send the message again.
--
-- -   PERMANENT_FAILURE - An error occurred when delivering the message to
--     the endpoint. Amazon Pinpoint won\'t attempt to send the message
--     again.
--
-- -   SUCCESSFUL - The message was successfully delivered to the endpoint.
--
-- -   TEMPORARY_FAILURE - A temporary error occurred. Amazon Pinpoint
--     won\'t attempt to send the message again.
--
-- -   THROTTLED - Amazon Pinpoint throttled the operation to send the
--     message to the endpoint.
--
-- -   TIMEOUT - The message couldn\'t be sent within the timeout period.
--
-- -   UNKNOWN_FAILURE - An unknown error occurred.
--
-- 'statusCode', 'endpointMessageResult_statusCode' - The downstream service status code for delivering the message.
newEndpointMessageResult ::
  -- | 'deliveryStatus'
  DeliveryStatus ->
  -- | 'statusCode'
  Prelude.Int ->
  EndpointMessageResult
newEndpointMessageResult :: DeliveryStatus -> Int -> EndpointMessageResult
newEndpointMessageResult
  DeliveryStatus
pDeliveryStatus_
  Int
pStatusCode_ =
    EndpointMessageResult' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> DeliveryStatus
-> Int
-> EndpointMessageResult
EndpointMessageResult'
      { $sel:address:EndpointMessageResult' :: Maybe Text
address = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:statusMessage:EndpointMessageResult' :: Maybe Text
statusMessage = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:updatedToken:EndpointMessageResult' :: Maybe Text
updatedToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:messageId:EndpointMessageResult' :: Maybe Text
messageId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:deliveryStatus:EndpointMessageResult' :: DeliveryStatus
deliveryStatus = DeliveryStatus
pDeliveryStatus_,
        $sel:statusCode:EndpointMessageResult' :: Int
statusCode = Int
pStatusCode_
      }

-- | The endpoint address that the message was delivered to.
endpointMessageResult_address :: Lens.Lens' EndpointMessageResult (Prelude.Maybe Prelude.Text)
endpointMessageResult_address :: (Maybe Text -> f (Maybe Text))
-> EndpointMessageResult -> f EndpointMessageResult
endpointMessageResult_address = (EndpointMessageResult -> Maybe Text)
-> (EndpointMessageResult -> Maybe Text -> EndpointMessageResult)
-> Lens
     EndpointMessageResult
     EndpointMessageResult
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointMessageResult' {Maybe Text
address :: Maybe Text
$sel:address:EndpointMessageResult' :: EndpointMessageResult -> Maybe Text
address} -> Maybe Text
address) (\s :: EndpointMessageResult
s@EndpointMessageResult' {} Maybe Text
a -> EndpointMessageResult
s {$sel:address:EndpointMessageResult' :: Maybe Text
address = Maybe Text
a} :: EndpointMessageResult)

-- | The status message for delivering the message.
endpointMessageResult_statusMessage :: Lens.Lens' EndpointMessageResult (Prelude.Maybe Prelude.Text)
endpointMessageResult_statusMessage :: (Maybe Text -> f (Maybe Text))
-> EndpointMessageResult -> f EndpointMessageResult
endpointMessageResult_statusMessage = (EndpointMessageResult -> Maybe Text)
-> (EndpointMessageResult -> Maybe Text -> EndpointMessageResult)
-> Lens
     EndpointMessageResult
     EndpointMessageResult
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointMessageResult' {Maybe Text
statusMessage :: Maybe Text
$sel:statusMessage:EndpointMessageResult' :: EndpointMessageResult -> Maybe Text
statusMessage} -> Maybe Text
statusMessage) (\s :: EndpointMessageResult
s@EndpointMessageResult' {} Maybe Text
a -> EndpointMessageResult
s {$sel:statusMessage:EndpointMessageResult' :: Maybe Text
statusMessage = Maybe Text
a} :: EndpointMessageResult)

-- | For push notifications that are sent through the GCM channel, specifies
-- whether the endpoint\'s device registration token was updated as part of
-- delivering the message.
endpointMessageResult_updatedToken :: Lens.Lens' EndpointMessageResult (Prelude.Maybe Prelude.Text)
endpointMessageResult_updatedToken :: (Maybe Text -> f (Maybe Text))
-> EndpointMessageResult -> f EndpointMessageResult
endpointMessageResult_updatedToken = (EndpointMessageResult -> Maybe Text)
-> (EndpointMessageResult -> Maybe Text -> EndpointMessageResult)
-> Lens
     EndpointMessageResult
     EndpointMessageResult
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointMessageResult' {Maybe Text
updatedToken :: Maybe Text
$sel:updatedToken:EndpointMessageResult' :: EndpointMessageResult -> Maybe Text
updatedToken} -> Maybe Text
updatedToken) (\s :: EndpointMessageResult
s@EndpointMessageResult' {} Maybe Text
a -> EndpointMessageResult
s {$sel:updatedToken:EndpointMessageResult' :: Maybe Text
updatedToken = Maybe Text
a} :: EndpointMessageResult)

-- | The unique identifier for the message that was sent.
endpointMessageResult_messageId :: Lens.Lens' EndpointMessageResult (Prelude.Maybe Prelude.Text)
endpointMessageResult_messageId :: (Maybe Text -> f (Maybe Text))
-> EndpointMessageResult -> f EndpointMessageResult
endpointMessageResult_messageId = (EndpointMessageResult -> Maybe Text)
-> (EndpointMessageResult -> Maybe Text -> EndpointMessageResult)
-> Lens
     EndpointMessageResult
     EndpointMessageResult
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointMessageResult' {Maybe Text
messageId :: Maybe Text
$sel:messageId:EndpointMessageResult' :: EndpointMessageResult -> Maybe Text
messageId} -> Maybe Text
messageId) (\s :: EndpointMessageResult
s@EndpointMessageResult' {} Maybe Text
a -> EndpointMessageResult
s {$sel:messageId:EndpointMessageResult' :: Maybe Text
messageId = Maybe Text
a} :: EndpointMessageResult)

-- | The delivery status of the message. Possible values are:
--
-- -   DUPLICATE - The endpoint address is a duplicate of another endpoint
--     address. Amazon Pinpoint won\'t attempt to send the message again.
--
-- -   OPT_OUT - The user who\'s associated with the endpoint has opted out
--     of receiving messages from you. Amazon Pinpoint won\'t attempt to
--     send the message again.
--
-- -   PERMANENT_FAILURE - An error occurred when delivering the message to
--     the endpoint. Amazon Pinpoint won\'t attempt to send the message
--     again.
--
-- -   SUCCESSFUL - The message was successfully delivered to the endpoint.
--
-- -   TEMPORARY_FAILURE - A temporary error occurred. Amazon Pinpoint
--     won\'t attempt to send the message again.
--
-- -   THROTTLED - Amazon Pinpoint throttled the operation to send the
--     message to the endpoint.
--
-- -   TIMEOUT - The message couldn\'t be sent within the timeout period.
--
-- -   UNKNOWN_FAILURE - An unknown error occurred.
endpointMessageResult_deliveryStatus :: Lens.Lens' EndpointMessageResult DeliveryStatus
endpointMessageResult_deliveryStatus :: (DeliveryStatus -> f DeliveryStatus)
-> EndpointMessageResult -> f EndpointMessageResult
endpointMessageResult_deliveryStatus = (EndpointMessageResult -> DeliveryStatus)
-> (EndpointMessageResult
    -> DeliveryStatus -> EndpointMessageResult)
-> Lens
     EndpointMessageResult
     EndpointMessageResult
     DeliveryStatus
     DeliveryStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointMessageResult' {DeliveryStatus
deliveryStatus :: DeliveryStatus
$sel:deliveryStatus:EndpointMessageResult' :: EndpointMessageResult -> DeliveryStatus
deliveryStatus} -> DeliveryStatus
deliveryStatus) (\s :: EndpointMessageResult
s@EndpointMessageResult' {} DeliveryStatus
a -> EndpointMessageResult
s {$sel:deliveryStatus:EndpointMessageResult' :: DeliveryStatus
deliveryStatus = DeliveryStatus
a} :: EndpointMessageResult)

-- | The downstream service status code for delivering the message.
endpointMessageResult_statusCode :: Lens.Lens' EndpointMessageResult Prelude.Int
endpointMessageResult_statusCode :: (Int -> f Int) -> EndpointMessageResult -> f EndpointMessageResult
endpointMessageResult_statusCode = (EndpointMessageResult -> Int)
-> (EndpointMessageResult -> Int -> EndpointMessageResult)
-> Lens EndpointMessageResult EndpointMessageResult Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointMessageResult' {Int
statusCode :: Int
$sel:statusCode:EndpointMessageResult' :: EndpointMessageResult -> Int
statusCode} -> Int
statusCode) (\s :: EndpointMessageResult
s@EndpointMessageResult' {} Int
a -> EndpointMessageResult
s {$sel:statusCode:EndpointMessageResult' :: Int
statusCode = Int
a} :: EndpointMessageResult)

instance Core.FromJSON EndpointMessageResult where
  parseJSON :: Value -> Parser EndpointMessageResult
parseJSON =
    String
-> (Object -> Parser EndpointMessageResult)
-> Value
-> Parser EndpointMessageResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EndpointMessageResult"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> DeliveryStatus
-> Int
-> EndpointMessageResult
EndpointMessageResult'
            (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> DeliveryStatus
 -> Int
 -> EndpointMessageResult)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> DeliveryStatus
      -> Int
      -> EndpointMessageResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Address")
            Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> DeliveryStatus
   -> Int
   -> EndpointMessageResult)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text -> DeliveryStatus -> Int -> EndpointMessageResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StatusMessage")
            Parser
  (Maybe Text
   -> Maybe Text -> DeliveryStatus -> Int -> EndpointMessageResult)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> DeliveryStatus -> Int -> EndpointMessageResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UpdatedToken")
            Parser
  (Maybe Text -> DeliveryStatus -> Int -> EndpointMessageResult)
-> Parser (Maybe Text)
-> Parser (DeliveryStatus -> Int -> EndpointMessageResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MessageId")
            Parser (DeliveryStatus -> Int -> EndpointMessageResult)
-> Parser DeliveryStatus -> Parser (Int -> EndpointMessageResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser DeliveryStatus
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DeliveryStatus")
            Parser (Int -> EndpointMessageResult)
-> Parser Int -> Parser EndpointMessageResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"StatusCode")
      )

instance Prelude.Hashable EndpointMessageResult

instance Prelude.NFData EndpointMessageResult