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

import Amazonka.AppMesh.Types.GrpcRetryPolicy
import Amazonka.AppMesh.Types.GrpcRouteAction
import Amazonka.AppMesh.Types.GrpcRouteMatch
import Amazonka.AppMesh.Types.GrpcTimeout
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents a gRPC route type.
--
-- /See:/ 'newGrpcRoute' smart constructor.
data GrpcRoute = GrpcRoute'
  { -- | An object that represents a retry policy.
    GrpcRoute -> Maybe GrpcRetryPolicy
retryPolicy :: Prelude.Maybe GrpcRetryPolicy,
    -- | An object that represents types of timeouts.
    GrpcRoute -> Maybe GrpcTimeout
timeout :: Prelude.Maybe GrpcTimeout,
    -- | An object that represents the action to take if a match is determined.
    GrpcRoute -> GrpcRouteAction
action :: GrpcRouteAction,
    -- | An object that represents the criteria for determining a request match.
    GrpcRoute -> GrpcRouteMatch
match :: GrpcRouteMatch
  }
  deriving (GrpcRoute -> GrpcRoute -> Bool
(GrpcRoute -> GrpcRoute -> Bool)
-> (GrpcRoute -> GrpcRoute -> Bool) -> Eq GrpcRoute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrpcRoute -> GrpcRoute -> Bool
$c/= :: GrpcRoute -> GrpcRoute -> Bool
== :: GrpcRoute -> GrpcRoute -> Bool
$c== :: GrpcRoute -> GrpcRoute -> Bool
Prelude.Eq, ReadPrec [GrpcRoute]
ReadPrec GrpcRoute
Int -> ReadS GrpcRoute
ReadS [GrpcRoute]
(Int -> ReadS GrpcRoute)
-> ReadS [GrpcRoute]
-> ReadPrec GrpcRoute
-> ReadPrec [GrpcRoute]
-> Read GrpcRoute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrpcRoute]
$creadListPrec :: ReadPrec [GrpcRoute]
readPrec :: ReadPrec GrpcRoute
$creadPrec :: ReadPrec GrpcRoute
readList :: ReadS [GrpcRoute]
$creadList :: ReadS [GrpcRoute]
readsPrec :: Int -> ReadS GrpcRoute
$creadsPrec :: Int -> ReadS GrpcRoute
Prelude.Read, Int -> GrpcRoute -> ShowS
[GrpcRoute] -> ShowS
GrpcRoute -> String
(Int -> GrpcRoute -> ShowS)
-> (GrpcRoute -> String)
-> ([GrpcRoute] -> ShowS)
-> Show GrpcRoute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrpcRoute] -> ShowS
$cshowList :: [GrpcRoute] -> ShowS
show :: GrpcRoute -> String
$cshow :: GrpcRoute -> String
showsPrec :: Int -> GrpcRoute -> ShowS
$cshowsPrec :: Int -> GrpcRoute -> ShowS
Prelude.Show, (forall x. GrpcRoute -> Rep GrpcRoute x)
-> (forall x. Rep GrpcRoute x -> GrpcRoute) -> Generic GrpcRoute
forall x. Rep GrpcRoute x -> GrpcRoute
forall x. GrpcRoute -> Rep GrpcRoute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrpcRoute x -> GrpcRoute
$cfrom :: forall x. GrpcRoute -> Rep GrpcRoute x
Prelude.Generic)

-- |
-- Create a value of 'GrpcRoute' 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:
--
-- 'retryPolicy', 'grpcRoute_retryPolicy' - An object that represents a retry policy.
--
-- 'timeout', 'grpcRoute_timeout' - An object that represents types of timeouts.
--
-- 'action', 'grpcRoute_action' - An object that represents the action to take if a match is determined.
--
-- 'match', 'grpcRoute_match' - An object that represents the criteria for determining a request match.
newGrpcRoute ::
  -- | 'action'
  GrpcRouteAction ->
  -- | 'match'
  GrpcRouteMatch ->
  GrpcRoute
newGrpcRoute :: GrpcRouteAction -> GrpcRouteMatch -> GrpcRoute
newGrpcRoute GrpcRouteAction
pAction_ GrpcRouteMatch
pMatch_ =
  GrpcRoute' :: Maybe GrpcRetryPolicy
-> Maybe GrpcTimeout
-> GrpcRouteAction
-> GrpcRouteMatch
-> GrpcRoute
GrpcRoute'
    { $sel:retryPolicy:GrpcRoute' :: Maybe GrpcRetryPolicy
retryPolicy = Maybe GrpcRetryPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:timeout:GrpcRoute' :: Maybe GrpcTimeout
timeout = Maybe GrpcTimeout
forall a. Maybe a
Prelude.Nothing,
      $sel:action:GrpcRoute' :: GrpcRouteAction
action = GrpcRouteAction
pAction_,
      $sel:match:GrpcRoute' :: GrpcRouteMatch
match = GrpcRouteMatch
pMatch_
    }

