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

import Amazonka.AppMesh.Types.GatewayRouteTarget
import Amazonka.AppMesh.Types.GrpcGatewayRouteRewrite
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 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
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]
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
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. 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'
    { $sel:rewrite:GrpcGatewayRouteAction' :: Maybe GrpcGatewayRouteRewrite
rewrite = 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 :: Lens' GrpcGatewayRouteAction (Maybe GrpcGatewayRouteRewrite)
grpcGatewayRouteAction_rewrite = 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 :: Lens' GrpcGatewayRouteAction GatewayRouteTarget
grpcGatewayRouteAction_target = 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 Data.FromJSON GrpcGatewayRouteAction where
  parseJSON :: Value -> Parser GrpcGatewayRouteAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"GrpcGatewayRouteAction"
      ( \Object
x ->
          Maybe GrpcGatewayRouteRewrite
-> GatewayRouteTarget -> GrpcGatewayRouteAction
GrpcGatewayRouteAction'
            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
"rewrite")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"target")
      )

instance Prelude.Hashable GrpcGatewayRouteAction where
  hashWithSalt :: Int -> GrpcGatewayRouteAction -> Int
hashWithSalt Int
_salt GrpcGatewayRouteAction' {Maybe GrpcGatewayRouteRewrite
GatewayRouteTarget
target :: GatewayRouteTarget
rewrite :: Maybe GrpcGatewayRouteRewrite
$sel:target:GrpcGatewayRouteAction' :: GrpcGatewayRouteAction -> GatewayRouteTarget
$sel:rewrite:GrpcGatewayRouteAction' :: GrpcGatewayRouteAction -> Maybe GrpcGatewayRouteRewrite
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe GrpcGatewayRouteRewrite
rewrite
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GatewayRouteTarget
target

instance Prelude.NFData GrpcGatewayRouteAction where
  rnf :: GrpcGatewayRouteAction -> ()
rnf GrpcGatewayRouteAction' {Maybe GrpcGatewayRouteRewrite
GatewayRouteTarget
target :: GatewayRouteTarget
rewrite :: Maybe GrpcGatewayRouteRewrite
$sel:target:GrpcGatewayRouteAction' :: GrpcGatewayRouteAction -> GatewayRouteTarget
$sel:rewrite:GrpcGatewayRouteAction' :: GrpcGatewayRouteAction -> Maybe GrpcGatewayRouteRewrite
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe GrpcGatewayRouteRewrite
rewrite
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf GatewayRouteTarget
target

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"rewrite" 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 GrpcGatewayRouteRewrite
rewrite,
            forall a. a -> Maybe a
Prelude.Just (Key
"target" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= GatewayRouteTarget
target)
          ]
      )