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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to publish data to an Amazon SQS queue.
--
-- /See:/ 'newSqsAction' smart constructor.
data SqsAction = SqsAction'
  { -- | Specifies whether to use Base64 encoding.
    SqsAction -> Maybe Bool
useBase64 :: Prelude.Maybe Prelude.Bool,
    -- | The ARN of the IAM role that grants access.
    SqsAction -> Text
roleArn :: Prelude.Text,
    -- | The URL of the Amazon SQS queue.
    SqsAction -> Text
queueUrl :: Prelude.Text
  }
  deriving (SqsAction -> SqsAction -> Bool
(SqsAction -> SqsAction -> Bool)
-> (SqsAction -> SqsAction -> Bool) -> Eq SqsAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqsAction -> SqsAction -> Bool
$c/= :: SqsAction -> SqsAction -> Bool
== :: SqsAction -> SqsAction -> Bool
$c== :: SqsAction -> SqsAction -> Bool
Prelude.Eq, ReadPrec [SqsAction]
ReadPrec SqsAction
Int -> ReadS SqsAction
ReadS [SqsAction]
(Int -> ReadS SqsAction)
-> ReadS [SqsAction]
-> ReadPrec SqsAction
-> ReadPrec [SqsAction]
-> Read SqsAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SqsAction]
$creadListPrec :: ReadPrec [SqsAction]
readPrec :: ReadPrec SqsAction
$creadPrec :: ReadPrec SqsAction
readList :: ReadS [SqsAction]
$creadList :: ReadS [SqsAction]
readsPrec :: Int -> ReadS SqsAction
$creadsPrec :: Int -> ReadS SqsAction
Prelude.Read, Int -> SqsAction -> ShowS
[SqsAction] -> ShowS
SqsAction -> String
(Int -> SqsAction -> ShowS)
-> (SqsAction -> String)
-> ([SqsAction] -> ShowS)
-> Show SqsAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqsAction] -> ShowS
$cshowList :: [SqsAction] -> ShowS
show :: SqsAction -> String
$cshow :: SqsAction -> String
showsPrec :: Int -> SqsAction -> ShowS
$cshowsPrec :: Int -> SqsAction -> ShowS
Prelude.Show, (forall x. SqsAction -> Rep SqsAction x)
-> (forall x. Rep SqsAction x -> SqsAction) -> Generic SqsAction
forall x. Rep SqsAction x -> SqsAction
forall x. SqsAction -> Rep SqsAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SqsAction x -> SqsAction
$cfrom :: forall x. SqsAction -> Rep SqsAction x
Prelude.Generic)

-- |
-- Create a value of 'SqsAction' 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:
--
-- 'useBase64', 'sqsAction_useBase64' - Specifies whether to use Base64 encoding.
--
-- 'roleArn', 'sqsAction_roleArn' - The ARN of the IAM role that grants access.
--
-- 'queueUrl', 'sqsAction_queueUrl' - The URL of the Amazon SQS queue.
newSqsAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'queueUrl'
  Prelude.Text ->
  SqsAction
newSqsAction :: Text -> Text -> SqsAction
newSqsAction Text
pRoleArn_ Text
pQueueUrl_ =
  SqsAction' :: Maybe Bool -> Text -> Text -> SqsAction
SqsAction'
    { $sel:useBase64:SqsAction' :: Maybe Bool
useBase64 = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:SqsAction' :: Text
roleArn = Text
pRoleArn_,
      $sel:queueUrl:SqsAction' :: Text
queueUrl = Text
pQueueUrl_
    }

-- | Specifies whether to use Base64 encoding.
sqsAction_useBase64 :: Lens.Lens' SqsAction (Prelude.Maybe Prelude.Bool)
sqsAction_useBase64 :: (Maybe Bool -> f (Maybe Bool)) -> SqsAction -> f SqsAction
sqsAction_useBase64 = (SqsAction -> Maybe Bool)
-> (SqsAction -> Maybe Bool -> SqsAction)
-> Lens SqsAction SqsAction (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SqsAction' {Maybe Bool
useBase64 :: Maybe Bool
$sel:useBase64:SqsAction' :: SqsAction -> Maybe Bool
useBase64} -> Maybe Bool
useBase64) (\s :: SqsAction
s@SqsAction' {} Maybe Bool
a -> SqsAction
s {$sel:useBase64:SqsAction' :: Maybe Bool
useBase64 = Maybe Bool
a} :: SqsAction)

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

-- | The URL of the Amazon SQS queue.
sqsAction_queueUrl :: Lens.Lens' SqsAction Prelude.Text
sqsAction_queueUrl :: (Text -> f Text) -> SqsAction -> f SqsAction
sqsAction_queueUrl = (SqsAction -> Text)
-> (SqsAction -> Text -> SqsAction)
-> Lens SqsAction SqsAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SqsAction' {Text
queueUrl :: Text
$sel:queueUrl:SqsAction' :: SqsAction -> Text
queueUrl} -> Text
queueUrl) (\s :: SqsAction
s@SqsAction' {} Text
a -> SqsAction
s {$sel:queueUrl:SqsAction' :: Text
queueUrl = Text
a} :: SqsAction)

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

instance Prelude.Hashable SqsAction

instance Prelude.NFData SqsAction

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