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

import Amazonka.AppMesh.Types.Duration
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

-- | An object that represents types of timeouts.
--
-- /See:/ 'newGrpcTimeout' smart constructor.
data GrpcTimeout = GrpcTimeout'
  { -- | An object that represents an idle timeout. An idle timeout bounds the
    -- amount of time that a connection may be idle. The default value is none.
    GrpcTimeout -> Maybe Duration
idle :: Prelude.Maybe Duration,
    -- | An object that represents a per request timeout. The default value is 15
    -- seconds. If you set a higher timeout, then make sure that the higher
    -- value is set for each App Mesh resource in a conversation. For example,
    -- if a virtual node backend uses a virtual router provider to route to
    -- another virtual node, then the timeout should be greater than 15 seconds
    -- for the source and destination virtual node and the route.
    GrpcTimeout -> Maybe Duration
perRequest :: Prelude.Maybe Duration
  }
  deriving (GrpcTimeout -> GrpcTimeout -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrpcTimeout -> GrpcTimeout -> Bool
$c/= :: GrpcTimeout -> GrpcTimeout -> Bool
== :: GrpcTimeout -> GrpcTimeout -> Bool
$c== :: GrpcTimeout -> GrpcTimeout -> Bool
Prelude.Eq, ReadPrec [GrpcTimeout]
ReadPrec GrpcTimeout
Int -> ReadS GrpcTimeout
ReadS [GrpcTimeout]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrpcTimeout]
$creadListPrec :: ReadPrec [GrpcTimeout]
readPrec :: ReadPrec GrpcTimeout
$creadPrec :: ReadPrec GrpcTimeout
readList :: ReadS [GrpcTimeout]
$creadList :: ReadS [GrpcTimeout]
readsPrec :: Int -> ReadS GrpcTimeout
$creadsPrec :: Int -> ReadS GrpcTimeout
Prelude.Read, Int -> GrpcTimeout -> ShowS
[GrpcTimeout] -> ShowS
GrpcTimeout -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrpcTimeout] -> ShowS
$cshowList :: [GrpcTimeout] -> ShowS
show :: GrpcTimeout -> String
$cshow :: GrpcTimeout -> String
showsPrec :: Int -> GrpcTimeout -> ShowS
$cshowsPrec :: Int -> GrpcTimeout -> ShowS
Prelude.Show, forall x. Rep GrpcTimeout x -> GrpcTimeout
forall x. GrpcTimeout -> Rep GrpcTimeout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrpcTimeout x -> GrpcTimeout
$cfrom :: forall x. GrpcTimeout -> Rep GrpcTimeout x
Prelude.Generic)

-- |
-- Create a value of 'GrpcTimeout' 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:
--
-- 'idle', 'grpcTimeout_idle' - An object that represents an idle timeout. An idle timeout bounds the
-- amount of time that a connection may be idle. The default value is none.
--
-- 'perRequest', 'grpcTimeout_perRequest' - An object that represents a per request timeout. The default value is 15
-- seconds. If you set a higher timeout, then make sure that the higher
-- value is set for each App Mesh resource in a conversation. For example,
-- if a virtual node backend uses a virtual router provider to route to
-- another virtual node, then the timeout should be greater than 15 seconds
-- for the source and destination virtual node and the route.
newGrpcTimeout ::
  GrpcTimeout
newGrpcTimeout :: GrpcTimeout
newGrpcTimeout =
  GrpcTimeout'
    { $sel:idle:GrpcTimeout' :: Maybe Duration
idle = forall a. Maybe a
Prelude.Nothing,
      $sel:perRequest:GrpcTimeout' :: Maybe Duration
perRequest = forall a. Maybe a
Prelude.Nothing
    }

-- | An object that represents an idle timeout. An idle timeout bounds the
-- amount of time that a connection may be idle. The default value is none.
grpcTimeout_idle :: Lens.Lens' GrpcTimeout (Prelude.Maybe Duration)
grpcTimeout_idle :: Lens' GrpcTimeout (Maybe Duration)
grpcTimeout_idle = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcTimeout' {Maybe Duration
idle :: Maybe Duration
$sel:idle:GrpcTimeout' :: GrpcTimeout -> Maybe Duration
idle} -> Maybe Duration
idle) (\s :: GrpcTimeout
s@GrpcTimeout' {} Maybe Duration
a -> GrpcTimeout
s {$sel:idle:GrpcTimeout' :: Maybe Duration
idle = Maybe Duration
a} :: GrpcTimeout)

-- | An object that represents a per request timeout. The default value is 15
-- seconds. If you set a higher timeout, then make sure that the higher
-- value is set for each App Mesh resource in a conversation. For example,
-- if a virtual node backend uses a virtual router provider to route to
-- another virtual node, then the timeout should be greater than 15 seconds
-- for the source and destination virtual node and the route.
grpcTimeout_perRequest :: Lens.Lens' GrpcTimeout (Prelude.Maybe Duration)
grpcTimeout_perRequest :: Lens' GrpcTimeout (Maybe Duration)
grpcTimeout_perRequest = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcTimeout' {Maybe Duration
perRequest :: Maybe Duration
$sel:perRequest:GrpcTimeout' :: GrpcTimeout -> Maybe Duration
perRequest} -> Maybe Duration
perRequest) (\s :: GrpcTimeout
s@GrpcTimeout' {} Maybe Duration
a -> GrpcTimeout
s {$sel:perRequest:GrpcTimeout' :: Maybe Duration
perRequest = Maybe Duration
a} :: GrpcTimeout)

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

instance Prelude.Hashable GrpcTimeout where
  hashWithSalt :: Int -> GrpcTimeout -> Int
hashWithSalt Int
_salt GrpcTimeout' {Maybe Duration
perRequest :: Maybe Duration
idle :: Maybe Duration
$sel:perRequest:GrpcTimeout' :: GrpcTimeout -> Maybe Duration
$sel:idle:GrpcTimeout' :: GrpcTimeout -> Maybe Duration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Duration
idle
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Duration
perRequest

instance Prelude.NFData GrpcTimeout where
  rnf :: GrpcTimeout -> ()
rnf GrpcTimeout' {Maybe Duration
perRequest :: Maybe Duration
idle :: Maybe Duration
$sel:perRequest:GrpcTimeout' :: GrpcTimeout -> Maybe Duration
$sel:idle:GrpcTimeout' :: GrpcTimeout -> Maybe Duration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Duration
idle
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Duration
perRequest

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