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

import Amazonka.AppMesh.Types.HttpGatewayRouteAction
import Amazonka.AppMesh.Types.HttpGatewayRouteMatch
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(HttpGatewayRoute -> HttpGatewayRoute -> Bool)
-> (HttpGatewayRoute -> HttpGatewayRoute -> Bool)
-> Eq HttpGatewayRoute
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]
(Int -> ReadS HttpGatewayRoute)
-> ReadS [HttpGatewayRoute]
-> ReadPrec HttpGatewayRoute
-> ReadPrec [HttpGatewayRoute]
-> Read 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
(Int -> HttpGatewayRoute -> ShowS)
-> (HttpGatewayRoute -> String)
-> ([HttpGatewayRoute] -> ShowS)
-> Show HttpGatewayRoute
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. HttpGatewayRoute -> Rep HttpGatewayRoute x)
-> (forall x. Rep HttpGatewayRoute x -> HttpGatewayRoute)
-> Generic HttpGatewayRoute
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' :: HttpGatewayRouteAction -> HttpGatewayRouteMatch -> HttpGatewayRoute
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 :: (HttpGatewayRouteAction -> f HttpGatewayRouteAction)
-> HttpGatewayRoute -> f HttpGatewayRoute
httpGatewayRoute_action = (HttpGatewayRoute -> HttpGatewayRouteAction)
-> (HttpGatewayRoute -> HttpGatewayRouteAction -> HttpGatewayRoute)
-> Lens
     HttpGatewayRoute
     HttpGatewayRoute
     HttpGatewayRouteAction
     HttpGatewayRouteAction
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 :: (HttpGatewayRouteMatch -> f HttpGatewayRouteMatch)
-> HttpGatewayRoute -> f HttpGatewayRoute
httpGatewayRoute_match = (HttpGatewayRoute -> HttpGatewayRouteMatch)
-> (HttpGatewayRoute -> HttpGatewayRouteMatch -> HttpGatewayRoute)
-> Lens
     HttpGatewayRoute
     HttpGatewayRoute
     HttpGatewayRouteMatch
     HttpGatewayRouteMatch
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 Core.FromJSON HttpGatewayRoute where
  parseJSON :: Value -> Parser HttpGatewayRoute
parseJSON =
    String
-> (Object -> Parser HttpGatewayRoute)
-> Value
-> Parser HttpGatewayRoute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpGatewayRoute"
      ( \Object
x ->
          HttpGatewayRouteAction -> HttpGatewayRouteMatch -> HttpGatewayRoute
HttpGatewayRoute'
            (HttpGatewayRouteAction
 -> HttpGatewayRouteMatch -> HttpGatewayRoute)
-> Parser HttpGatewayRouteAction
-> Parser (HttpGatewayRouteMatch -> HttpGatewayRoute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser HttpGatewayRouteAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"action") Parser (HttpGatewayRouteMatch -> HttpGatewayRoute)
-> Parser HttpGatewayRouteMatch -> Parser HttpGatewayRoute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser HttpGatewayRouteMatch
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"match")
      )

instance Prelude.Hashable HttpGatewayRoute

instance Prelude.NFData HttpGatewayRoute

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> HttpGatewayRouteAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HttpGatewayRouteAction
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"match" Text -> HttpGatewayRouteMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HttpGatewayRouteMatch
match)
          ]
      )