-- | An object that represents a retry policy.
grpcRoute_retryPolicy :: Lens.Lens' GrpcRoute (Prelude.Maybe GrpcRetryPolicy)
grpcRoute_retryPolicy :: (Maybe GrpcRetryPolicy -> f (Maybe GrpcRetryPolicy))
-> GrpcRoute -> f GrpcRoute
grpcRoute_retryPolicy = (GrpcRoute -> Maybe GrpcRetryPolicy)
-> (GrpcRoute -> Maybe GrpcRetryPolicy -> GrpcRoute)
-> Lens
     GrpcRoute GrpcRoute (Maybe GrpcRetryPolicy) (Maybe GrpcRetryPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRoute' {Maybe GrpcRetryPolicy
retryPolicy :: Maybe GrpcRetryPolicy
$sel:retryPolicy:GrpcRoute' :: GrpcRoute -> Maybe GrpcRetryPolicy
retryPolicy} -> Maybe GrpcRetryPolicy
retryPolicy) (\s :: GrpcRoute
s@GrpcRoute' {} Maybe GrpcRetryPolicy
a -> GrpcRoute
s {$sel:retryPolicy:GrpcRoute' :: Maybe GrpcRetryPolicy
retryPolicy = Maybe GrpcRetryPolicy
a} :: GrpcRoute)

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

-- | An object that represents the action to take if a match is determined.
grpcRoute_action :: Lens.Lens' GrpcRoute GrpcRouteAction
grpcRoute_action :: (GrpcRouteAction -> f GrpcRouteAction) -> GrpcRoute -> f GrpcRoute
grpcRoute_action = (GrpcRoute -> GrpcRouteAction)
-> (GrpcRoute -> GrpcRouteAction -> GrpcRoute)
-> Lens GrpcRoute GrpcRoute GrpcRouteAction GrpcRouteAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRoute' {GrpcRouteAction
action :: GrpcRouteAction
$sel:action:GrpcRoute' :: GrpcRoute -> GrpcRouteAction
action} -> GrpcRouteAction
action) (\s :: GrpcRoute
s@GrpcRoute' {} GrpcRouteAction
a -> GrpcRoute
s {$sel:action:GrpcRoute' :: GrpcRouteAction
action = GrpcRouteAction
a} :: GrpcRoute)

-- | An object that represents the criteria for determining a request match.
grpcRoute_match :: Lens.Lens' GrpcRoute GrpcRouteMatch
grpcRoute_match :: (GrpcRouteMatch -> f GrpcRouteMatch) -> GrpcRoute -> f GrpcRoute
grpcRoute_match = (GrpcRoute -> GrpcRouteMatch)
-> (GrpcRoute -> GrpcRouteMatch -> GrpcRoute)
-> Lens GrpcRoute GrpcRoute GrpcRouteMatch GrpcRouteMatch
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRoute' {GrpcRouteMatch
match :: GrpcRouteMatch
$sel:match:GrpcRoute' :: GrpcRoute -> GrpcRouteMatch
match} -> GrpcRouteMatch
match) (\s :: GrpcRoute
s@GrpcRoute' {} GrpcRouteMatch
a -> GrpcRoute
s {$sel:match:GrpcRoute' :: GrpcRouteMatch
match = GrpcRouteMatch
a} :: GrpcRoute)

instance Core.FromJSON GrpcRoute where
  parseJSON :: Value -> Parser GrpcRoute
parseJSON =
    String -> (Object -> Parser GrpcRoute) -> Value -> Parser GrpcRoute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GrpcRoute"
      ( \Object
x ->
          Maybe GrpcRetryPolicy
-> Maybe GrpcTimeout
-> GrpcRouteAction
-> GrpcRouteMatch
-> GrpcRoute
GrpcRoute'
            (Maybe GrpcRetryPolicy
 -> Maybe GrpcTimeout
 -> GrpcRouteAction
 -> GrpcRouteMatch
 -> GrpcRoute)
-> Parser (Maybe GrpcRetryPolicy)
-> Parser
     (Maybe GrpcTimeout
      -> GrpcRouteAction -> GrpcRouteMatch -> GrpcRoute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe GrpcRetryPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"retryPolicy")
            Parser
  (Maybe GrpcTimeout
   -> GrpcRouteAction -> GrpcRouteMatch -> GrpcRoute)
-> Parser (Maybe GrpcTimeout)
-> Parser (GrpcRouteAction -> GrpcRouteMatch -> GrpcRoute)
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
"timeout")
            Parser (GrpcRouteAction -> GrpcRouteMatch -> GrpcRoute)
-> Parser GrpcRouteAction -> Parser (GrpcRouteMatch -> GrpcRoute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GrpcRouteAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"action")
            Parser (GrpcRouteMatch -> GrpcRoute)
-> Parser GrpcRouteMatch -> Parser GrpcRoute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GrpcRouteMatch
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"match")
      )

instance Prelude.Hashable GrpcRoute

instance Prelude.NFData GrpcRoute

instance Core.ToJSON GrpcRoute where
  toJSON :: GrpcRoute -> Value
toJSON GrpcRoute' {Maybe GrpcTimeout
Maybe GrpcRetryPolicy
GrpcRouteMatch
GrpcRouteAction
match :: GrpcRouteMatch
action :: GrpcRouteAction
timeout :: Maybe GrpcTimeout
retryPolicy :: Maybe GrpcRetryPolicy
$sel:match:GrpcRoute' :: GrpcRoute -> GrpcRouteMatch
$sel:action:GrpcRoute' :: GrpcRoute -> GrpcRouteAction
$sel:timeout:GrpcRoute' :: GrpcRoute -> Maybe GrpcTimeout
$sel:retryPolicy:GrpcRoute' :: GrpcRoute -> Maybe GrpcRetryPolicy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"retryPolicy" Text -> GrpcRetryPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (GrpcRetryPolicy -> Pair) -> Maybe GrpcRetryPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GrpcRetryPolicy
retryPolicy,
            (Text
"timeout" 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
timeout,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> GrpcRouteAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GrpcRouteAction
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"match" Text -> GrpcRouteMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GrpcRouteMatch
match)
          ]
      )