{-# 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.Lambda.Types.DeadLetterConfig
-- 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.Lambda.Types.DeadLetterConfig where

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

-- | The
-- <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#dlq dead-letter queue>
-- for failed asynchronous invocations.
--
-- /See:/ 'newDeadLetterConfig' smart constructor.
data DeadLetterConfig = DeadLetterConfig'
  { -- | The Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS
    -- topic.
    DeadLetterConfig -> Maybe Text
targetArn :: Prelude.Maybe Prelude.Text
  }
  deriving (DeadLetterConfig -> DeadLetterConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeadLetterConfig -> DeadLetterConfig -> Bool
$c/= :: DeadLetterConfig -> DeadLetterConfig -> Bool
== :: DeadLetterConfig -> DeadLetterConfig -> Bool
$c== :: DeadLetterConfig -> DeadLetterConfig -> Bool
Prelude.Eq, ReadPrec [DeadLetterConfig]
ReadPrec DeadLetterConfig
Int -> ReadS DeadLetterConfig
ReadS [DeadLetterConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeadLetterConfig]
$creadListPrec :: ReadPrec [DeadLetterConfig]
readPrec :: ReadPrec DeadLetterConfig
$creadPrec :: ReadPrec DeadLetterConfig
readList :: ReadS [DeadLetterConfig]
$creadList :: ReadS [DeadLetterConfig]
readsPrec :: Int -> ReadS DeadLetterConfig
$creadsPrec :: Int -> ReadS DeadLetterConfig
Prelude.Read, Int -> DeadLetterConfig -> ShowS
[DeadLetterConfig] -> ShowS
DeadLetterConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeadLetterConfig] -> ShowS
$cshowList :: [DeadLetterConfig] -> ShowS
show :: DeadLetterConfig -> String
$cshow :: DeadLetterConfig -> String
showsPrec :: Int -> DeadLetterConfig -> ShowS
$cshowsPrec :: Int -> DeadLetterConfig -> ShowS
Prelude.Show, forall x. Rep DeadLetterConfig x -> DeadLetterConfig
forall x. DeadLetterConfig -> Rep DeadLetterConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeadLetterConfig x -> DeadLetterConfig
$cfrom :: forall x. DeadLetterConfig -> Rep DeadLetterConfig x
Prelude.Generic)

-- |
-- Create a value of 'DeadLetterConfig' 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:
--
-- 'targetArn', 'deadLetterConfig_targetArn' - The Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS
-- topic.
newDeadLetterConfig ::
  DeadLetterConfig
newDeadLetterConfig :: DeadLetterConfig
newDeadLetterConfig =
  DeadLetterConfig' {$sel:targetArn:DeadLetterConfig' :: Maybe Text
targetArn = forall a. Maybe a
Prelude.Nothing}

-- | The Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS
-- topic.
deadLetterConfig_targetArn :: Lens.Lens' DeadLetterConfig (Prelude.Maybe Prelude.Text)
deadLetterConfig_targetArn :: Lens' DeadLetterConfig (Maybe Text)
deadLetterConfig_targetArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeadLetterConfig' {Maybe Text
targetArn :: Maybe Text
$sel:targetArn:DeadLetterConfig' :: DeadLetterConfig -> Maybe Text
targetArn} -> Maybe Text
targetArn) (\s :: DeadLetterConfig
s@DeadLetterConfig' {} Maybe Text
a -> DeadLetterConfig
s {$sel:targetArn:DeadLetterConfig' :: Maybe Text
targetArn = Maybe Text
a} :: DeadLetterConfig)

instance Data.FromJSON DeadLetterConfig where
  parseJSON :: Value -> Parser DeadLetterConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeadLetterConfig"
      ( \Object
x ->
          Maybe Text -> DeadLetterConfig
DeadLetterConfig'
            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
"TargetArn")
      )

instance Prelude.Hashable DeadLetterConfig where
  hashWithSalt :: Int -> DeadLetterConfig -> Int
hashWithSalt Int
_salt DeadLetterConfig' {Maybe Text
targetArn :: Maybe Text
$sel:targetArn:DeadLetterConfig' :: DeadLetterConfig -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
targetArn

instance Prelude.NFData DeadLetterConfig where
  rnf :: DeadLetterConfig -> ()
rnf DeadLetterConfig' {Maybe Text
targetArn :: Maybe Text
$sel:targetArn:DeadLetterConfig' :: DeadLetterConfig -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
targetArn

instance Data.ToJSON DeadLetterConfig where
  toJSON :: DeadLetterConfig -> Value
toJSON DeadLetterConfig' {Maybe Text
targetArn :: Maybe Text
$sel:targetArn:DeadLetterConfig' :: DeadLetterConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"TargetArn" 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 Text
targetArn]
      )