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

import Amazonka.AppMesh.Types.GatewayRouteTarget
import Amazonka.AppMesh.Types.HttpGatewayRouteRewrite
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:/ 'newHttpGatewayRouteAction' smart constructor.
data HttpGatewayRouteAction = HttpGatewayRouteAction'
  { -- | The gateway route action to rewrite.
    HttpGatewayRouteAction -> Maybe HttpGatewayRouteRewrite
rewrite :: Prelude.Maybe HttpGatewayRouteRewrite,
    -- | An object that represents the target that traffic is routed to when a
    -- request matches the gateway route.
    HttpGatewayRouteAction -> GatewayRouteTarget
target :: GatewayRouteTarget
  }
  deriving (HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool
(HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool)
-> (HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool)
-> Eq HttpGatewayRouteAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool
$c/= :: HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool
== :: HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool
$c== :: HttpGatewayRouteAction -> HttpGatewayRouteAction -> Bool
Prelude.Eq, ReadPrec [HttpGatewayRouteAction]
ReadPrec HttpGatewayRouteAction
Int -> ReadS HttpGatewayRouteAction
ReadS [HttpGatewayRouteAction]
(Int -> ReadS HttpGatewayRouteAction)
-> ReadS [HttpGatewayRouteAction]
-> ReadPrec HttpGatewayRouteAction
-> ReadPrec [HttpGatewayRouteAction]
-> Read HttpGatewayRouteAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpGatewayRouteAction]
$creadListPrec :: ReadPrec [HttpGatewayRouteAction]
readPrec :: ReadPrec HttpGatewayRouteAction
$creadPrec :: ReadPrec HttpGatewayRouteAction
readList :: ReadS [HttpGatewayRouteAction]
$creadList :: ReadS [HttpGatewayRouteAction]
readsPrec :: Int -> ReadS HttpGatewayRouteAction
$creadsPrec :: Int -> ReadS HttpGatewayRouteAction
Prelude.Read, Int -> HttpGatewayRouteAction -> ShowS
[HttpGatewayRouteAction] -> ShowS
HttpGatewayRouteAction -> String
(Int -> HttpGatewayRouteAction -> ShowS)
-> (HttpGatewayRouteAction -> String)
-> ([HttpGatewayRouteAction] -> ShowS)
-> Show HttpGatewayRouteAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpGatewayRouteAction] -> ShowS
$cshowList :: [HttpGatewayRouteAction] -> ShowS
show :: HttpGatewayRouteAction -> String
$cshow :: HttpGatewayRouteAction -> String
showsPrec :: Int -> HttpGatewayRouteAction -> ShowS
$cshowsPrec :: Int -> HttpGatewayRouteAction -> ShowS
Prelude.Show, (forall x. HttpGatewayRouteAction -> Rep HttpGatewayRouteAction x)
-> (forall x.
    Rep HttpGatewayRouteAction x -> HttpGatewayRouteAction)
-> Generic HttpGatewayRouteAction
forall x. Rep HttpGatewayRouteAction x -> HttpGatewayRouteAction
forall x. HttpGatewayRouteAction -> Rep HttpGatewayRouteAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpGatewayRouteAction x -> HttpGatewayRouteAction
$cfrom :: forall x. HttpGatewayRouteAction -> Rep HttpGatewayRouteAction x
Prelude.Generic)

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

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

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

instance Core.FromJSON HttpGatewayRouteAction where
  parseJSON :: Value -> Parser HttpGatewayRouteAction
parseJSON =
    String
-> (Object -> Parser HttpGatewayRouteAction)
-> Value
-> Parser HttpGatewayRouteAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpGatewayRouteAction"
      ( \Object
x ->
          Maybe HttpGatewayRouteRewrite
-> GatewayRouteTarget -> HttpGatewayRouteAction
HttpGatewayRouteAction'
            (Maybe HttpGatewayRouteRewrite
 -> GatewayRouteTarget -> HttpGatewayRouteAction)
-> Parser (Maybe HttpGatewayRouteRewrite)
-> Parser (GatewayRouteTarget -> HttpGatewayRouteAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe HttpGatewayRouteRewrite)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"rewrite")
            Parser (GatewayRouteTarget -> HttpGatewayRouteAction)
-> Parser GatewayRouteTarget -> Parser HttpGatewayRouteAction
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 HttpGatewayRouteAction

instance Prelude.NFData HttpGatewayRouteAction

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