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

import Amazonka.AppMesh.Types.GrpcTimeout
import Amazonka.AppMesh.Types.HttpTimeout
import Amazonka.AppMesh.Types.TcpTimeout
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents timeouts for different protocols.
--
-- /See:/ 'newListenerTimeout' smart constructor.
data ListenerTimeout = ListenerTimeout'
  { -- | An object that represents types of timeouts.
    ListenerTimeout -> Maybe HttpTimeout
http2 :: Prelude.Maybe HttpTimeout,
    -- | An object that represents types of timeouts.
    ListenerTimeout -> Maybe GrpcTimeout
grpc :: Prelude.Maybe GrpcTimeout,
    -- | An object that represents types of timeouts.
    ListenerTimeout -> Maybe TcpTimeout
tcp :: Prelude.Maybe TcpTimeout,
    -- | An object that represents types of timeouts.
    ListenerTimeout -> Maybe HttpTimeout
http :: Prelude.Maybe HttpTimeout
  }
  deriving (ListenerTimeout -> ListenerTimeout -> Bool
(ListenerTimeout -> ListenerTimeout -> Bool)
-> (ListenerTimeout -> ListenerTimeout -> Bool)
-> Eq ListenerTimeout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListenerTimeout -> ListenerTimeout -> Bool
$c/= :: ListenerTimeout -> ListenerTimeout -> Bool
== :: ListenerTimeout -> ListenerTimeout -> Bool
$c== :: ListenerTimeout -> ListenerTimeout -> Bool
Prelude.Eq, ReadPrec [ListenerTimeout]
ReadPrec ListenerTimeout
Int -> ReadS ListenerTimeout
ReadS [ListenerTimeout]
(Int -> ReadS ListenerTimeout)
-> ReadS [ListenerTimeout]
-> ReadPrec ListenerTimeout
-> ReadPrec [ListenerTimeout]
-> Read ListenerTimeout
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListenerTimeout]
$creadListPrec :: ReadPrec [ListenerTimeout]
readPrec :: ReadPrec ListenerTimeout
$creadPrec :: ReadPrec ListenerTimeout
readList :: ReadS [ListenerTimeout]
$creadList :: ReadS [ListenerTimeout]
readsPrec :: Int -> ReadS ListenerTimeout
$creadsPrec :: Int -> ReadS ListenerTimeout
Prelude.Read, Int -> ListenerTimeout -> ShowS
[ListenerTimeout] -> ShowS
ListenerTimeout -> String
(Int -> ListenerTimeout -> ShowS)
-> (ListenerTimeout -> String)
-> ([ListenerTimeout] -> ShowS)
-> Show ListenerTimeout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListenerTimeout] -> ShowS
$cshowList :: [ListenerTimeout] -> ShowS
show :: ListenerTimeout -> String
$cshow :: ListenerTimeout -> String
showsPrec :: Int -> ListenerTimeout -> ShowS
$cshowsPrec :: Int -> ListenerTimeout -> ShowS
Prelude.Show, (forall x. ListenerTimeout -> Rep ListenerTimeout x)
-> (forall x. Rep ListenerTimeout x -> ListenerTimeout)
-> Generic ListenerTimeout
forall x. Rep ListenerTimeout x -> ListenerTimeout
forall x. ListenerTimeout -> Rep ListenerTimeout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListenerTimeout x -> ListenerTimeout
$cfrom :: forall x. ListenerTimeout -> Rep ListenerTimeout x
Prelude.Generic)

-- |
-- Create a value of 'ListenerTimeout' 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:
--
-- 'http2', 'listenerTimeout_http2' - An object that represents types of timeouts.
--
-- 'grpc', 'listenerTimeout_grpc' - An object that represents types of timeouts.
--
-- 'tcp', 'listenerTimeout_tcp' - An object that represents types of timeouts.
--
-- 'http', 'listenerTimeout_http' - An object that represents types of timeouts.
newListenerTimeout ::
  ListenerTimeout
newListenerTimeout :: ListenerTimeout
newListenerTimeout =
  ListenerTimeout' :: Maybe HttpTimeout
-> Maybe GrpcTimeout
-> Maybe TcpTimeout
-> Maybe HttpTimeout
-> ListenerTimeout
ListenerTimeout'
    { $sel:http2:ListenerTimeout' :: Maybe HttpTimeout
http2 = Maybe HttpTimeout
forall a. Maybe a
Prelude.Nothing,
      $sel:grpc:ListenerTimeout' :: Maybe GrpcTimeout
grpc = Maybe GrpcTimeout
forall a. Maybe a
Prelude.Nothing,
      $sel:tcp:ListenerTimeout' :: Maybe TcpTimeout
tcp = Maybe TcpTimeout
forall a. Maybe a
Prelude.Nothing,
      $sel:http:ListenerTimeout' :: Maybe HttpTimeout
http = Maybe HttpTimeout
forall a. Maybe a
Prelude.Nothing
    }

-- | An object that represents types of timeouts.
listenerTimeout_http2 :: Lens.Lens' ListenerTimeout (Prelude.Maybe HttpTimeout)
listenerTimeout_http2 :: (Maybe HttpTimeout -> f (Maybe HttpTimeout))
-> ListenerTimeout -> f ListenerTimeout
listenerTimeout_http2 = (ListenerTimeout -> Maybe HttpTimeout)
-> (ListenerTimeout -> Maybe HttpTimeout -> ListenerTimeout)
-> Lens
     ListenerTimeout
     ListenerTimeout
     (Maybe HttpTimeout)
     (Maybe HttpTimeout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListenerTimeout' {Maybe HttpTimeout
http2 :: Maybe HttpTimeout
$sel:http2:ListenerTimeout' :: ListenerTimeout -> Maybe HttpTimeout
http2} -> Maybe HttpTimeout
http2) (\s :: ListenerTimeout
s@ListenerTimeout' {} Maybe HttpTimeout
a -> ListenerTimeout
s {$sel:http2:ListenerTimeout' :: Maybe HttpTimeout
http2 = Maybe HttpTimeout
a} :: ListenerTimeout)

