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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lambda.Types.OnFailure
import Amazonka.Lambda.Types.OnSuccess
import qualified Amazonka.Prelude as Prelude

-- | A configuration object that specifies the destination of an event after
-- Lambda processes it.
--
-- /See:/ 'newDestinationConfig' smart constructor.
data DestinationConfig = DestinationConfig'
  { -- | The destination configuration for failed invocations.
    DestinationConfig -> Maybe OnFailure
onFailure :: Prelude.Maybe OnFailure,
    -- | The destination configuration for successful invocations.
    DestinationConfig -> Maybe OnSuccess
onSuccess :: Prelude.Maybe OnSuccess
  }
  deriving (DestinationConfig -> DestinationConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DestinationConfig -> DestinationConfig -> Bool
$c/= :: DestinationConfig -> DestinationConfig -> Bool
== :: DestinationConfig -> DestinationConfig -> Bool
$c== :: DestinationConfig -> DestinationConfig -> Bool
Prelude.Eq, ReadPrec [DestinationConfig]
ReadPrec DestinationConfig
Int -> ReadS DestinationConfig
ReadS [DestinationConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DestinationConfig]
$creadListPrec :: ReadPrec [DestinationConfig]
readPrec :: ReadPrec DestinationConfig
$creadPrec :: ReadPrec DestinationConfig
readList :: ReadS [DestinationConfig]
$creadList :: ReadS [DestinationConfig]
readsPrec :: Int -> ReadS DestinationConfig
$creadsPrec :: Int -> ReadS DestinationConfig
Prelude.Read, Int -> DestinationConfig -> ShowS
[DestinationConfig] -> ShowS
DestinationConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DestinationConfig] -> ShowS
$cshowList :: [DestinationConfig] -> ShowS
show :: DestinationConfig -> String
$cshow :: DestinationConfig -> String
showsPrec :: Int -> DestinationConfig -> ShowS
$cshowsPrec :: Int -> DestinationConfig -> ShowS
Prelude.Show, forall x. Rep DestinationConfig x -> DestinationConfig
forall x. DestinationConfig -> Rep DestinationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DestinationConfig x -> DestinationConfig
$cfrom :: forall x. DestinationConfig -> Rep DestinationConfig x
Prelude.Generic)

-- |
-- Create a value of 'DestinationConfig' 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:
--
-- 'onFailure', 'destinationConfig_onFailure' - The destination configuration for failed invocations.
--
-- 'onSuccess', 'destinationConfig_onSuccess' - The destination configuration for successful invocations.
newDestinationConfig ::
  DestinationConfig
newDestinationConfig :: DestinationConfig
newDestinationConfig =
  DestinationConfig'
    { $sel:onFailure:DestinationConfig' :: Maybe OnFailure
onFailure = forall a. Maybe a
Prelude.Nothing,
      $sel:onSuccess:DestinationConfig' :: Maybe OnSuccess
onSuccess = forall a. Maybe a
Prelude.Nothing
    }

-- | The destination configuration for failed invocations.
destinationConfig_onFailure :: Lens.Lens' DestinationConfig (Prelude.Maybe OnFailure)
destinationConfig_onFailure :: Lens' DestinationConfig (Maybe OnFailure)
destinationConfig_onFailure = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DestinationConfig' {Maybe OnFailure
onFailure :: Maybe OnFailure
$sel:onFailure:DestinationConfig' :: DestinationConfig -> Maybe OnFailure
onFailure} -> Maybe OnFailure
onFailure) (\s :: DestinationConfig
s@DestinationConfig' {} Maybe OnFailure
a -> DestinationConfig
s {$sel:onFailure:DestinationConfig' :: Maybe OnFailure
onFailure = Maybe OnFailure
a} :: DestinationConfig)

-- | The destination configuration for successful invocations.
destinationConfig_onSuccess :: Lens.Lens' DestinationConfig (Prelude.Maybe OnSuccess)
destinationConfig_onSuccess :: Lens' DestinationConfig (Maybe OnSuccess)
destinationConfig_onSuccess = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DestinationConfig' {Maybe OnSuccess
onSuccess :: Maybe OnSuccess
$sel:onSuccess:DestinationConfig' :: DestinationConfig -> Maybe OnSuccess
onSuccess} -> Maybe OnSuccess
onSuccess) (\s :: DestinationConfig
s@DestinationConfig' {} Maybe OnSuccess
a -> DestinationConfig
s {$sel:onSuccess:DestinationConfig' :: Maybe OnSuccess
onSuccess = Maybe OnSuccess
a} :: DestinationConfig)

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

instance Prelude.Hashable DestinationConfig where
  hashWithSalt :: Int -> DestinationConfig -> Int
hashWithSalt Int
_salt DestinationConfig' {Maybe OnFailure
Maybe OnSuccess
onSuccess :: Maybe OnSuccess
onFailure :: Maybe OnFailure
$sel:onSuccess:DestinationConfig' :: DestinationConfig -> Maybe OnSuccess
$sel:onFailure:DestinationConfig' :: DestinationConfig -> Maybe OnFailure
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe OnFailure
onFailure
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe OnSuccess
onSuccess

instance Prelude.NFData DestinationConfig where
  rnf :: DestinationConfig -> ()
rnf DestinationConfig' {Maybe OnFailure
Maybe OnSuccess
onSuccess :: Maybe OnSuccess
onFailure :: Maybe OnFailure
$sel:onSuccess:DestinationConfig' :: DestinationConfig -> Maybe OnSuccess
$sel:onFailure:DestinationConfig' :: DestinationConfig -> Maybe OnFailure
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe OnFailure
onFailure
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe OnSuccess
onSuccess

instance Data.ToJSON DestinationConfig where
  toJSON :: DestinationConfig -> Value
toJSON DestinationConfig' {Maybe OnFailure
Maybe OnSuccess
onSuccess :: Maybe OnSuccess
onFailure :: Maybe OnFailure
$sel:onSuccess:DestinationConfig' :: DestinationConfig -> Maybe OnSuccess
$sel:onFailure:DestinationConfig' :: DestinationConfig -> Maybe OnFailure
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"OnFailure" 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 OnFailure
onFailure,
            (Key
"OnSuccess" 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 OnSuccess
onSuccess
          ]
      )