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

import Amazonka.AppMesh.Types.HttpGatewayRouteAction
import Amazonka.AppMesh.Types.HttpGatewayRouteMatch
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 an HTTP gateway route.
--
-- /See:/ 'newHttpGatewayRoute' smart constructor.
data HttpGatewayRoute = HttpGatewayRoute'
  { -- | An object that represents the action to take if a match is determined.
    HttpGatewayRoute -> HttpGatewayRouteAction
action :: HttpGatewayRouteAction,
    -- | An object that represents the criteria for determining a request match.
    HttpGatewayRoute -> HttpGatewayRouteMatch
match :: HttpGatewayRouteMatch
  }
  deriving (HttpGatewayRoute -> HttpGatewayRoute -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpGatewayRoute -> HttpGatewayRoute -> Bool
$c/= :: HttpGatewayRoute -> HttpGatewayRoute -> Bool
== :: HttpGatewayRoute -> HttpGatewayRoute -> Bool
$c== :: HttpGatewayRoute -> HttpGatewayRoute -> Bool
Prelude.Eq, ReadPrec [HttpGatewayRoute]
ReadPrec HttpGatewayRoute
Int -> ReadS HttpGatewayRoute
ReadS [HttpGatewayRoute]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpGatewayRoute]
$creadListPrec :: ReadPrec [HttpGatewayRoute]
readPrec :: ReadPrec HttpGatewayRoute
$creadPrec :: ReadPrec HttpGatewayRoute
readList :: ReadS [HttpGatewayRoute]
$creadList :: ReadS [HttpGatewayRoute]
readsPrec :: Int -> ReadS HttpGatewayRoute
$creadsPrec :: Int -> ReadS HttpGatewayRoute
Prelude.Read, Int -> HttpGatewayRoute -> ShowS
[HttpGatewayRoute] -> ShowS
HttpGatewayRoute -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpGatewayRoute] -> ShowS
$cshowList :: [HttpGatewayRoute] -> ShowS
show :: HttpGatewayRoute -> String
$cshow :: HttpGatewayRoute -> String
showsPrec :: Int -> HttpGatewayRoute -> ShowS
$cshowsPrec :: Int -> HttpGatewayRoute -> ShowS
Prelude.Show, forall x. Rep HttpGatewayRoute x -> HttpGatewayRoute
forall x. HttpGatewayRoute -> Rep HttpGatewayRoute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpGatewayRoute x -> HttpGatewayRoute
$cfrom :: forall x. HttpGatewayRoute -> Rep HttpGatewayRoute x
Prelude.Generic)

-- |
-- Create a value of 'HttpGatewayRoute' 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:
--
-- 'action', 'httpGatewayRoute_action' - An object that represents the action to take if a match is determined.
--
-- 'match', 'httpGatewayRoute_match' - An object that represents the criteria for determining a request match.
newHttpGatewayRoute ::
  -- | 'action'
  HttpGatewayRouteAction ->
  -- | 'match'
  HttpGatewayRouteMatch ->
  HttpGatewayRoute
newHttpGatewayRoute :: HttpGatewayRouteAction -> HttpGatewayRouteMatch -> HttpGatewayRoute
newHttpGatewayRoute HttpGatewayRouteAction
pAction_ HttpGatewayRouteMatch
pMatch_ =
  HttpGatewayRoute'
    { $sel:action:HttpGatewayRoute' :: HttpGatewayRouteAction
action = HttpGatewayRouteAction
pAction_,
      $sel:match:HttpGatewayRoute' :: HttpGatewayRouteMatch
match = HttpGatewayRouteMatch
pMatch_
    }

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

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

instance Data.FromJSON HttpGatewayRoute where
  parseJSON :: Value -> Parser HttpGatewayRoute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HttpGatewayRoute"
      ( \Object
x ->
          HttpGatewayRouteAction -> HttpGatewayRouteMatch -> HttpGatewayRoute
HttpGatewayRoute'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"action")
            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
"match")
      )

instance Prelude.Hashable HttpGatewayRoute where
  hashWithSalt :: Int -> HttpGatewayRoute -> Int
hashWithSalt Int
_salt HttpGatewayRoute' {HttpGatewayRouteAction
HttpGatewayRouteMatch
match :: HttpGatewayRouteMatch
action :: HttpGatewayRouteAction
$sel:match:HttpGatewayRoute' :: HttpGatewayRoute -> HttpGatewayRouteMatch
$sel:action:HttpGatewayRoute' :: HttpGatewayRoute -> HttpGatewayRouteAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HttpGatewayRouteAction
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HttpGatewayRouteMatch
match

instance Prelude.NFData HttpGatewayRoute where
  rnf :: HttpGatewayRoute -> ()
rnf HttpGatewayRoute' {HttpGatewayRouteAction
HttpGatewayRouteMatch
match :: HttpGatewayRouteMatch
action :: HttpGatewayRouteAction
$sel:match:HttpGatewayRoute' :: HttpGatewayRoute -> HttpGatewayRouteMatch
$sel:action:HttpGatewayRoute' :: HttpGatewayRoute -> HttpGatewayRouteAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf HttpGatewayRouteAction
action seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HttpGatewayRouteMatch
match

instance Data.ToJSON HttpGatewayRoute where
  toJSON :: HttpGatewayRoute -> Value
toJSON HttpGatewayRoute' {HttpGatewayRouteAction
HttpGatewayRouteMatch
match :: HttpGatewayRouteMatch
action :: HttpGatewayRouteAction
$sel:match:HttpGatewayRoute' :: HttpGatewayRoute -> HttpGatewayRouteMatch
$sel:action:HttpGatewayRoute' :: HttpGatewayRoute -> HttpGatewayRouteAction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"action" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HttpGatewayRouteAction
action),
            forall a. a -> Maybe a
Prelude.Just (Key
"match" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HttpGatewayRouteMatch
match)
          ]
      )