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

import Amazonka.AppMesh.Types.GatewayRouteTarget
import Amazonka.AppMesh.Types.GrpcGatewayRouteRewrite
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the action to take if a match is determined.
--
-- /See:/ 'newGrpcGatewayRouteAction' smart constructor.
data GrpcGatewayRouteAction = GrpcGatewayRouteAction'
  { -- | The gateway route action to rewrite.
    GrpcGatewayRouteAction -> Maybe GrpcGatewayRouteRewrite
rewrite :: Prelude.Maybe GrpcGatewayRouteRewrite,
    -- | An object that represents the target that traffic is routed to when a
    -- request matches the gateway route.
    GrpcGatewayRouteAction -> GatewayRouteTarget
target :: GatewayRouteTarget
  }
  deriving (GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool
(GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool)
-> (GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool)
-> Eq GrpcGatewayRouteAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool
$c/= :: GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool
== :: GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool
$c== :: GrpcGatewayRouteAction -> GrpcGatewayRouteAction -> Bool
Prelude.Eq, ReadPrec [GrpcGatewayRouteAction]
ReadPrec GrpcGatewayRouteAction
Int -> ReadS GrpcGatewayRouteAction
ReadS [GrpcGatewayRouteAction]
(Int -> ReadS GrpcGatewayRouteAction)
-> ReadS [GrpcGatewayRouteAction]
-> ReadPrec GrpcGatewayRouteAction
-> ReadPrec [GrpcGatewayRouteAction]
-> Read GrpcGatewayRouteAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrpcGatewayRouteAction]
$creadListPrec :: ReadPrec [GrpcGatewayRouteAction]
readPrec :: ReadPrec GrpcGatewayRouteAction
$creadPrec :: ReadPrec GrpcGatewayRouteAction
readList :: ReadS [GrpcGatewayRouteAction]
$creadList :: ReadS [GrpcGatewayRouteAction]
readsPrec :: Int -> ReadS GrpcGatewayRouteAction
$creadsPrec :: Int -> ReadS GrpcGatewayRouteAction
Prelude.Read, Int -> GrpcGatewayRouteAction -> ShowS
[GrpcGatewayRouteAction] -> ShowS
GrpcGatewayRouteAction -> String
(Int -> GrpcGatewayRouteAction -> ShowS)
-> (GrpcGatewayRouteAction -> String)
-> ([GrpcGatewayRouteAction] -> ShowS)
-> Show GrpcGatewayRouteAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrpcGatewayRouteAction] -> ShowS
$cshowList :: [GrpcGatewayRouteAction] -> ShowS
show :: GrpcGatewayRouteAction -> String
$cshow :: GrpcGatewayRouteAction -> String
showsPrec :: Int -> GrpcGatewayRouteAction -> ShowS
$cshowsPrec :: Int -> GrpcGatewayRouteAction -> ShowS
Prelude.Show, (forall x. GrpcGatewayRouteAction -> Rep GrpcGatewayRouteAction x)
-> (forall x.
    Rep GrpcGatewayRouteAction x -> GrpcGatewayRouteAction)
-> Generic GrpcGatewayRouteAction
forall x. Rep GrpcGatewayRouteAction x -> GrpcGatewayRouteAction
forall x. GrpcGatewayRouteAction -> Rep GrpcGatewayRouteAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrpcGatewayRouteAction x -> GrpcGatewayRouteAction
$cfrom :: forall x. GrpcGatewayRouteAction -> Rep GrpcGatewayRouteAction x
Prelude.Generic)

-- |
-- Create a value of 'GrpcGatewayRouteAction' 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:
--
-- 'rewrite', 'grpcGatewayRouteAction_rewrite' - The gateway route action to rewrite.
--
-- 'target', 'grpcGatewayRouteAction_target' - An object that represents the target that traffic is routed to when a
-- request matches the gateway route.
newGrpcGatewayRouteAction ::
  -- | 'target'
  GatewayRouteTarget ->
  GrpcGatewayRouteAction
newGrpcGatewayRouteAction :: GatewayRouteTarget -> GrpcGatewayRouteAction
newGrpcGatewayRouteAction GatewayRouteTarget
pTarget_ =
  GrpcGatewayRouteAction' :: Maybe GrpcGatewayRouteRewrite
-> GatewayRouteTarget -> GrpcGatewayRouteAction
GrpcGatewayRouteAction'
    { $sel:rewrite:GrpcGatewayRouteAction' :: Maybe GrpcGatewayRouteRewrite
rewrite = Maybe GrpcGatewayRouteRewrite
forall a. Maybe a
Prelude.Nothing,
      $sel:target:GrpcGatewayRouteAction' :: GatewayRouteTarget
target = GatewayRouteTarget
pTarget_
    }

