{-# 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.AppFlow.Types.ErrorHandlingConfig
-- 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.AppFlow.Types.ErrorHandlingConfig 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 settings that determine how Amazon AppFlow handles an error when
-- placing data in the destination. For example, this setting would
-- determine if the flow should fail after one insertion error, or continue
-- and attempt to insert every record regardless of the initial failure.
-- @ErrorHandlingConfig@ is a part of the destination connector details.
--
-- /See:/ 'newErrorHandlingConfig' smart constructor.
data ErrorHandlingConfig = ErrorHandlingConfig'
  { -- | Specifies the name of the Amazon S3 bucket.
    ErrorHandlingConfig -> Maybe Text
bucketName :: Prelude.Maybe Prelude.Text,
    -- | Specifies the Amazon S3 bucket prefix.
    ErrorHandlingConfig -> Maybe Text
bucketPrefix :: Prelude.Maybe Prelude.Text,
    -- | Specifies if the flow should fail after the first instance of a failure
    -- when attempting to place data in the destination.
    ErrorHandlingConfig -> Maybe Bool
failOnFirstDestinationError :: Prelude.Maybe Prelude.Bool
  }
  deriving (ErrorHandlingConfig -> ErrorHandlingConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorHandlingConfig -> ErrorHandlingConfig -> Bool
$c/= :: ErrorHandlingConfig -> ErrorHandlingConfig -> Bool
== :: ErrorHandlingConfig -> ErrorHandlingConfig -> Bool
$c== :: ErrorHandlingConfig -> ErrorHandlingConfig -> Bool
Prelude.Eq, ReadPrec [ErrorHandlingConfig]
ReadPrec ErrorHandlingConfig
Int -> ReadS ErrorHandlingConfig
ReadS [ErrorHandlingConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ErrorHandlingConfig]
$creadListPrec :: ReadPrec [ErrorHandlingConfig]
readPrec :: ReadPrec ErrorHandlingConfig
$creadPrec :: ReadPrec ErrorHandlingConfig
readList :: ReadS [ErrorHandlingConfig]
$creadList :: ReadS [ErrorHandlingConfig]
readsPrec :: Int -> ReadS ErrorHandlingConfig
$creadsPrec :: Int -> ReadS ErrorHandlingConfig
Prelude.Read, Int -> ErrorHandlingConfig -> ShowS
[ErrorHandlingConfig] -> ShowS
ErrorHandlingConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorHandlingConfig] -> ShowS
$cshowList :: [ErrorHandlingConfig] -> ShowS
show :: ErrorHandlingConfig -> String
$cshow :: ErrorHandlingConfig -> String
showsPrec :: Int -> ErrorHandlingConfig -> ShowS
$cshowsPrec :: Int -> ErrorHandlingConfig -> ShowS
Prelude.Show, forall x. Rep ErrorHandlingConfig x -> ErrorHandlingConfig
forall x. ErrorHandlingConfig -> Rep ErrorHandlingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ErrorHandlingConfig x -> ErrorHandlingConfig
$cfrom :: forall x. ErrorHandlingConfig -> Rep ErrorHandlingConfig x
Prelude.Generic)

-- |
-- Create a value of 'ErrorHandlingConfig' 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:
--
-- 'bucketName', 'errorHandlingConfig_bucketName' - Specifies the name of the Amazon S3 bucket.
--
-- 'bucketPrefix', 'errorHandlingConfig_bucketPrefix' - Specifies the Amazon S3 bucket prefix.
--
-- 'failOnFirstDestinationError', 'errorHandlingConfig_failOnFirstDestinationError' - Specifies if the flow should fail after the first instance of a failure
-- when attempting to place data in the destination.
newErrorHandlingConfig ::
  ErrorHandlingConfig
