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

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

-- | Sends information about the detector model instance and the event that
-- triggered the action to an Amazon SQS queue.
--
-- /See:/ 'newSqsAction' smart constructor.
data SqsAction = SqsAction'
  { -- | You can configure the action payload when you send a message to an
    -- Amazon SQS queue.
    SqsAction -> Maybe Payload
payload :: Prelude.Maybe Payload,
    -- | Set this to TRUE if you want the data to be base-64 encoded before it is
    -- written to the queue. Otherwise, set this to FALSE.
    SqsAction -> Maybe Bool
useBase64 :: Prelude.Maybe Prelude.Bool,
    -- | The URL of the SQS queue where the data is written.
    SqsAction -> Text
queueUrl :: Prelude.Text
  }
  deriving (SqsAction -> SqsAction -> Bool
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]
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
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. 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:
--
-- 'payload', 'sqsAction_payload' - You can configure the action payload when you send a message to an
-- Amazon SQS queue.
--
-- 'useBase64', 'sqsAction_useBase64' - Set this to TRUE if you want the data to be base-64 encoded before it is
-- written to the queue. Otherwise, set this to FALSE.
--
-- 'queueUrl', 'sqsAction_queueUrl' - The URL of the SQS queue where the data is written.
newSqsAction ::
  -- | 'queueUrl'
  Prelude.Text ->
  SqsAction
newSqsAction :: Text -> SqsAction
newSqsAction Text
pQueueUrl_ =
  SqsAction'
    { $sel:payload:SqsAction' :: Maybe Payload
payload = forall a. Maybe a
Prelude.Nothing,
      $sel:useBase64:SqsAction' :: Maybe Bool
useBase64 = forall a. Maybe a
Prelude.Nothing,
      $sel:queueUrl:SqsAction' :: Text
queueUrl = Text
pQueueUrl_
    }

-- | You can configure the action payload when you send a message to an
-- Amazon SQS queue.
sqsAction_payload :: Lens.Lens' SqsAction (Prelude.Maybe Payload)
sqsAction_payload :: Lens' SqsAction (Maybe Payload)
sqsAction_payload = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SqsAction' {Maybe Payload
payload :: Maybe Payload
$sel:payload:SqsAction' :: SqsAction -> Maybe Payload
payload} -> Maybe Payload
payload) (\s :: SqsAction
s@SqsAction' {} Maybe Payload
a -> SqsAction
s {$sel:payload:SqsAction' :: Maybe Payload
payload = Maybe Payload
a} :: SqsAction)

-- | Set this to TRUE if you want the data to be base-64 encoded before it is
-- written to the queue. Otherwise, set this to FALSE.
sqsAction_useBase64 :: Lens.Lens' SqsAction (Prelude.Maybe Prelude.Bool)
sqsAction_useBase64 :: Lens' SqsAction (Maybe Bool)
sqsAction_useBase64 = 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 URL of the SQS queue where the data is written.
sqsAction_queueUrl :: Lens.Lens' SqsAction Prelude.Text
sqsAction_queueUrl :: Lens' SqsAction Text
sqsAction_queueUrl = 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 Data.FromJSON SqsAction where
  parseJSON :: Value -> Parser SqsAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SqsAction"
      ( \Object
x ->
          Maybe Payload -> Maybe Bool -> Text -> SqsAction
SqsAction'
            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
"payload")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"useBase64")
            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
"queueUrl")
      )

instance Prelude.Hashable SqsAction where
  hashWithSalt :: Int -> SqsAction -> Int
hashWithSalt Int
_salt SqsAction' {Maybe Bool
Maybe Payload
Text
queueUrl :: Text
useBase64 :: Maybe Bool
payload :: Maybe Payload
$sel:queueUrl:SqsAction' :: SqsAction -> Text
$sel:useBase64:SqsAction' :: SqsAction -> Maybe Bool
$sel:payload:SqsAction' :: SqsAction -> Maybe Payload
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Payload
payload
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
useBase64
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
queueUrl

instance Prelude.NFData SqsAction where
  rnf :: SqsAction -> ()
rnf SqsAction' {Maybe Bool
Maybe Payload
Text
queueUrl :: Text
useBase64 :: Maybe Bool
payload :: Maybe Payload
$sel:queueUrl:SqsAction' :: SqsAction -> Text
$sel:useBase64:SqsAction' :: SqsAction -> Maybe Bool
$sel:payload:SqsAction' :: SqsAction -> Maybe Payload
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Payload
payload
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
useBase64
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
queueUrl

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