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

import Amazonka.AppMesh.Types.GatewayRouteTarget
import Amazonka.AppMesh.Types.HttpGatewayRouteRewrite
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:/ '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
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]
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
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. 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'
    { $sel:rewrite:HttpGatewayRouteAction' :: Maybe HttpGatewayRouteRewrite
rewrite = 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 :: Lens' HttpGatewayRouteAction (Maybe HttpGatewayRouteRewrite)
httpGatewayRouteAction_rewrite = 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 :: Lens' HttpGatewayRouteAction GatewayRouteTarget
httpGatewayRouteAction_target = 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 Data.FromJSON HttpGatewayRouteAction where
  parseJSON :: Value -> Parser HttpGatewayRouteAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HttpGatewayRouteAction"
      ( \Object
x ->
          Maybe HttpGatewayRouteRewrite
-> GatewayRouteTarget -> HttpGatewayRouteAction
HttpGatewayRouteAction'
            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 HttpGatewayRouteAction where
  hashWithSalt :: Int -> HttpGatewayRouteAction -> Int
hashWithSalt Int
_salt HttpGatewayRouteAction' {Maybe HttpGatewayRouteRewrite
GatewayRouteTarget
target :: GatewayRouteTarget
rewrite :: Maybe HttpGatewayRouteRewrite
$sel:target:HttpGatewayRouteAction' :: HttpGatewayRouteAction -> GatewayRouteTarget
$sel:rewrite:HttpGatewayRouteAction' :: HttpGatewayRouteAction -> Maybe HttpGatewayRouteRewrite
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe HttpGatewayRouteRewrite
rewrite
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GatewayRouteTarget
target

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

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