{-# 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.IoT.Types.SnsAction
-- 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.IoT.Types.SnsAction where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.MessageFormat
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to publish to an Amazon SNS topic.
--
-- /See:/ 'newSnsAction' smart constructor.
data SnsAction = SnsAction'
  { -- | (Optional) The message format of the message to publish. Accepted values
    -- are \"JSON\" and \"RAW\". The default value of the attribute is \"RAW\".
    -- SNS uses this setting to determine if the payload should be parsed and
    -- relevant platform-specific bits of the payload should be extracted. To
    -- read more about SNS message formats, see
    -- <https://docs.aws.amazon.com/sns/latest/dg/json-formats.html> refer to
    -- their official documentation.
    SnsAction -> Maybe MessageFormat
messageFormat :: Prelude.Maybe MessageFormat,
    -- | The ARN of the SNS topic.
    SnsAction -> Text
targetArn :: Prelude.Text,
    -- | The ARN of the IAM role that grants access.
    SnsAction -> Text
roleArn :: Prelude.Text
  }
  deriving (SnsAction -> SnsAction -> Bool
(SnsAction -> SnsAction -> Bool)
-> (SnsAction -> SnsAction -> Bool) -> Eq SnsAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SnsAction -> SnsAction -> Bool
$c/= :: SnsAction -> SnsAction -> Bool
== :: SnsAction -> SnsAction -> Bool
$c== :: SnsAction -> SnsAction -> Bool
Prelude.Eq, ReadPrec [SnsAction]
ReadPrec SnsAction
Int -> ReadS SnsAction
ReadS [SnsAction]
(Int -> ReadS SnsAction)
-> ReadS [SnsAction]
-> ReadPrec SnsAction
-> ReadPrec [SnsAction]
-> Read SnsAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SnsAction]
$creadListPrec :: ReadPrec [SnsAction]
readPrec :: ReadPrec SnsAction
$creadPrec :: ReadPrec SnsAction
readList :: ReadS [SnsAction]
$creadList :: ReadS [SnsAction]
readsPrec :: Int -> ReadS SnsAction
$creadsPrec :: Int -> ReadS SnsAction
Prelude.Read, Int -> SnsAction -> ShowS
[SnsAction] -> ShowS
SnsAction -> String
(Int -> SnsAction -> ShowS)
-> (SnsAction -> String)
-> ([SnsAction] -> ShowS)
-> Show SnsAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SnsAction] -> ShowS
$cshowList :: [SnsAction] -> ShowS
show :: SnsAction -> String
$cshow :: SnsAction -> String
showsPrec :: Int -> SnsAction -> ShowS
$cshowsPrec :: Int -> SnsAction -> ShowS
Prelude.Show, (forall x. SnsAction -> Rep SnsAction x)
-> (forall x. Rep SnsAction x -> SnsAction) -> Generic SnsAction
forall x. Rep SnsAction x -> SnsAction
forall x. SnsAction -> Rep SnsAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SnsAction x -> SnsAction
$cfrom :: forall x. SnsAction -> Rep SnsAction x
Prelude.Generic)

-- |
-- Create a value of 'SnsAction' 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:
--
-- 'messageFormat', 'snsAction_messageFormat' - (Optional) The message format of the message to publish. Accepted values
-- are \"JSON\" and \"RAW\". The default value of the attribute is \"RAW\".
-- SNS uses this setting to determine if the payload should be parsed and
-- relevant platform-specific bits of the payload should be extracted. To
-- read more about SNS message formats, see
-- <https://docs.aws.amazon.com/sns/latest/dg/json-formats.html> refer to
-- their official documentation.
--
-- 'targetArn', 'snsAction_targetArn' - The ARN of the SNS topic.
--
-- 'roleArn', 'snsAction_roleArn' - The ARN of the IAM role that grants access.
newSnsAction ::
  -- | 'targetArn'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  SnsAction
newSnsAction :: Text -> Text -> SnsAction
newSnsAction Text
pTargetArn_ Text
pRoleArn_ =
  SnsAction' :: Maybe MessageFormat -> Text -> Text -> SnsAction
