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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.MessageFormat
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
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]
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
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. 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'
    { $sel:messageFormat:SnsAction' :: Maybe MessageFormat
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 :: Lens' SnsAction (Maybe MessageFormat)
snsAction_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 :: Lens' SnsAction Text
snsAction_targetArn = 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 :: Lens' SnsAction Text
snsAction_roleArn = 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 Data.FromJSON SnsAction where
  parseJSON :: Value -> Parser SnsAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SnsAction"
      ( \Object
x ->
          Maybe MessageFormat -> Text -> Text -> SnsAction
SnsAction'
            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
"messageFormat")
            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
"targetArn")
            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
"roleArn")
      )

instance Prelude.Hashable SnsAction where
  hashWithSalt :: Int -> SnsAction -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MessageFormat
messageFormat
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn

instance Prelude.NFData SnsAction where
  rnf :: SnsAction -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe MessageFormat
messageFormat
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"messageFormat" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MessageFormat
messageFormat,
            forall a. a -> Maybe a
Prelude.Just (Key
"targetArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
targetArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"roleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn)
          ]
      )