-- | An object that represents types of timeouts.
listenerTimeout_grpc :: Lens.Lens' ListenerTimeout (Prelude.Maybe GrpcTimeout)
listenerTimeout_grpc :: (Maybe GrpcTimeout -> f (Maybe GrpcTimeout))
-> ListenerTimeout -> f ListenerTimeout
listenerTimeout_grpc = (ListenerTimeout -> Maybe GrpcTimeout)
-> (ListenerTimeout -> Maybe GrpcTimeout -> ListenerTimeout)
-> Lens
     ListenerTimeout
     ListenerTimeout
     (Maybe GrpcTimeout)
     (Maybe GrpcTimeout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListenerTimeout' {Maybe GrpcTimeout
grpc :: Maybe GrpcTimeout
$sel:grpc:ListenerTimeout' :: ListenerTimeout -> Maybe GrpcTimeout
grpc} -> Maybe GrpcTimeout
grpc) (\s :: ListenerTimeout
s@ListenerTimeout' {} Maybe GrpcTimeout
a -> ListenerTimeout
s {$sel:grpc:ListenerTimeout' :: Maybe GrpcTimeout
grpc = Maybe GrpcTimeout
a} :: ListenerTimeout)

-- | An object that represents types of timeouts.
listenerTimeout_tcp :: Lens.Lens' ListenerTimeout (Prelude.Maybe TcpTimeout)
listenerTimeout_tcp :: (Maybe TcpTimeout -> f (Maybe TcpTimeout))
-> ListenerTimeout -> f ListenerTimeout
listenerTimeout_tcp = (ListenerTimeout -> Maybe TcpTimeout)
-> (ListenerTimeout -> Maybe TcpTimeout -> ListenerTimeout)
-> Lens
     ListenerTimeout
     ListenerTimeout
     (Maybe TcpTimeout)
     (Maybe TcpTimeout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListenerTimeout' {Maybe TcpTimeout
tcp :: Maybe TcpTimeout
$sel:tcp:ListenerTimeout' :: ListenerTimeout -> Maybe TcpTimeout
tcp} -> Maybe TcpTimeout
tcp) (\s :: ListenerTimeout
s@ListenerTimeout' {} Maybe TcpTimeout
a -> ListenerTimeout
s {$sel:tcp:ListenerTimeout' :: Maybe TcpTimeout
tcp = Maybe TcpTimeout
a} :: ListenerTimeout)

-- | An object that represents types of timeouts.
listenerTimeout_http :: Lens.Lens' ListenerTimeout (Prelude.Maybe HttpTimeout)
listenerTimeout_http :: (Maybe HttpTimeout -> f (Maybe HttpTimeout))
-> ListenerTimeout -> f ListenerTimeout
listenerTimeout_http = (ListenerTimeout -> Maybe HttpTimeout)
-> (ListenerTimeout -> Maybe HttpTimeout -> ListenerTimeout)
-> Lens
     ListenerTimeout
     ListenerTimeout
     (Maybe HttpTimeout)
     (Maybe HttpTimeout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListenerTimeout' {Maybe HttpTimeout
http :: Maybe HttpTimeout
$sel:http:ListenerTimeout' :: ListenerTimeout -> Maybe HttpTimeout
http} -> Maybe HttpTimeout
http) (\s :: ListenerTimeout
s@ListenerTimeout' {} Maybe HttpTimeout
a -> ListenerTimeout
s {$sel:http:ListenerTimeout' :: Maybe HttpTimeout
http = Maybe HttpTimeout
a} :: ListenerTimeout)

instance Core.FromJSON ListenerTimeout where
  parseJSON :: Value -> Parser ListenerTimeout
parseJSON =
    String
-> (Object -> Parser ListenerTimeout)
-> Value
-> Parser ListenerTimeout
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ListenerTimeout"
      ( \Object
x ->
          Maybe HttpTimeout
-> Maybe GrpcTimeout
-> Maybe TcpTimeout
-> Maybe HttpTimeout
-> ListenerTimeout
ListenerTimeout'
            (Maybe HttpTimeout
 -> Maybe GrpcTimeout
 -> Maybe TcpTimeout
 -> Maybe HttpTimeout
 -> ListenerTimeout)
-> Parser (Maybe HttpTimeout)
-> Parser
     (Maybe GrpcTimeout
      -> Maybe TcpTimeout -> Maybe HttpTimeout -> ListenerTimeout)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe HttpTimeout)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"http2")
            Parser
  (Maybe GrpcTimeout
   -> Maybe TcpTimeout -> Maybe HttpTimeout -> ListenerTimeout)
-> Parser (Maybe GrpcTimeout)
-> Parser
     (Maybe TcpTimeout -> Maybe HttpTimeout -> ListenerTimeout)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GrpcTimeout)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"grpc")
            Parser (Maybe TcpTimeout -> Maybe HttpTimeout -> ListenerTimeout)
-> Parser (Maybe TcpTimeout)
-> Parser (Maybe HttpTimeout -> ListenerTimeout)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TcpTimeout)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"tcp")
            Parser (Maybe HttpTimeout -> ListenerTimeout)
-> Parser (Maybe HttpTimeout) -> Parser ListenerTimeout
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HttpTimeout)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"http")
      )

instance Prelude.Hashable ListenerTimeout

instance Prelude.NFData ListenerTimeout

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