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

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

-- |
-- Create a value of 'GrpcGatewayRoute' 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', 'grpcGatewayRoute_action' - An object that represents the action to take if a match is determined.
--
-- 'match', 'grpcGatewayRoute_match' - An object that represents the criteria for determining a request match.
newGrpcGatewayRoute ::
  -- | 'action'
  GrpcGatewayRouteAction ->
  -- | 'match'
  GrpcGatewayRouteMatch ->
  GrpcGatewayRoute
newGrpcGatewayRoute :: GrpcGatewayRouteAction -> GrpcGatewayRouteMatch -> GrpcGatewayRoute
newGrpcGatewayRoute GrpcGatewayRouteAction
pAction_ GrpcGatewayRouteMatch
pMatch_ =
  GrpcGatewayRoute'
    { $sel:action:GrpcGatewayRoute' :: GrpcGatewayRouteAction
action = GrpcGatewayRouteAction
pAction_,
      $sel:match:GrpcGatewayRoute' :: GrpcGatewayRouteMatch
match = GrpcGatewayRouteMatch
pMatch_
    }

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

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

instance Data.FromJSON GrpcGatewayRoute where
  parseJSON :: Value -> Parser GrpcGatewayRoute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"GrpcGatewayRoute"
      ( \Object
x ->
          GrpcGatewayRouteAction -> GrpcGatewayRouteMatch -> GrpcGatewayRoute
GrpcGatewayRoute'
            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 GrpcGatewayRoute where
  hashWithSalt :: Int -> GrpcGatewayRoute -> Int
hashWithSalt Int
_salt GrpcGatewayRoute' {GrpcGatewayRouteAction
GrpcGatewayRouteMatch
match :: GrpcGatewayRouteMatch
action :: GrpcGatewayRouteAction
$sel:match:GrpcGatewayRoute' :: GrpcGatewayRoute -> GrpcGatewayRouteMatch
$sel:action:GrpcGatewayRoute' :: GrpcGatewayRoute -> GrpcGatewayRouteAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GrpcGatewayRouteAction
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GrpcGatewayRouteMatch
match

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

instance Data.ToJSON GrpcGatewayRoute where
  toJSON :: GrpcGatewayRoute -> Value
toJSON GrpcGatewayRoute' {GrpcGatewayRouteAction
GrpcGatewayRouteMatch
match :: GrpcGatewayRouteMatch
action :: GrpcGatewayRouteAction
$sel:match:GrpcGatewayRoute' :: GrpcGatewayRoute -> GrpcGatewayRouteMatch
$sel:action:GrpcGatewayRoute' :: GrpcGatewayRoute -> GrpcGatewayRouteAction
..} =
    [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..= GrpcGatewayRouteAction
action),
            forall a. a -> Maybe a
Prelude.Just (Key
"match" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= GrpcGatewayRouteMatch
match)
          ]
      )