{-# 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.IoTEvents.Types.SNSTopicPublishAction
-- 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.IoTEvents.Types.SNSTopicPublishAction where

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.Payload
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information required to publish the Amazon SNS message.
--
-- /See:/ 'newSNSTopicPublishAction' smart constructor.
data SNSTopicPublishAction = SNSTopicPublishAction'
  { -- | You can configure the action payload when you send a message as an
    -- Amazon SNS push notification.
    SNSTopicPublishAction -> Maybe Payload
payload :: Prelude.Maybe Payload,
    -- | The ARN of the Amazon SNS target where the message is sent.
    SNSTopicPublishAction -> Text
targetArn :: Prelude.Text
  }
  deriving (SNSTopicPublishAction -> SNSTopicPublishAction -> Bool
(SNSTopicPublishAction -> SNSTopicPublishAction -> Bool)
-> (SNSTopicPublishAction -> SNSTopicPublishAction -> Bool)
-> Eq SNSTopicPublishAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SNSTopicPublishAction -> SNSTopicPublishAction -> Bool
$c/= :: SNSTopicPublishAction -> SNSTopicPublishAction -> Bool
== :: SNSTopicPublishAction -> SNSTopicPublishAction -> Bool
$c== :: SNSTopicPublishAction -> SNSTopicPublishAction -> Bool
Prelude.Eq, ReadPrec [SNSTopicPublishAction]
ReadPrec SNSTopicPublishAction
Int -> ReadS SNSTopicPublishAction
ReadS [SNSTopicPublishAction]
(Int -> ReadS SNSTopicPublishAction)
-> ReadS [SNSTopicPublishAction]
-> ReadPrec SNSTopicPublishAction
-> ReadPrec [SNSTopicPublishAction]
-> Read SNSTopicPublishAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SNSTopicPublishAction]
$creadListPrec :: ReadPrec [SNSTopicPublishAction]
readPrec :: ReadPrec SNSTopicPublishAction
$creadPrec :: ReadPrec SNSTopicPublishAction
readList :: ReadS [SNSTopicPublishAction]
$creadList :: ReadS [SNSTopicPublishAction]
readsPrec :: Int -> ReadS SNSTopicPublishAction
$creadsPrec :: Int -> ReadS SNSTopicPublishAction
Prelude.Read, Int -> SNSTopicPublishAction -> ShowS
[SNSTopicPublishAction] -> ShowS
SNSTopicPublishAction -> String
(Int -> SNSTopicPublishAction -> ShowS)
-> (SNSTopicPublishAction -> String)
-> ([SNSTopicPublishAction] -> ShowS)
-> Show SNSTopicPublishAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SNSTopicPublishAction] -> ShowS
$cshowList :: [SNSTopicPublishAction] -> ShowS
show :: SNSTopicPublishAction -> String
$cshow :: SNSTopicPublishAction -> String
showsPrec :: Int -> SNSTopicPublishAction -> ShowS
$cshowsPrec :: Int -> SNSTopicPublishAction -> ShowS
Prelude.Show, (forall x. SNSTopicPublishAction -> Rep SNSTopicPublishAction x)
-> (forall x. Rep SNSTopicPublishAction x -> SNSTopicPublishAction)
-> Generic SNSTopicPublishAction
forall x. Rep SNSTopicPublishAction x -> SNSTopicPublishAction
forall x. SNSTopicPublishAction -> Rep SNSTopicPublishAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SNSTopicPublishAction x -> SNSTopicPublishAction
$cfrom :: forall x. SNSTopicPublishAction -> Rep SNSTopicPublishAction x
Prelude.Generic)

-- |
-- Create a value of 'SNSTopicPublishAction' 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:
--
-- 'payload', 'sNSTopicPublishAction_payload' - You can configure the action payload when you send a message as an
-- Amazon SNS push notification.
--
-- 'targetArn', 'sNSTopicPublishAction_targetArn' - The ARN of the Amazon SNS target where the message is sent.
newSNSTopicPublishAction ::
  -- | 'targetArn'
  Prelude.Text ->
  SNSTopicPublishAction