-- | The gateway route action to rewrite.
grpcGatewayRouteAction_rewrite :: Lens.Lens' GrpcGatewayRouteAction (Prelude.Maybe GrpcGatewayRouteRewrite)
grpcGatewayRouteAction_rewrite :: (Maybe GrpcGatewayRouteRewrite
 -> f (Maybe GrpcGatewayRouteRewrite))
-> GrpcGatewayRouteAction -> f GrpcGatewayRouteAction
grpcGatewayRouteAction_rewrite = (GrpcGatewayRouteAction -> Maybe GrpcGatewayRouteRewrite)
-> (GrpcGatewayRouteAction
    -> Maybe GrpcGatewayRouteRewrite -> GrpcGatewayRouteAction)
-> Lens
     GrpcGatewayRouteAction
     GrpcGatewayRouteAction
     (Maybe GrpcGatewayRouteRewrite)
     (Maybe GrpcGatewayRouteRewrite)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcGatewayRouteAction' {Maybe GrpcGatewayRouteRewrite
rewrite :: Maybe GrpcGatewayRouteRewrite
$sel:rewrite:GrpcGatewayRouteAction' :: GrpcGatewayRouteAction -> Maybe GrpcGatewayRouteRewrite
rewrite} -> Maybe GrpcGatewayRouteRewrite
rewrite) (\s :: GrpcGatewayRouteAction
s@GrpcGatewayRouteAction' {} Maybe GrpcGatewayRouteRewrite
a -> GrpcGatewayRouteAction
s {$sel:rewrite:GrpcGatewayRouteAction' :: Maybe GrpcGatewayRouteRewrite
rewrite = Maybe GrpcGatewayRouteRewrite
a} :: GrpcGatewayRouteAction)

-- | An object that represents the target that traffic is routed to when a
-- request matches the gateway route.
grpcGatewayRouteAction_target :: Lens.Lens' GrpcGatewayRouteAction GatewayRouteTarget
grpcGatewayRouteAction_target :: (GatewayRouteTarget -> f GatewayRouteTarget)
-> GrpcGatewayRouteAction -> f GrpcGatewayRouteAction
grpcGatewayRouteAction_target = (GrpcGatewayRouteAction -> GatewayRouteTarget)
-> (GrpcGatewayRouteAction
    -> GatewayRouteTarget -> GrpcGatewayRouteAction)
-> Lens
     GrpcGatewayRouteAction
     GrpcGatewayRouteAction
     GatewayRouteTarget
     GatewayRouteTarget
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcGatewayRouteAction' {GatewayRouteTarget
target :: GatewayRouteTarget
$sel:target:GrpcGatewayRouteAction' :: GrpcGatewayRouteAction -> GatewayRouteTarget
target} -> GatewayRouteTarget
target) (\s :: GrpcGatewayRouteAction
s@GrpcGatewayRouteAction' {} GatewayRouteTarget
a -> GrpcGatewayRouteAction
s {$sel:target:GrpcGatewayRouteAction' :: GatewayRouteTarget
target = GatewayRouteTarget
a} :: GrpcGatewayRouteAction)

instance Core.FromJSON GrpcGatewayRouteAction where
  parseJSON :: Value -> Parser GrpcGatewayRouteAction
parseJSON =
    String
-> (Object -> Parser GrpcGatewayRouteAction)
-> Value
-> Parser GrpcGatewayRouteAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GrpcGatewayRouteAction"
      ( \Object
x ->
          Maybe GrpcGatewayRouteRewrite
-> GatewayRouteTarget -> GrpcGatewayRouteAction
GrpcGatewayRouteAction'
            (Maybe GrpcGatewayRouteRewrite
 -> GatewayRouteTarget -> GrpcGatewayRouteAction)
-> Parser (Maybe GrpcGatewayRouteRewrite)
-> Parser (GatewayRouteTarget -> GrpcGatewayRouteAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe GrpcGatewayRouteRewrite)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"rewrite")
            Parser (GatewayRouteTarget -> GrpcGatewayRouteAction)
-> Parser GatewayRouteTarget -> Parser GrpcGatewayRouteAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GatewayRouteTarget
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"target")
      )

instance Prelude.Hashable GrpcGatewayRouteAction

instance Prelude.NFData GrpcGatewayRouteAction

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