SnsAction'
    { $sel:messageFormat:SnsAction' :: Maybe MessageFormat
messageFormat = Maybe MessageFormat
forall a. Maybe a
Prelude.Nothing,
      $sel:targetArn:SnsAction' :: Text
targetArn = Text
pTargetArn_,
      $sel:roleArn:SnsAction' :: Text
roleArn = Text
pRoleArn_
    }

-- | (Optional) The message format of the message to publish. Accepted values
-- are \"JSON\" and \"RAW\". The default value of the attribute is \"RAW\".
-- SNS uses this setting to determine if the payload should be parsed and
-- relevant platform-specific bits of the payload should be extracted. To
-- read more about SNS message formats, see
-- <https://docs.aws.amazon.com/sns/latest/dg/json-formats.html> refer to
-- their official documentation.
snsAction_messageFormat :: Lens.Lens' SnsAction (Prelude.Maybe MessageFormat)
snsAction_messageFormat :: (Maybe MessageFormat -> f (Maybe MessageFormat))
-> SnsAction -> f SnsAction
snsAction_messageFormat = (SnsAction -> Maybe MessageFormat)
-> (SnsAction -> Maybe MessageFormat -> SnsAction)
-> Lens
     SnsAction SnsAction (Maybe MessageFormat) (Maybe MessageFormat)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnsAction' {Maybe MessageFormat
messageFormat :: Maybe MessageFormat
$sel:messageFormat:SnsAction' :: SnsAction -> Maybe MessageFormat
messageFormat} -> Maybe MessageFormat
messageFormat) (\s :: SnsAction
s@SnsAction' {} Maybe MessageFormat
a -> SnsAction
s {$sel:messageFormat:SnsAction' :: Maybe MessageFormat
messageFormat = Maybe MessageFormat
a} :: SnsAction)

-- | The ARN of the SNS topic.
snsAction_targetArn :: Lens.Lens' SnsAction Prelude.Text
snsAction_targetArn :: (Text -> f Text) -> SnsAction -> f SnsAction
snsAction_targetArn = (SnsAction -> Text)
-> (SnsAction -> Text -> SnsAction)
-> Lens SnsAction SnsAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnsAction' {Text
targetArn :: Text
$sel:targetArn:SnsAction' :: SnsAction -> Text
targetArn} -> Text
targetArn) (\s :: SnsAction
s@SnsAction' {} Text
a -> SnsAction
s {$sel:targetArn:SnsAction' :: Text
targetArn = Text
a} :: SnsAction)

-- | The ARN of the IAM role that grants access.
snsAction_roleArn :: Lens.Lens' SnsAction Prelude.Text
snsAction_roleArn :: (Text -> f Text) -> SnsAction -> f SnsAction
snsAction_roleArn = (SnsAction -> Text)
-> (SnsAction -> Text -> SnsAction)
-> Lens SnsAction SnsAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SnsAction' {Text
roleArn :: Text
$sel:roleArn:SnsAction' :: SnsAction -> Text
roleArn} -> Text
roleArn) (\s :: SnsAction
s@SnsAction' {} Text
a -> SnsAction
s {$sel:roleArn:SnsAction' :: Text
roleArn = Text
a} :: SnsAction)

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

instance Prelude.Hashable SnsAction

instance Prelude.NFData SnsAction

instance Core.ToJSON SnsAction where
  toJSON :: SnsAction -> Value
toJSON SnsAction' {Maybe MessageFormat
Text
roleArn :: Text
targetArn :: Text
messageFormat :: Maybe MessageFormat
$sel:roleArn:SnsAction' :: SnsAction -> Text
$sel:targetArn:SnsAction' :: SnsAction -> Text
$sel:messageFormat:SnsAction' :: SnsAction -> Maybe MessageFormat
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"messageFormat" Text -> MessageFormat -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (MessageFormat -> Pair) -> Maybe MessageFormat -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MessageFormat
messageFormat,
            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),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )