{-# 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.AppMesh.Types.GrpcRetryPolicy
-- 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.AppMesh.Types.GrpcRetryPolicy where

import Amazonka.AppMesh.Types.Duration
import Amazonka.AppMesh.Types.GrpcRetryPolicyEvent
import Amazonka.AppMesh.Types.TcpRetryPolicyEvent
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents a retry policy. Specify at least one value for
-- at least one of the types of @RetryEvents@, a value for @maxRetries@,
-- and a value for @perRetryTimeout@. Both @server-error@ and
-- @gateway-error@ under @httpRetryEvents@ include the Envoy @reset@
-- policy. For more information on the @reset@ policy, see the
-- <https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on Envoy documentation>.
--
-- /See:/ 'newGrpcRetryPolicy' smart constructor.
data GrpcRetryPolicy = GrpcRetryPolicy'
  { -- | Specify at least one of the following values.
    --
    -- -   __server-error__ – HTTP status codes 500, 501, 502, 503, 504, 505,
    --     506, 507, 508, 510, and 511
    --
    -- -   __gateway-error__ – HTTP status codes 502, 503, and 504
    --
    -- -   __client-error__ – HTTP status code 409
    --
    -- -   __stream-error__ – Retry on refused stream
    GrpcRetryPolicy -> Maybe (NonEmpty Text)
httpRetryEvents :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | Specify at least one of the valid values.
    GrpcRetryPolicy -> Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents :: Prelude.Maybe (Prelude.NonEmpty GrpcRetryPolicyEvent),
    -- | Specify a valid value. The event occurs before any processing of a
    -- request has started and is encountered when the upstream is temporarily
    -- or permanently unavailable.
    GrpcRetryPolicy -> Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents :: Prelude.Maybe (Prelude.NonEmpty TcpRetryPolicyEvent),
    -- | The maximum number of retry attempts.
    GrpcRetryPolicy -> Natural
maxRetries :: Prelude.Natural,
    -- | The timeout for each retry attempt.
    GrpcRetryPolicy -> Duration
perRetryTimeout :: Duration
  }
  deriving (GrpcRetryPolicy -> GrpcRetryPolicy -> Bool
(GrpcRetryPolicy -> GrpcRetryPolicy -> Bool)
-> (GrpcRetryPolicy -> GrpcRetryPolicy -> Bool)
-> Eq GrpcRetryPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrpcRetryPolicy -> GrpcRetryPolicy -> Bool
$c/= :: GrpcRetryPolicy -> GrpcRetryPolicy -> Bool
== :: GrpcRetryPolicy -> GrpcRetryPolicy -> Bool
$c== :: GrpcRetryPolicy -> GrpcRetryPolicy -> Bool
Prelude.Eq, ReadPrec [GrpcRetryPolicy]
ReadPrec GrpcRetryPolicy
Int -> ReadS GrpcRetryPolicy
ReadS [GrpcRetryPolicy]
(Int -> ReadS GrpcRetryPolicy)
-> ReadS [GrpcRetryPolicy]
-> ReadPrec GrpcRetryPolicy
-> ReadPrec [GrpcRetryPolicy]
-> Read GrpcRetryPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrpcRetryPolicy]
$creadListPrec :: ReadPrec [GrpcRetryPolicy]
readPrec :: ReadPrec GrpcRetryPolicy
$creadPrec :: ReadPrec GrpcRetryPolicy
readList :: ReadS [GrpcRetryPolicy]
$creadList :: ReadS [GrpcRetryPolicy]
readsPrec :: Int -> ReadS GrpcRetryPolicy
$creadsPrec :: Int -> ReadS GrpcRetryPolicy
Prelude.Read, Int -> GrpcRetryPolicy -> ShowS
[GrpcRetryPolicy] -> ShowS
GrpcRetryPolicy -> String
(Int -> GrpcRetryPolicy -> ShowS)
-> (GrpcRetryPolicy -> String)
-> ([GrpcRetryPolicy] -> ShowS)
-> Show GrpcRetryPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrpcRetryPolicy] -> ShowS
$cshowList :: [GrpcRetryPolicy] -> ShowS
show :: GrpcRetryPolicy -> String
$cshow :: GrpcRetryPolicy -> String
showsPrec :: Int -> GrpcRetryPolicy -> ShowS
$cshowsPrec :: Int -> GrpcRetryPolicy -> ShowS
Prelude.Show, (forall x. GrpcRetryPolicy -> Rep GrpcRetryPolicy x)
-> (forall x. Rep GrpcRetryPolicy x -> GrpcRetryPolicy)
-> Generic GrpcRetryPolicy
forall x. Rep GrpcRetryPolicy x -> GrpcRetryPolicy
forall x. GrpcRetryPolicy -> Rep GrpcRetryPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrpcRetryPolicy x -> GrpcRetryPolicy
$cfrom :: forall x. GrpcRetryPolicy -> Rep GrpcRetryPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GrpcRetryPolicy' 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:
--
-- 'httpRetryEvents', 'grpcRetryPolicy_httpRetryEvents' - Specify at least one of the following values.
--
-- -   __server-error__ – HTTP status codes 500, 501, 502, 503, 504, 505,
--     506, 507, 508, 510, and 511
--
-- -   __gateway-error__ – HTTP status codes 502, 503, and 504
--
-- -   __client-error__ – HTTP status code 409
--
-- -   __stream-error__ – Retry on refused stream
--
-- 'grpcRetryEvents', 'grpcRetryPolicy_grpcRetryEvents' - Specify at least one of the valid values.
--
-- 'tcpRetryEvents', 'grpcRetryPolicy_tcpRetryEvents' - Specify a valid value. The event occurs before any processing of a
-- request has started and is encountered when the upstream is temporarily
-- or permanently unavailable.
--
-- 'maxRetries', 'grpcRetryPolicy_maxRetries' - The maximum number of retry attempts.
--
-- 'perRetryTimeout', 'grpcRetryPolicy_perRetryTimeout' - The timeout for each retry attempt.
newGrpcRetryPolicy ::
  -- | 'maxRetries'
  Prelude.Natural ->
  -- | 'perRetryTimeout'
  Duration ->
  GrpcRetryPolicy
