{-# 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.Firehose.Types.ElasticsearchRetryOptions
-- 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.Firehose.Types.ElasticsearchRetryOptions where

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

-- | Configures retry behavior in case Kinesis Data Firehose is unable to
-- deliver documents to Amazon ES.
--
-- /See:/ 'newElasticsearchRetryOptions' smart constructor.
data ElasticsearchRetryOptions = ElasticsearchRetryOptions'
  { -- | After an initial failure to deliver to Amazon ES, the total amount of
    -- time during which Kinesis Data Firehose retries delivery (including the
    -- first attempt). After this time has elapsed, the failed documents are
    -- written to Amazon S3. Default value is 300 seconds (5 minutes). A value
    -- of 0 (zero) results in no retries.
    ElasticsearchRetryOptions -> Maybe Natural
durationInSeconds :: Prelude.Maybe Prelude.Natural
  }
  deriving (ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool
(ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool)
-> (ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool)
-> Eq ElasticsearchRetryOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool
$c/= :: ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool
== :: ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool
$c== :: ElasticsearchRetryOptions -> ElasticsearchRetryOptions -> Bool
Prelude.Eq, ReadPrec [ElasticsearchRetryOptions]
ReadPrec ElasticsearchRetryOptions
Int -> ReadS ElasticsearchRetryOptions
ReadS [ElasticsearchRetryOptions]
(Int -> ReadS ElasticsearchRetryOptions)
-> ReadS [ElasticsearchRetryOptions]
-> ReadPrec ElasticsearchRetryOptions
-> ReadPrec [ElasticsearchRetryOptions]
-> Read ElasticsearchRetryOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ElasticsearchRetryOptions]
$creadListPrec :: ReadPrec [ElasticsearchRetryOptions]
readPrec :: ReadPrec ElasticsearchRetryOptions
$creadPrec :: ReadPrec ElasticsearchRetryOptions
readList :: ReadS [ElasticsearchRetryOptions]
$creadList :: ReadS [ElasticsearchRetryOptions]
readsPrec :: Int -> ReadS ElasticsearchRetryOptions
$creadsPrec :: Int -> ReadS ElasticsearchRetryOptions
Prelude.Read, Int -> ElasticsearchRetryOptions -> ShowS
[ElasticsearchRetryOptions] -> ShowS
ElasticsearchRetryOptions -> String
(Int -> ElasticsearchRetryOptions -> ShowS)
-> (ElasticsearchRetryOptions -> String)
-> ([ElasticsearchRetryOptions] -> ShowS)
-> Show ElasticsearchRetryOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElasticsearchRetryOptions] -> ShowS
$cshowList :: [ElasticsearchRetryOptions] -> ShowS
show :: ElasticsearchRetryOptions -> String
$cshow :: ElasticsearchRetryOptions -> String
showsPrec :: Int -> ElasticsearchRetryOptions -> ShowS
$cshowsPrec :: Int -> ElasticsearchRetryOptions -> ShowS
Prelude.Show, (forall x.
 ElasticsearchRetryOptions -> Rep ElasticsearchRetryOptions x)
-> (forall x.
    Rep ElasticsearchRetryOptions x -> ElasticsearchRetryOptions)
-> Generic ElasticsearchRetryOptions
forall x.
Rep ElasticsearchRetryOptions x -> ElasticsearchRetryOptions
forall x.
ElasticsearchRetryOptions -> Rep ElasticsearchRetryOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ElasticsearchRetryOptions x -> ElasticsearchRetryOptions
$cfrom :: forall x.
ElasticsearchRetryOptions -> Rep ElasticsearchRetryOptions x
Prelude.Generic)

-- |
-- Create a value of 'ElasticsearchRetryOptions' 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:
--
-- 'durationInSeconds', 'elasticsearchRetryOptions_durationInSeconds' - After an initial failure to deliver to Amazon ES, the total amount of
-- time during which Kinesis Data Firehose retries delivery (including the
-- first attempt). After this time has elapsed, the failed documents are
-- written to Amazon S3. Default value is 300 seconds (5 minutes). A value
-- of 0 (zero) results in no retries.
newElasticsearchRetryOptions ::
  ElasticsearchRetryOptions
newElasticsearchRetryOptions :: ElasticsearchRetryOptions
newElasticsearchRetryOptions =
  ElasticsearchRetryOptions' :: Maybe Natural -> ElasticsearchRetryOptions
ElasticsearchRetryOptions'
    { $sel:durationInSeconds:ElasticsearchRetryOptions' :: Maybe Natural
durationInSeconds =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | After an initial failure to deliver to Amazon ES, the total amount of
-- time during which Kinesis Data Firehose retries delivery (including the
-- first attempt). After this time has elapsed, the failed documents are
-- written to Amazon S3. Default value is 300 seconds (5 minutes). A value
-- of 0 (zero) results in no retries.
elasticsearchRetryOptions_durationInSeconds :: Lens.Lens' ElasticsearchRetryOptions (Prelude.Maybe Prelude.Natural)
elasticsearchRetryOptions_durationInSeconds :: (Maybe Natural -> f (Maybe Natural))
-> ElasticsearchRetryOptions -> f ElasticsearchRetryOptions
elasticsearchRetryOptions_durationInSeconds = (ElasticsearchRetryOptions -> Maybe Natural)
-> (ElasticsearchRetryOptions
    -> Maybe Natural -> ElasticsearchRetryOptions)
-> Lens
     ElasticsearchRetryOptions
     ElasticsearchRetryOptions
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ElasticsearchRetryOptions' {Maybe Natural
durationInSeconds :: Maybe Natural
$sel:durationInSeconds:ElasticsearchRetryOptions' :: ElasticsearchRetryOptions -> Maybe Natural
durationInSeconds} -> Maybe Natural
durationInSeconds) (\s :: ElasticsearchRetryOptions
s@ElasticsearchRetryOptions' {} Maybe Natural
a -> ElasticsearchRetryOptions
s {$sel:durationInSeconds:ElasticsearchRetryOptions' :: Maybe Natural
durationInSeconds = Maybe Natural
a} :: ElasticsearchRetryOptions)

instance Core.FromJSON ElasticsearchRetryOptions where
  parseJSON :: Value -> Parser ElasticsearchRetryOptions
parseJSON =
    String
-> (Object -> Parser ElasticsearchRetryOptions)
-> Value
-> Parser ElasticsearchRetryOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ElasticsearchRetryOptions"
      ( \Object
x ->
          Maybe Natural -> ElasticsearchRetryOptions
ElasticsearchRetryOptions'
            (Maybe Natural -> ElasticsearchRetryOptions)
-> Parser (Maybe Natural) -> Parser ElasticsearchRetryOptions
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DurationInSeconds")
      )

instance Prelude.Hashable ElasticsearchRetryOptions

instance Prelude.NFData ElasticsearchRetryOptions

instance Core.ToJSON ElasticsearchRetryOptions where
  toJSON :: ElasticsearchRetryOptions -> Value
toJSON ElasticsearchRetryOptions' {Maybe Natural
durationInSeconds :: Maybe Natural
$sel:durationInSeconds:ElasticsearchRetryOptions' :: ElasticsearchRetryOptions -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DurationInSeconds" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
durationInSeconds
          ]
      )