{-# 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.MessageResponse
-- 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.MessageResponse where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.EndpointMessageResult
import Amazonka.Pinpoint.Types.MessageResult
import qualified Amazonka.Prelude as Prelude

-- | Provides information about the results of a request to send a message to
-- an endpoint address.
--
-- /See:/ 'newMessageResponse' smart constructor.
data MessageResponse = MessageResponse'
  { -- | The identifier for the original request that the message was delivered
    -- for.
    MessageResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | A map that contains a multipart response for each address (email
    -- address, phone number, or push notification token) that the message was
    -- sent to. In the map, the address is the key and the result is the value.
    MessageResponse -> Maybe (HashMap Text MessageResult)
result :: Prelude.Maybe (Prelude.HashMap Prelude.Text MessageResult),
    -- | A map that contains a multipart response for each address that the
    -- message was sent to. In the map, the endpoint ID is the key and the
    -- result is the value.
    MessageResponse -> Maybe (HashMap Text EndpointMessageResult)
endpointResult :: Prelude.Maybe (Prelude.HashMap Prelude.Text EndpointMessageResult),
    -- | The unique identifier for the application that was used to send the
    -- message.
    MessageResponse -> Text
applicationId :: Prelude.Text
  }
  deriving (MessageResponse -> MessageResponse -> Bool
(MessageResponse -> MessageResponse -> Bool)
-> (MessageResponse -> MessageResponse -> Bool)
-> Eq MessageResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageResponse -> MessageResponse -> Bool
$c/= :: MessageResponse -> MessageResponse -> Bool
== :: MessageResponse -> MessageResponse -> Bool
$c== :: MessageResponse -> MessageResponse -> Bool
Prelude.Eq, ReadPrec [MessageResponse]
ReadPrec MessageResponse
Int -> ReadS MessageResponse
ReadS [MessageResponse]
(Int -> ReadS MessageResponse)
-> ReadS [MessageResponse]
-> ReadPrec MessageResponse
-> ReadPrec [MessageResponse]
-> Read MessageResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageResponse]
$creadListPrec :: ReadPrec [MessageResponse]
readPrec :: ReadPrec MessageResponse
$creadPrec :: ReadPrec MessageResponse
readList :: ReadS [MessageResponse]
$creadList :: ReadS [MessageResponse]
readsPrec :: Int -> ReadS MessageResponse
$creadsPrec :: Int -> ReadS MessageResponse
Prelude.Read, Int -> MessageResponse -> ShowS
[MessageResponse] -> ShowS
MessageResponse -> String
(Int -> MessageResponse -> ShowS)
-> (MessageResponse -> String)
-> ([MessageResponse] -> ShowS)
-> Show MessageResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageResponse] -> ShowS
$cshowList :: [MessageResponse] -> ShowS
show :: MessageResponse -> String
$cshow :: MessageResponse -> String
showsPrec :: Int -> MessageResponse -> ShowS
$cshowsPrec :: Int -> MessageResponse -> ShowS
Prelude.Show, (forall x. MessageResponse -> Rep MessageResponse x)
-> (forall x. Rep MessageResponse x -> MessageResponse)
-> Generic MessageResponse
forall x. Rep MessageResponse x -> MessageResponse
forall x. MessageResponse -> Rep MessageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MessageResponse x -> MessageResponse
$cfrom :: forall x. MessageResponse -> Rep MessageResponse x
Prelude.Generic)

-- |
-- Create a value of 'MessageResponse' 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:
--
-- 'requestId', 'messageResponse_requestId' - The identifier for the original request that the message was delivered
-- for.
--
-- 'result', 'messageResponse_result' - A map that contains a multipart response for each address (email
-- address, phone number, or push notification token) that the message was
-- sent to. In the map, the address is the key and the result is the value.
--
-- 'endpointResult', 'messageResponse_endpointResult' - A map that contains a multipart response for each address that the
-- message was sent to. In the map, the endpoint ID is the key and the
-- result is the value.
--
-- 'applicationId', 'messageResponse_applicationId' - The unique identifier for the application that was used to send the
-- message.
newMessageResponse ::
  -- | 'applicationId'
  Prelude.Text ->
  MessageResponse
newMessageResponse :: Text -> MessageResponse
newMessageResponse Text
pApplicationId_ =
  MessageResponse' :: Maybe Text