newGrpcRetryPolicy :: Natural -> Duration -> GrpcRetryPolicy
newGrpcRetryPolicy Natural
pMaxRetries_ Duration
pPerRetryTimeout_ =
  GrpcRetryPolicy' :: Maybe (NonEmpty Text)
-> Maybe (NonEmpty GrpcRetryPolicyEvent)
-> Maybe (NonEmpty TcpRetryPolicyEvent)
-> Natural
-> Duration
-> GrpcRetryPolicy
GrpcRetryPolicy'
    { $sel:httpRetryEvents:GrpcRetryPolicy' :: Maybe (NonEmpty Text)
httpRetryEvents = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:grpcRetryEvents:GrpcRetryPolicy' :: Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents = Maybe (NonEmpty GrpcRetryPolicyEvent)
forall a. Maybe a
Prelude.Nothing,
      $sel:tcpRetryEvents:GrpcRetryPolicy' :: Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents = Maybe (NonEmpty TcpRetryPolicyEvent)
forall a. Maybe a
Prelude.Nothing,
      $sel:maxRetries:GrpcRetryPolicy' :: Natural
maxRetries = Natural
pMaxRetries_,
      $sel:perRetryTimeout:GrpcRetryPolicy' :: Duration
perRetryTimeout = Duration
pPerRetryTimeout_
    }

-- | Specify at least one of the following values.
--
-- -   __server-error__ – HTTP status codes 500, 501, 502, 503, 504, 505,
--     506, 507, 508, 510, and 511
--
-- -   __gateway-error__ – HTTP status codes 502, 503, and 504
--
-- -   __client-error__ – HTTP status code 409
--
-- -   __stream-error__ – Retry on refused stream
grpcRetryPolicy_httpRetryEvents :: Lens.Lens' GrpcRetryPolicy (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
grpcRetryPolicy_httpRetryEvents :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> GrpcRetryPolicy -> f GrpcRetryPolicy
grpcRetryPolicy_httpRetryEvents = (GrpcRetryPolicy -> Maybe (NonEmpty Text))
-> (GrpcRetryPolicy -> Maybe (NonEmpty Text) -> GrpcRetryPolicy)
-> Lens
     GrpcRetryPolicy
     GrpcRetryPolicy
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRetryPolicy' {Maybe (NonEmpty Text)
httpRetryEvents :: Maybe (NonEmpty Text)
$sel:httpRetryEvents:GrpcRetryPolicy' :: GrpcRetryPolicy -> Maybe (NonEmpty Text)
httpRetryEvents} -> Maybe (NonEmpty Text)
httpRetryEvents) (\s :: GrpcRetryPolicy
s@GrpcRetryPolicy' {} Maybe (NonEmpty Text)
a -> GrpcRetryPolicy
s {$sel:httpRetryEvents:GrpcRetryPolicy' :: Maybe (NonEmpty Text)
httpRetryEvents = Maybe (NonEmpty Text)
a} :: GrpcRetryPolicy) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> GrpcRetryPolicy -> f GrpcRetryPolicy)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> GrpcRetryPolicy
-> f GrpcRetryPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specify at least one of the valid values.
grpcRetryPolicy_grpcRetryEvents :: Lens.Lens' GrpcRetryPolicy (Prelude.Maybe (Prelude.NonEmpty GrpcRetryPolicyEvent))
grpcRetryPolicy_grpcRetryEvents :: (Maybe (NonEmpty GrpcRetryPolicyEvent)
 -> f (Maybe (NonEmpty GrpcRetryPolicyEvent)))