newSNSTopicPublishAction :: Text -> SNSTopicPublishAction
newSNSTopicPublishAction Text
pTargetArn_ =
  SNSTopicPublishAction' :: Maybe Payload -> Text -> SNSTopicPublishAction
SNSTopicPublishAction'
    { $sel:payload:SNSTopicPublishAction' :: Maybe Payload
payload = Maybe Payload
forall a. Maybe a
Prelude.Nothing,
      $sel:targetArn:SNSTopicPublishAction' :: Text
targetArn = Text
pTargetArn_
    }

-- | You can configure the action payload when you send a message as an
-- Amazon SNS push notification.
sNSTopicPublishAction_payload :: Lens.Lens' SNSTopicPublishAction (Prelude.Maybe Payload)
sNSTopicPublishAction_payload :: (Maybe Payload -> f (Maybe Payload))
-> SNSTopicPublishAction -> f SNSTopicPublishAction
sNSTopicPublishAction_payload = (SNSTopicPublishAction -> Maybe Payload)
-> (SNSTopicPublishAction
    -> Maybe Payload -> SNSTopicPublishAction)
-> Lens
     SNSTopicPublishAction
     SNSTopicPublishAction
     (Maybe Payload)
     (Maybe Payload)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSTopicPublishAction' {Maybe Payload
payload :: Maybe Payload
$sel:payload:SNSTopicPublishAction' :: SNSTopicPublishAction -> Maybe Payload
payload} -> Maybe Payload
payload) (\s :: SNSTopicPublishAction
s@SNSTopicPublishAction' {} Maybe Payload
a -> SNSTopicPublishAction
s {$sel:payload:SNSTopicPublishAction' :: Maybe Payload
payload = Maybe Payload
a} :: SNSTopicPublishAction)

-- | The ARN of the Amazon SNS target where the message is sent.
sNSTopicPublishAction_targetArn :: Lens.Lens' SNSTopicPublishAction Prelude.Text
sNSTopicPublishAction_targetArn :: (Text -> f Text)
-> SNSTopicPublishAction -> f SNSTopicPublishAction
sNSTopicPublishAction_targetArn = (SNSTopicPublishAction -> Text)
-> (SNSTopicPublishAction -> Text -> SNSTopicPublishAction)
-> Lens SNSTopicPublishAction SNSTopicPublishAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSTopicPublishAction' {Text
targetArn :: Text
$sel:targetArn:SNSTopicPublishAction' :: SNSTopicPublishAction -> Text
targetArn} -> Text
targetArn) (\s :: SNSTopicPublishAction
s@SNSTopicPublishAction' {} Text
a -> SNSTopicPublishAction
s {$sel:targetArn:SNSTopicPublishAction' :: Text
targetArn = Text
a} :: SNSTopicPublishAction)

instance Core.FromJSON SNSTopicPublishAction where
  parseJSON :: Value -> Parser SNSTopicPublishAction
parseJSON =
    String
-> (Object -> Parser SNSTopicPublishAction)
-> Value
-> Parser SNSTopicPublishAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SNSTopicPublishAction"
      ( \Object
x ->
          Maybe Payload -> Text -> SNSTopicPublishAction
SNSTopicPublishAction'
            (Maybe Payload -> Text -> SNSTopicPublishAction)
-> Parser (Maybe Payload) -> Parser (Text -> SNSTopicPublishAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Payload)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"payload")
            Parser (Text -> SNSTopicPublishAction)
-> Parser Text -> Parser SNSTopicPublishAction
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
"targetArn")
      )

instance Prelude.Hashable SNSTopicPublishAction

instance Prelude.NFData SNSTopicPublishAction

instance Core.ToJSON SNSTopicPublishAction where
  toJSON :: SNSTopicPublishAction -> Value
toJSON SNSTopicPublishAction' {Maybe Payload
Text
targetArn :: Text
payload :: Maybe Payload
$sel:targetArn:SNSTopicPublishAction' :: SNSTopicPublishAction -> Text
$sel:payload:SNSTopicPublishAction' :: SNSTopicPublishAction -> Maybe Payload
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"payload" Text -> Payload -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Payload -> Pair) -> Maybe Payload -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Payload
payload,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"targetArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
targetArn)
          ]
      )