-> Maybe (HashMap Text MessageResult)
-> Maybe (HashMap Text EndpointMessageResult)
-> Text
-> MessageResponse
MessageResponse'
    { $sel:requestId:MessageResponse' :: Maybe Text
requestId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:result:MessageResponse' :: Maybe (HashMap Text MessageResult)
result = Maybe (HashMap Text MessageResult)
forall a. Maybe a
Prelude.Nothing,
      $sel:endpointResult:MessageResponse' :: Maybe (HashMap Text EndpointMessageResult)
endpointResult = Maybe (HashMap Text EndpointMessageResult)
forall a. Maybe a
Prelude.Nothing,
      $sel:applicationId:MessageResponse' :: Text
applicationId = Text
pApplicationId_
    }

-- | The identifier for the original request that the message was delivered
-- for.
messageResponse_requestId :: Lens.Lens' MessageResponse (Prelude.Maybe Prelude.Text)
messageResponse_requestId :: (Maybe Text -> f (Maybe Text))
-> MessageResponse -> f MessageResponse
messageResponse_requestId = (MessageResponse -> Maybe Text)
-> (MessageResponse -> Maybe Text -> MessageResponse)
-> Lens MessageResponse MessageResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageResponse' {Maybe Text
requestId :: Maybe Text
$sel:requestId:MessageResponse' :: MessageResponse -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: MessageResponse
s@MessageResponse' {} Maybe Text
a -> MessageResponse
s {$sel:requestId:MessageResponse' :: Maybe Text
requestId = Maybe Text
a} :: MessageResponse)

-- | A map that contains a multipart response for each address (email
-- address, phone number, or push notification token) that the message was
-- sent to. In the map, the address is the key and the result is the value.
messageResponse_result :: Lens.Lens' MessageResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text MessageResult))
messageResponse_result :: (Maybe (HashMap Text MessageResult)
 -> f (Maybe (HashMap Text MessageResult)))
-> MessageResponse -> f MessageResponse
messageResponse_result = (MessageResponse -> Maybe (HashMap Text MessageResult))
-> (MessageResponse
    -> Maybe (HashMap Text MessageResult) -> MessageResponse)
-> Lens
     MessageResponse
     MessageResponse
     (Maybe (HashMap Text MessageResult))
     (Maybe (HashMap Text MessageResult))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageResponse' {Maybe (HashMap Text MessageResult)
result :: Maybe (HashMap Text MessageResult)
$sel:result:MessageResponse' :: MessageResponse -> Maybe (HashMap Text MessageResult)
result} -> Maybe (HashMap Text MessageResult)
result) (\s :: MessageResponse
s@MessageResponse' {} Maybe (HashMap Text MessageResult)
a -> MessageResponse
s {$sel:result:MessageResponse' :: Maybe (HashMap Text MessageResult)
result = Maybe (HashMap Text MessageResult)
a} :: MessageResponse) ((Maybe (HashMap Text MessageResult)
  -> f (Maybe (HashMap Text MessageResult)))
 -> MessageResponse -> f MessageResponse)
-> ((Maybe (HashMap Text MessageResult)
     -> f (Maybe (HashMap Text MessageResult)))
    -> Maybe (HashMap Text MessageResult)
    -> f (Maybe (HashMap Text MessageResult)))
-> (Maybe (HashMap Text MessageResult)
    -> f (Maybe (HashMap Text MessageResult)))
-> MessageResponse
-> f MessageResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text MessageResult)
  (HashMap Text MessageResult)
  (HashMap Text MessageResult)
  (HashMap Text MessageResult)
-> Iso
     (Maybe (HashMap Text MessageResult))
     (Maybe (HashMap Text MessageResult))
     (Maybe (HashMap Text MessageResult))
     (Maybe (HashMap Text MessageResult))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text MessageResult)
  (HashMap Text MessageResult)
  (HashMap Text MessageResult)
  (HashMap Text MessageResult)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A map that contains a multipart response for each address that the
-- message was sent to. In the map, the endpoint ID is the key and the
-- result is the value.
messageResponse_endpointResult :: Lens.Lens' MessageResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text EndpointMessageResult))
messageResponse_endpointResult :: (Maybe (HashMap Text EndpointMessageResult)
 -> f (Maybe (HashMap Text EndpointMessageResult)))
-> MessageResponse -> f MessageResponse
messageResponse_endpointResult = (MessageResponse -> Maybe (HashMap Text EndpointMessageResult))
-> (MessageResponse
    -> Maybe (HashMap Text EndpointMessageResult) -> MessageResponse)
-> Lens
     MessageResponse
     MessageResponse
     (Maybe (HashMap Text EndpointMessageResult))
     (Maybe (HashMap Text EndpointMessageResult))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageResponse' {Maybe (HashMap Text EndpointMessageResult)