-> GrpcRetryPolicy -> f GrpcRetryPolicy
grpcRetryPolicy_grpcRetryEvents = (GrpcRetryPolicy -> Maybe (NonEmpty GrpcRetryPolicyEvent))
-> (GrpcRetryPolicy
    -> Maybe (NonEmpty GrpcRetryPolicyEvent) -> GrpcRetryPolicy)
-> Lens
     GrpcRetryPolicy
     GrpcRetryPolicy
     (Maybe (NonEmpty GrpcRetryPolicyEvent))
     (Maybe (NonEmpty GrpcRetryPolicyEvent))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRetryPolicy' {Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents :: Maybe (NonEmpty GrpcRetryPolicyEvent)
$sel:grpcRetryEvents:GrpcRetryPolicy' :: GrpcRetryPolicy -> Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents} -> Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents) (\s :: GrpcRetryPolicy
s@GrpcRetryPolicy' {} Maybe (NonEmpty GrpcRetryPolicyEvent)
a -> GrpcRetryPolicy
s {$sel:grpcRetryEvents:GrpcRetryPolicy' :: Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents = Maybe (NonEmpty GrpcRetryPolicyEvent)
a} :: GrpcRetryPolicy) ((Maybe (NonEmpty GrpcRetryPolicyEvent)
  -> f (Maybe (NonEmpty GrpcRetryPolicyEvent)))
 -> GrpcRetryPolicy -> f GrpcRetryPolicy)
-> ((Maybe (NonEmpty GrpcRetryPolicyEvent)
     -> f (Maybe (NonEmpty GrpcRetryPolicyEvent)))
    -> Maybe (NonEmpty GrpcRetryPolicyEvent)
    -> f (Maybe (NonEmpty GrpcRetryPolicyEvent)))
-> (Maybe (NonEmpty GrpcRetryPolicyEvent)
    -> f (Maybe (NonEmpty GrpcRetryPolicyEvent)))
-> GrpcRetryPolicy
-> f GrpcRetryPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty GrpcRetryPolicyEvent)
  (NonEmpty GrpcRetryPolicyEvent)
  (NonEmpty GrpcRetryPolicyEvent)
  (NonEmpty GrpcRetryPolicyEvent)
-> Iso
     (Maybe (NonEmpty GrpcRetryPolicyEvent))
     (Maybe (NonEmpty GrpcRetryPolicyEvent))
     (Maybe (NonEmpty GrpcRetryPolicyEvent))
     (Maybe (NonEmpty GrpcRetryPolicyEvent))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty GrpcRetryPolicyEvent)
  (NonEmpty GrpcRetryPolicyEvent)
  (NonEmpty GrpcRetryPolicyEvent)
  (NonEmpty GrpcRetryPolicyEvent)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specify a valid value. The event occurs before any processing of a
-- request has started and is encountered when the upstream is temporarily
-- or permanently unavailable.
grpcRetryPolicy_tcpRetryEvents :: Lens.Lens' GrpcRetryPolicy (Prelude.Maybe (Prelude.NonEmpty TcpRetryPolicyEvent))
grpcRetryPolicy_tcpRetryEvents :: (Maybe (NonEmpty TcpRetryPolicyEvent)
 -> f (Maybe (NonEmpty TcpRetryPolicyEvent)))
-> GrpcRetryPolicy -> f GrpcRetryPolicy
grpcRetryPolicy_tcpRetryEvents = (GrpcRetryPolicy -> Maybe (NonEmpty TcpRetryPolicyEvent))
-> (GrpcRetryPolicy
    -> Maybe (NonEmpty TcpRetryPolicyEvent) -> GrpcRetryPolicy)
