{-# 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.MessageResult
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Pinpoint.Types.MessageResult where

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

-- | Provides information about the results of sending a message directly to
-- an endpoint address.
--
-- /See:/ 'newMessageResult' smart constructor.
data MessageResult = MessageResult'
  { -- | The unique identifier for the message that was sent.
    MessageResult -> Maybe Text
messageId :: Prelude.Maybe Prelude.Text,
    -- | The status message for delivering the message.
    MessageResult -> 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.
    MessageResult -> Maybe Text
updatedToken :: 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 address 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 address. Amazon Pinpoint won\'t attempt to send the
    --     message again.
    --
    -- -   SUCCESSFUL - The message was successfully delivered to the endpoint
    --     address.
    --
    -- -   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 address.
    --
    -- -   TIMEOUT - The message couldn\'t be sent within the timeout period.
    --
    -- -   UNKNOWN_FAILURE - An unknown error occurred.
    MessageResult -> DeliveryStatus
deliveryStatus :: DeliveryStatus,
    -- | The downstream service status code for delivering the message.
    MessageResult -> Int
statusCode :: Prelude.Int
  }
  deriving (MessageResult -> MessageResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageResult -> MessageResult -> Bool
$c/= :: MessageResult -> MessageResult -> Bool
== :: MessageResult -> MessageResult -> Bool
$c== :: MessageResult -> MessageResult -> Bool
Prelude.Eq, ReadPrec [MessageResult]
ReadPrec MessageResult
Int -> ReadS MessageResult
ReadS [MessageResult]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageResult]
$creadListPrec :: ReadPrec [MessageResult]
readPrec :: ReadPrec MessageResult
$creadPrec :: ReadPrec MessageResult
readList :: ReadS [MessageResult]
$creadList :: ReadS [MessageResult]
readsPrec :: Int -> ReadS MessageResult
$creadsPrec :: Int -> ReadS MessageResult
Prelude.Read, Int -> MessageResult -> ShowS
[MessageResult] -> ShowS
MessageResult -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageResult] -> ShowS
$cshowList :: [MessageResult] -> ShowS
show :: MessageResult -> String
$cshow :: MessageResult -> String
showsPrec :: Int -> MessageResult -> ShowS
$cshowsPrec :: Int -> MessageResult -> ShowS
Prelude.Show, forall x. Rep MessageResult x -> MessageResult
forall x. MessageResult -> Rep MessageResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MessageResult x -> MessageResult
$cfrom :: forall x. MessageResult -> Rep MessageResult x
Prelude.Generic)

-- |
-- Create a value of 'MessageResult' 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:
--
-- 'messageId', 'messageResult_messageId' - The unique identifier for the message that was sent.
--
-- 'statusMessage', 'messageResult_statusMessage' - The status message for delivering the message.
--
-- 'updatedToken', 'messageResult_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.
--
-- 'deliveryStatus', 'messageResult_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 address 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 address. Amazon Pinpoint won\'t attempt to send the
--     message again.
--
-- -   SUCCESSFUL - The message was successfully delivered to the endpoint
--     address.
--
-- -   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 address.
--
-- -   TIMEOUT - The message couldn\'t be sent within the timeout period.
--
-- -   UNKNOWN_FAILURE - An unknown error occurred.
--
-- 'statusCode', 'messageResult_statusCode' - The downstream service status code for delivering the message.
newMessageResult ::
  -- | 'deliveryStatus'
  DeliveryStatus ->
  -- | 'statusCode'
  Prelude.Int ->
  MessageResult