endpointResult :: Maybe (HashMap Text EndpointMessageResult)
$sel:endpointResult:MessageResponse' :: MessageResponse -> Maybe (HashMap Text EndpointMessageResult)
endpointResult} -> Maybe (HashMap Text EndpointMessageResult)
endpointResult) (\s :: MessageResponse
s@MessageResponse' {} Maybe (HashMap Text EndpointMessageResult)
a -> MessageResponse
s {$sel:endpointResult:MessageResponse' :: Maybe (HashMap Text EndpointMessageResult)
endpointResult = Maybe (HashMap Text EndpointMessageResult)
a} :: MessageResponse) ((Maybe (HashMap Text EndpointMessageResult)
  -> f (Maybe (HashMap Text EndpointMessageResult)))
 -> MessageResponse -> f MessageResponse)
-> ((Maybe (HashMap Text EndpointMessageResult)
     -> f (Maybe (HashMap Text EndpointMessageResult)))
    -> Maybe (HashMap Text EndpointMessageResult)
    -> f (Maybe (HashMap Text EndpointMessageResult)))
-> (Maybe (HashMap Text EndpointMessageResult)
    -> f (Maybe (HashMap Text EndpointMessageResult)))
-> MessageResponse
-> f MessageResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text EndpointMessageResult)
  (HashMap Text EndpointMessageResult)
  (HashMap Text EndpointMessageResult)
  (HashMap Text EndpointMessageResult)
-> Iso
     (Maybe (HashMap Text EndpointMessageResult))
     (Maybe (HashMap Text EndpointMessageResult))
     (Maybe (HashMap Text EndpointMessageResult))
     (Maybe (HashMap Text EndpointMessageResult))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text EndpointMessageResult)
  (HashMap Text EndpointMessageResult)
  (HashMap Text EndpointMessageResult)
  (HashMap Text EndpointMessageResult)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The unique identifier for the application that was used to send the
-- message.
messageResponse_applicationId :: Lens.Lens' MessageResponse Prelude.Text
messageResponse_applicationId :: (Text -> f Text) -> MessageResponse -> f MessageResponse
messageResponse_applicationId = (MessageResponse -> Text)
-> (MessageResponse -> Text -> MessageResponse)
-> Lens MessageResponse MessageResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageResponse' {Text
applicationId :: Text
$sel:applicationId:MessageResponse' :: MessageResponse -> Text
applicationId} -> Text
applicationId) (\s :: MessageResponse
s@MessageResponse' {} Text
a -> MessageResponse
s {$sel:applicationId:MessageResponse' :: Text
applicationId = Text
a} :: MessageResponse)

instance Core.FromJSON MessageResponse where
  parseJSON :: Value -> Parser MessageResponse
parseJSON =
    String
-> (Object -> Parser MessageResponse)
-> Value
-> Parser MessageResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MessageResponse"
      ( \Object
x ->
          Maybe Text
-> Maybe (HashMap Text MessageResult)
-> Maybe (HashMap Text EndpointMessageResult)
-> Text
-> MessageResponse
MessageResponse'
            (Maybe Text
 -> Maybe (HashMap Text MessageResult)
 -> Maybe (HashMap Text EndpointMessageResult)
 -> Text
 -> MessageResponse)
-> Parser (Maybe Text)
-> Parser
     (Maybe (HashMap Text MessageResult)
      -> Maybe (HashMap Text EndpointMessageResult)
      -> Text
      -> MessageResponse)
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
"RequestId")
            Parser
  (Maybe (HashMap Text MessageResult)
   -> Maybe (HashMap Text EndpointMessageResult)
   -> Text
   -> MessageResponse)
-> Parser (Maybe (HashMap Text MessageResult))
-> Parser
     (Maybe (HashMap Text EndpointMessageResult)
      -> Text -> MessageResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe (Maybe (HashMap Text MessageResult)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Result" Parser (Maybe (Maybe (HashMap Text MessageResult)))
-> Maybe (HashMap Text MessageResult)
-> Parser (Maybe (HashMap Text MessageResult))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text MessageResult)
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe (HashMap Text EndpointMessageResult)
   -> Text -> MessageResponse)
-> Parser (Maybe (HashMap Text EndpointMessageResult))
-> Parser (Text -> MessageResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text
-> Parser (Maybe (Maybe (HashMap Text EndpointMessageResult)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EndpointResult" Parser (Maybe (Maybe (HashMap Text EndpointMessageResult)))
-> Maybe (HashMap Text EndpointMessageResult)
-> Parser (Maybe (HashMap Text EndpointMessageResult))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text EndpointMessageResult)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> MessageResponse)
-> Parser Text -> Parser MessageResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ApplicationId")
      )

instance Prelude.Hashable MessageResponse

instance Prelude.NFData MessageResponse