-> Lens
     GrpcRetryPolicy
     GrpcRetryPolicy
     (Maybe (NonEmpty TcpRetryPolicyEvent))
     (Maybe (NonEmpty TcpRetryPolicyEvent))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRetryPolicy' {Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents :: Maybe (NonEmpty TcpRetryPolicyEvent)
$sel:tcpRetryEvents:GrpcRetryPolicy' :: GrpcRetryPolicy -> Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents} -> Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents) (\s :: GrpcRetryPolicy
s@GrpcRetryPolicy' {} Maybe (NonEmpty TcpRetryPolicyEvent)
a -> GrpcRetryPolicy
s {$sel:tcpRetryEvents:GrpcRetryPolicy' :: Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents = Maybe (NonEmpty TcpRetryPolicyEvent)
a} :: GrpcRetryPolicy) ((Maybe (NonEmpty TcpRetryPolicyEvent)
  -> f (Maybe (NonEmpty TcpRetryPolicyEvent)))
 -> GrpcRetryPolicy -> f GrpcRetryPolicy)
-> ((Maybe (NonEmpty TcpRetryPolicyEvent)
     -> f (Maybe (NonEmpty TcpRetryPolicyEvent)))
    -> Maybe (NonEmpty TcpRetryPolicyEvent)
    -> f (Maybe (NonEmpty TcpRetryPolicyEvent)))
-> (Maybe (NonEmpty TcpRetryPolicyEvent)
    -> f (Maybe (NonEmpty TcpRetryPolicyEvent)))
-> GrpcRetryPolicy
-> f GrpcRetryPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty TcpRetryPolicyEvent)
  (NonEmpty TcpRetryPolicyEvent)
  (NonEmpty TcpRetryPolicyEvent)
  (NonEmpty TcpRetryPolicyEvent)
-> Iso
     (Maybe (NonEmpty TcpRetryPolicyEvent))
     (Maybe (NonEmpty TcpRetryPolicyEvent))
     (Maybe (NonEmpty TcpRetryPolicyEvent))
     (Maybe (NonEmpty TcpRetryPolicyEvent))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty TcpRetryPolicyEvent)
  (NonEmpty TcpRetryPolicyEvent)
  (NonEmpty TcpRetryPolicyEvent)
  (NonEmpty TcpRetryPolicyEvent)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The maximum number of retry attempts.
grpcRetryPolicy_maxRetries :: Lens.Lens' GrpcRetryPolicy Prelude.Natural
grpcRetryPolicy_maxRetries :: (Natural -> f Natural) -> GrpcRetryPolicy -> f GrpcRetryPolicy
grpcRetryPolicy_maxRetries = (GrpcRetryPolicy -> Natural)
-> (GrpcRetryPolicy -> Natural -> GrpcRetryPolicy)
-> Lens GrpcRetryPolicy GrpcRetryPolicy Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRetryPolicy' {Natural
maxRetries :: Natural
$sel:maxRetries:GrpcRetryPolicy' :: GrpcRetryPolicy -> Natural
maxRetries} -> Natural
maxRetries) (\s :: GrpcRetryPolicy
s@GrpcRetryPolicy' {} Natural
a -> GrpcRetryPolicy
s {$sel:maxRetries:GrpcRetryPolicy' :: Natural
maxRetries = Natural
a} :: GrpcRetryPolicy)

-- | The timeout for each retry attempt.
grpcRetryPolicy_perRetryTimeout :: Lens.Lens' GrpcRetryPolicy Duration
grpcRetryPolicy_perRetryTimeout :: (Duration -> f Duration) -> GrpcRetryPolicy -> f GrpcRetryPolicy
grpcRetryPolicy_perRetryTimeout = (GrpcRetryPolicy -> Duration)
-> (GrpcRetryPolicy -> Duration -> GrpcRetryPolicy)
-> Lens GrpcRetryPolicy GrpcRetryPolicy Duration Duration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRetryPolicy' {Duration
perRetryTimeout :: Duration
$sel:perRetryTimeout:GrpcRetryPolicy' :: GrpcRetryPolicy -> Duration
perRetryTimeout} -> Duration
perRetryTimeout) (\s :: GrpcRetryPolicy
s@GrpcRetryPolicy' {} Duration
a -> GrpcRetryPolicy
s {$sel:perRetryTimeout:GrpcRetryPolicy' :: Duration
perRetryTimeout = Duration
a} :: GrpcRetryPolicy)

instance Core.FromJSON GrpcRetryPolicy where
  parseJSON :: Value -> Parser GrpcRetryPolicy