newMessageResult :: DeliveryStatus -> Int -> MessageResult
newMessageResult DeliveryStatus
pDeliveryStatus_ Int
pStatusCode_ =
  MessageResult'
    { $sel:messageId:MessageResult' :: Maybe Text
messageId = forall a. Maybe a
Prelude.Nothing,
      $sel:statusMessage:MessageResult' :: Maybe Text
statusMessage = forall a. Maybe a
Prelude.Nothing,
      $sel:updatedToken:MessageResult' :: Maybe Text
updatedToken = forall a. Maybe a
Prelude.Nothing,
      $sel:deliveryStatus:MessageResult' :: DeliveryStatus
deliveryStatus = DeliveryStatus
pDeliveryStatus_,
      $sel:statusCode:MessageResult' :: Int
statusCode = Int
pStatusCode_
    }

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

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

-- | 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.
messageResult_updatedToken :: Lens.Lens' MessageResult (Prelude.Maybe Prelude.Text)
messageResult_updatedToken :: Lens' MessageResult (Maybe Text)
messageResult_updatedToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageResult' {Maybe Text
updatedToken :: Maybe Text
$sel:updatedToken:MessageResult' :: MessageResult -> Maybe Text
updatedToken} -> Maybe Text
updatedToken) (\s :: MessageResult
s@MessageResult' {} Maybe Text
a -> MessageResult
s {$sel:updatedToken:MessageResult' :: Maybe Text
updatedToken = Maybe Text
a} :: MessageResult)

-- | 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 address 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 address. Amazon Pinpoint won\'t attempt to send the
--     message again.
--
-- -   SUCCESSFUL - The message was successfully delivered to the endpoint
--     address.
--
-- -   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 address.
--
-- -   TIMEOUT - The message couldn\'t be sent within the timeout period.
--
-- -   UNKNOWN_FAILURE - An unknown error occurred.
messageResult_deliveryStatus :: Lens.Lens' MessageResult DeliveryStatus
messageResult_deliveryStatus :: Lens' MessageResult DeliveryStatus
messageResult_deliveryStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageResult' {DeliveryStatus
deliveryStatus :: DeliveryStatus
$sel:deliveryStatus:MessageResult' :: MessageResult -> DeliveryStatus
deliveryStatus} -> DeliveryStatus
deliveryStatus) (\s :: MessageResult
s@MessageResult' {} DeliveryStatus
a -> MessageResult
s {$sel:deliveryStatus:MessageResult' :: DeliveryStatus
deliveryStatus = DeliveryStatus
a} :: MessageResult)

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

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

instance Prelude.Hashable MessageResult where
  hashWithSalt :: Int -> MessageResult -> Int
hashWithSalt Int
_salt MessageResult' {Int
Maybe Text
DeliveryStatus
statusCode :: Int
deliveryStatus :: DeliveryStatus
updatedToken :: Maybe Text
statusMessage :: Maybe Text
messageId :: Maybe Text
$sel:statusCode:MessageResult' :: MessageResult -> Int
$sel:deliveryStatus:MessageResult' :: MessageResult -> DeliveryStatus
$sel:updatedToken:MessageResult' :: MessageResult -> Maybe Text
$sel:statusMessage:MessageResult' :: MessageResult -> Maybe Text
$sel:messageId:MessageResult' :: MessageResult -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
messageId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
statusMessage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
updatedToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DeliveryStatus
deliveryStatus
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
statusCode

instance Prelude.NFData MessageResult where
  rnf :: MessageResult -> ()
rnf MessageResult' {Int
Maybe Text
DeliveryStatus
statusCode :: Int
deliveryStatus :: DeliveryStatus
updatedToken :: Maybe Text
statusMessage :: Maybe Text
messageId :: Maybe Text
$sel:statusCode:MessageResult' :: MessageResult -> Int
$sel:deliveryStatus:MessageResult' :: MessageResult -> DeliveryStatus
$sel:updatedToken:MessageResult' :: MessageResult -> Maybe Text
$sel:statusMessage:MessageResult' :: MessageResult -> Maybe Text
$sel:messageId:MessageResult' :: MessageResult -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
messageId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
statusMessage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
updatedToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DeliveryStatus
deliveryStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
statusCode