newErrorHandlingConfig :: ErrorHandlingConfig
newErrorHandlingConfig =
  ErrorHandlingConfig'
    { $sel:bucketName:ErrorHandlingConfig' :: Maybe Text
bucketName = forall a. Maybe a
Prelude.Nothing,
      $sel:bucketPrefix:ErrorHandlingConfig' :: Maybe Text
bucketPrefix = forall a. Maybe a
Prelude.Nothing,
      $sel:failOnFirstDestinationError:ErrorHandlingConfig' :: Maybe Bool
failOnFirstDestinationError = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the name of the Amazon S3 bucket.
errorHandlingConfig_bucketName :: Lens.Lens' ErrorHandlingConfig (Prelude.Maybe Prelude.Text)
errorHandlingConfig_bucketName :: Lens' ErrorHandlingConfig (Maybe Text)
errorHandlingConfig_bucketName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorHandlingConfig' {Maybe Text
bucketName :: Maybe Text
$sel:bucketName:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Text
bucketName} -> Maybe Text
bucketName) (\s :: ErrorHandlingConfig
s@ErrorHandlingConfig' {} Maybe Text
a -> ErrorHandlingConfig
s {$sel:bucketName:ErrorHandlingConfig' :: Maybe Text
bucketName = Maybe Text
a} :: ErrorHandlingConfig)

-- | Specifies the Amazon S3 bucket prefix.
errorHandlingConfig_bucketPrefix :: Lens.Lens' ErrorHandlingConfig (Prelude.Maybe Prelude.Text)
errorHandlingConfig_bucketPrefix :: Lens' ErrorHandlingConfig (Maybe Text)
errorHandlingConfig_bucketPrefix = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorHandlingConfig' {Maybe Text
bucketPrefix :: Maybe Text
$sel:bucketPrefix:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Text
bucketPrefix} -> Maybe Text
bucketPrefix) (\s :: ErrorHandlingConfig
s@ErrorHandlingConfig' {} Maybe Text
a -> ErrorHandlingConfig
s {$sel:bucketPrefix:ErrorHandlingConfig' :: Maybe Text
bucketPrefix = Maybe Text
a} :: ErrorHandlingConfig)

-- | Specifies if the flow should fail after the first instance of a failure
-- when attempting to place data in the destination.
errorHandlingConfig_failOnFirstDestinationError :: Lens.Lens' ErrorHandlingConfig (Prelude.Maybe Prelude.Bool)
errorHandlingConfig_failOnFirstDestinationError :: Lens' ErrorHandlingConfig (Maybe Bool)
errorHandlingConfig_failOnFirstDestinationError = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorHandlingConfig' {Maybe Bool
failOnFirstDestinationError :: Maybe Bool
$sel:failOnFirstDestinationError:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Bool
failOnFirstDestinationError} -> Maybe Bool
failOnFirstDestinationError) (\s :: ErrorHandlingConfig
s@ErrorHandlingConfig' {} Maybe Bool
a -> ErrorHandlingConfig
s {$sel:failOnFirstDestinationError:ErrorHandlingConfig' :: Maybe Bool
failOnFirstDestinationError = Maybe Bool
a} :: ErrorHandlingConfig)

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

instance Prelude.Hashable ErrorHandlingConfig where
  hashWithSalt :: Int -> ErrorHandlingConfig -> Int
hashWithSalt Int
_salt ErrorHandlingConfig' {Maybe Bool
Maybe Text
failOnFirstDestinationError :: Maybe Bool
bucketPrefix :: Maybe Text
bucketName :: Maybe Text
$sel:failOnFirstDestinationError:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Bool
$sel:bucketPrefix:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Text
$sel:bucketName:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
bucketName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
bucketPrefix
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
failOnFirstDestinationError

instance Prelude.NFData ErrorHandlingConfig where
  rnf :: ErrorHandlingConfig -> ()
rnf ErrorHandlingConfig' {Maybe Bool
Maybe Text
failOnFirstDestinationError :: Maybe Bool
bucketPrefix :: Maybe Text
bucketName :: Maybe Text
$sel:failOnFirstDestinationError:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Bool
$sel:bucketPrefix:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Text
$sel:bucketName:ErrorHandlingConfig' :: ErrorHandlingConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
bucketName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
bucketPrefix
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
failOnFirstDestinationError

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