parseJSON =
    String
-> (Object -> Parser GrpcRetryPolicy)
-> Value
-> Parser GrpcRetryPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GrpcRetryPolicy"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe (NonEmpty GrpcRetryPolicyEvent)
-> Maybe (NonEmpty TcpRetryPolicyEvent)
-> Natural
-> Duration
-> GrpcRetryPolicy
GrpcRetryPolicy'
            (Maybe (NonEmpty Text)
 -> Maybe (NonEmpty GrpcRetryPolicyEvent)
 -> Maybe (NonEmpty TcpRetryPolicyEvent)
 -> Natural
 -> Duration
 -> GrpcRetryPolicy)
-> Parser (Maybe (NonEmpty Text))
-> Parser
     (Maybe (NonEmpty GrpcRetryPolicyEvent)
      -> Maybe (NonEmpty TcpRetryPolicyEvent)
      -> Natural
      -> Duration
      -> GrpcRetryPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"httpRetryEvents")
            Parser
  (Maybe (NonEmpty GrpcRetryPolicyEvent)
   -> Maybe (NonEmpty TcpRetryPolicyEvent)
   -> Natural
   -> Duration
   -> GrpcRetryPolicy)
-> Parser (Maybe (NonEmpty GrpcRetryPolicyEvent))
-> Parser
     (Maybe (NonEmpty TcpRetryPolicyEvent)
      -> Natural -> Duration -> GrpcRetryPolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty GrpcRetryPolicyEvent))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"grpcRetryEvents")
            Parser
  (Maybe (NonEmpty TcpRetryPolicyEvent)
   -> Natural -> Duration -> GrpcRetryPolicy)
-> Parser (Maybe (NonEmpty TcpRetryPolicyEvent))
-> Parser (Natural -> Duration -> GrpcRetryPolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty TcpRetryPolicyEvent))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"tcpRetryEvents")
            Parser (Natural -> Duration -> GrpcRetryPolicy)
-> Parser Natural -> Parser (Duration -> GrpcRetryPolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"maxRetries")
            Parser (Duration -> GrpcRetryPolicy)
-> Parser Duration -> Parser GrpcRetryPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Duration
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"perRetryTimeout")
      )

instance Prelude.Hashable GrpcRetryPolicy

instance Prelude.NFData GrpcRetryPolicy

instance Core.ToJSON GrpcRetryPolicy where
  toJSON :: GrpcRetryPolicy -> Value
toJSON GrpcRetryPolicy' {Natural
Maybe (NonEmpty Text)
Maybe (NonEmpty GrpcRetryPolicyEvent)
Maybe (NonEmpty TcpRetryPolicyEvent)
Duration
perRetryTimeout :: Duration
maxRetries :: Natural
tcpRetryEvents :: Maybe (NonEmpty TcpRetryPolicyEvent)
grpcRetryEvents :: Maybe (NonEmpty GrpcRetryPolicyEvent)
httpRetryEvents :: Maybe (NonEmpty Text)
$sel:perRetryTimeout:GrpcRetryPolicy' :: GrpcRetryPolicy -> Duration
$sel:maxRetries:GrpcRetryPolicy' :: GrpcRetryPolicy -> Natural
$sel:tcpRetryEvents:GrpcRetryPolicy' :: GrpcRetryPolicy -> Maybe (NonEmpty TcpRetryPolicyEvent)
$sel:grpcRetryEvents:GrpcRetryPolicy' :: GrpcRetryPolicy -> Maybe (NonEmpty GrpcRetryPolicyEvent)
$sel:httpRetryEvents:GrpcRetryPolicy' :: GrpcRetryPolicy -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"httpRetryEvents" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
httpRetryEvents,
            (Text
"grpcRetryEvents" Text -> NonEmpty GrpcRetryPolicyEvent -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty GrpcRetryPolicyEvent -> Pair)
-> Maybe (NonEmpty GrpcRetryPolicyEvent) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty GrpcRetryPolicyEvent)
grpcRetryEvents,
            (Text
"tcpRetryEvents" Text -> NonEmpty TcpRetryPolicyEvent -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty TcpRetryPolicyEvent -> Pair)
-> Maybe (NonEmpty TcpRetryPolicyEvent) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty TcpRetryPolicyEvent)
tcpRetryEvents,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"maxRetries" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
maxRetries),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"perRetryTimeout" Text -> Duration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Duration
perRetryTimeout)
          ]
      )