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

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

-- | An object that represents types of timeouts.
--
-- /See:/ 'newTcpTimeout' smart constructor.
data TcpTimeout = TcpTimeout'
  { -- | 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.
    TcpTimeout -> Maybe Duration
idle :: Prelude.Maybe Duration
  }
  deriving (TcpTimeout -> TcpTimeout -> Bool
(TcpTimeout -> TcpTimeout -> Bool)
-> (TcpTimeout -> TcpTimeout -> Bool) -> Eq TcpTimeout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TcpTimeout -> TcpTimeout -> Bool
$c/= :: TcpTimeout -> TcpTimeout -> Bool
== :: TcpTimeout -> TcpTimeout -> Bool
$c== :: TcpTimeout -> TcpTimeout -> Bool
Prelude.Eq, ReadPrec [TcpTimeout]
ReadPrec TcpTimeout
Int -> ReadS TcpTimeout
ReadS [TcpTimeout]
(Int -> ReadS TcpTimeout)
-> ReadS [TcpTimeout]
-> ReadPrec TcpTimeout
-> ReadPrec [TcpTimeout]
-> Read TcpTimeout
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TcpTimeout]
$creadListPrec :: ReadPrec [TcpTimeout]
readPrec :: ReadPrec TcpTimeout
$creadPrec :: ReadPrec TcpTimeout
readList :: ReadS [TcpTimeout]
$creadList :: ReadS [TcpTimeout]
readsPrec :: Int -> ReadS TcpTimeout
$creadsPrec :: Int -> ReadS TcpTimeout
Prelude.Read, Int -> TcpTimeout -> ShowS
[TcpTimeout] -> ShowS
TcpTimeout -> String
(Int -> TcpTimeout -> ShowS)
-> (TcpTimeout -> String)
-> ([TcpTimeout] -> ShowS)
-> Show TcpTimeout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TcpTimeout] -> ShowS
$cshowList :: [TcpTimeout] -> ShowS
show :: TcpTimeout -> String
$cshow :: TcpTimeout -> String
showsPrec :: Int -> TcpTimeout -> ShowS
$cshowsPrec :: Int -> TcpTimeout -> ShowS
Prelude.Show, (forall x. TcpTimeout -> Rep TcpTimeout x)
-> (forall x. Rep TcpTimeout x -> TcpTimeout) -> Generic TcpTimeout
forall x. Rep TcpTimeout x -> TcpTimeout
forall x. TcpTimeout -> Rep TcpTimeout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TcpTimeout x -> TcpTimeout
$cfrom :: forall x. TcpTimeout -> Rep TcpTimeout x
Prelude.Generic)

-- |
-- Create a value of 'TcpTimeout' 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', 'tcpTimeout_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.
newTcpTimeout ::
  TcpTimeout
newTcpTimeout :: TcpTimeout
newTcpTimeout = TcpTimeout' :: Maybe Duration -> TcpTimeout
TcpTimeout' {$sel:idle:TcpTimeout' :: Maybe Duration
idle = Maybe Duration
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.
tcpTimeout_idle :: Lens.Lens' TcpTimeout (Prelude.Maybe Duration)
tcpTimeout_idle :: (Maybe Duration -> f (Maybe Duration))
-> TcpTimeout -> f TcpTimeout
tcpTimeout_idle = (TcpTimeout -> Maybe Duration)
-> (TcpTimeout -> Maybe Duration -> TcpTimeout)
-> Lens TcpTimeout TcpTimeout (Maybe Duration) (Maybe Duration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TcpTimeout' {Maybe Duration
idle :: Maybe Duration
$sel:idle:TcpTimeout' :: TcpTimeout -> Maybe Duration
idle} -> Maybe Duration
idle) (\s :: TcpTimeout
s@TcpTimeout' {} Maybe Duration
a -> TcpTimeout
s {$sel:idle:TcpTimeout' :: Maybe Duration
idle = Maybe Duration
a} :: TcpTimeout)

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

instance Prelude.Hashable TcpTimeout

instance Prelude.NFData TcpTimeout

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