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

import Amazonka.AppMesh.Types.GrpcRouteMetadataMatchMethod
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the match metadata for the route.
--
-- /See:/ 'newGrpcRouteMetadata' smart constructor.
data GrpcRouteMetadata = GrpcRouteMetadata'
  { -- | Specify @True@ to match anything except the match criteria. The default
    -- value is @False@.
    GrpcRouteMetadata -> Maybe Bool
invert :: Prelude.Maybe Prelude.Bool,
    -- | An object that represents the data to match from the request.
    GrpcRouteMetadata -> Maybe GrpcRouteMetadataMatchMethod
match :: Prelude.Maybe GrpcRouteMetadataMatchMethod,
    -- | The name of the route.
    GrpcRouteMetadata -> Text
name :: Prelude.Text
  }
  deriving (GrpcRouteMetadata -> GrpcRouteMetadata -> Bool
(GrpcRouteMetadata -> GrpcRouteMetadata -> Bool)
-> (GrpcRouteMetadata -> GrpcRouteMetadata -> Bool)
-> Eq GrpcRouteMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrpcRouteMetadata -> GrpcRouteMetadata -> Bool
$c/= :: GrpcRouteMetadata -> GrpcRouteMetadata -> Bool
== :: GrpcRouteMetadata -> GrpcRouteMetadata -> Bool
$c== :: GrpcRouteMetadata -> GrpcRouteMetadata -> Bool
Prelude.Eq, ReadPrec [GrpcRouteMetadata]
ReadPrec GrpcRouteMetadata
Int -> ReadS GrpcRouteMetadata
ReadS [GrpcRouteMetadata]
(Int -> ReadS GrpcRouteMetadata)
-> ReadS [GrpcRouteMetadata]
-> ReadPrec GrpcRouteMetadata
-> ReadPrec [GrpcRouteMetadata]
-> Read GrpcRouteMetadata
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrpcRouteMetadata]
$creadListPrec :: ReadPrec [GrpcRouteMetadata]
readPrec :: ReadPrec GrpcRouteMetadata
$creadPrec :: ReadPrec GrpcRouteMetadata
readList :: ReadS [GrpcRouteMetadata]
$creadList :: ReadS [GrpcRouteMetadata]
readsPrec :: Int -> ReadS GrpcRouteMetadata
$creadsPrec :: Int -> ReadS GrpcRouteMetadata
Prelude.Read, Int -> GrpcRouteMetadata -> ShowS
[GrpcRouteMetadata] -> ShowS
GrpcRouteMetadata -> String
(Int -> GrpcRouteMetadata -> ShowS)
-> (GrpcRouteMetadata -> String)
-> ([GrpcRouteMetadata] -> ShowS)
-> Show GrpcRouteMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrpcRouteMetadata] -> ShowS
$cshowList :: [GrpcRouteMetadata] -> ShowS
show :: GrpcRouteMetadata -> String
$cshow :: GrpcRouteMetadata -> String
showsPrec :: Int -> GrpcRouteMetadata -> ShowS
$cshowsPrec :: Int -> GrpcRouteMetadata -> ShowS
Prelude.Show, (forall x. GrpcRouteMetadata -> Rep GrpcRouteMetadata x)
-> (forall x. Rep GrpcRouteMetadata x -> GrpcRouteMetadata)
-> Generic GrpcRouteMetadata
forall x. Rep GrpcRouteMetadata x -> GrpcRouteMetadata
forall x. GrpcRouteMetadata -> Rep GrpcRouteMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrpcRouteMetadata x -> GrpcRouteMetadata
$cfrom :: forall x. GrpcRouteMetadata -> Rep GrpcRouteMetadata x
Prelude.Generic)

-- |
-- Create a value of 'GrpcRouteMetadata' 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:
--
-- 'invert', 'grpcRouteMetadata_invert' - Specify @True@ to match anything except the match criteria. The default
-- value is @False@.
--
-- 'match', 'grpcRouteMetadata_match' - An object that represents the data to match from the request.
--
-- 'name', 'grpcRouteMetadata_name' - The name of the route.
newGrpcRouteMetadata ::
  -- | 'name'
  Prelude.Text ->
  GrpcRouteMetadata
newGrpcRouteMetadata :: Text -> GrpcRouteMetadata
newGrpcRouteMetadata Text
pName_ =
  GrpcRouteMetadata' :: Maybe Bool
-> Maybe GrpcRouteMetadataMatchMethod -> Text -> GrpcRouteMetadata
GrpcRouteMetadata'
    { $sel:invert:GrpcRouteMetadata' :: Maybe Bool
invert = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:match:GrpcRouteMetadata' :: Maybe GrpcRouteMetadataMatchMethod
match = Maybe GrpcRouteMetadataMatchMethod
forall a. Maybe a
Prelude.Nothing,
      $sel:name:GrpcRouteMetadata' :: Text
name = Text
pName_
    }

-- | Specify @True@ to match anything except the match criteria. The default
-- value is @False@.
grpcRouteMetadata_invert :: Lens.Lens' GrpcRouteMetadata (Prelude.Maybe Prelude.Bool)
grpcRouteMetadata_invert :: (Maybe Bool -> f (Maybe Bool))
-> GrpcRouteMetadata -> f GrpcRouteMetadata
grpcRouteMetadata_invert = (GrpcRouteMetadata -> Maybe Bool)
-> (GrpcRouteMetadata -> Maybe Bool -> GrpcRouteMetadata)
-> Lens
     GrpcRouteMetadata GrpcRouteMetadata (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMetadata' {Maybe Bool
invert :: Maybe Bool
$sel:invert:GrpcRouteMetadata' :: GrpcRouteMetadata -> Maybe Bool
invert} -> Maybe Bool
invert) (\s :: GrpcRouteMetadata
s@GrpcRouteMetadata' {} Maybe Bool
a -> GrpcRouteMetadata
s {$sel:invert:GrpcRouteMetadata' :: Maybe Bool
invert = Maybe Bool
a} :: GrpcRouteMetadata)

-- | An object that represents the data to match from the request.
grpcRouteMetadata_match :: Lens.Lens' GrpcRouteMetadata (Prelude.Maybe GrpcRouteMetadataMatchMethod)
grpcRouteMetadata_match :: (Maybe GrpcRouteMetadataMatchMethod
 -> f (Maybe GrpcRouteMetadataMatchMethod))
-> GrpcRouteMetadata -> f GrpcRouteMetadata
grpcRouteMetadata_match = (GrpcRouteMetadata -> Maybe GrpcRouteMetadataMatchMethod)
-> (GrpcRouteMetadata
    -> Maybe GrpcRouteMetadataMatchMethod -> GrpcRouteMetadata)
-> Lens
     GrpcRouteMetadata
     GrpcRouteMetadata
     (Maybe GrpcRouteMetadataMatchMethod)
     (Maybe GrpcRouteMetadataMatchMethod)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMetadata' {Maybe GrpcRouteMetadataMatchMethod
match :: Maybe GrpcRouteMetadataMatchMethod
$sel:match:GrpcRouteMetadata' :: GrpcRouteMetadata -> Maybe GrpcRouteMetadataMatchMethod
match} -> Maybe GrpcRouteMetadataMatchMethod
match) (\s :: GrpcRouteMetadata
s@GrpcRouteMetadata' {} Maybe GrpcRouteMetadataMatchMethod
a -> GrpcRouteMetadata
s {$sel:match:GrpcRouteMetadata' :: Maybe GrpcRouteMetadataMatchMethod
match = Maybe GrpcRouteMetadataMatchMethod
a} :: GrpcRouteMetadata)

-- | The name of the route.
grpcRouteMetadata_name :: Lens.Lens' GrpcRouteMetadata Prelude.Text
grpcRouteMetadata_name :: (Text -> f Text) -> GrpcRouteMetadata -> f GrpcRouteMetadata
grpcRouteMetadata_name = (GrpcRouteMetadata -> Text)
-> (GrpcRouteMetadata -> Text -> GrpcRouteMetadata)
-> Lens GrpcRouteMetadata GrpcRouteMetadata Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMetadata' {Text
name :: Text
$sel:name:GrpcRouteMetadata' :: GrpcRouteMetadata -> Text
name} -> Text
name) (\s :: GrpcRouteMetadata
s@GrpcRouteMetadata' {} Text
a -> GrpcRouteMetadata
s {$sel:name:GrpcRouteMetadata' :: Text
name = Text
a} :: GrpcRouteMetadata)

instance Core.FromJSON GrpcRouteMetadata where
  parseJSON :: Value -> Parser GrpcRouteMetadata
parseJSON =
    String
-> (Object -> Parser GrpcRouteMetadata)
-> Value
-> Parser GrpcRouteMetadata
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GrpcRouteMetadata"
      ( \Object
x ->
          Maybe Bool
-> Maybe GrpcRouteMetadataMatchMethod -> Text -> GrpcRouteMetadata
GrpcRouteMetadata'
            (Maybe Bool
 -> Maybe GrpcRouteMetadataMatchMethod -> Text -> GrpcRouteMetadata)
-> Parser (Maybe Bool)
-> Parser
     (Maybe GrpcRouteMetadataMatchMethod -> Text -> GrpcRouteMetadata)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"invert")
            Parser
  (Maybe GrpcRouteMetadataMatchMethod -> Text -> GrpcRouteMetadata)
-> Parser (Maybe GrpcRouteMetadataMatchMethod)
-> Parser (Text -> GrpcRouteMetadata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GrpcRouteMetadataMatchMethod)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"match")
            Parser (Text -> GrpcRouteMetadata)
-> Parser Text -> Parser GrpcRouteMetadata
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
      )

instance Prelude.Hashable GrpcRouteMetadata

instance Prelude.NFData GrpcRouteMetadata

instance Core.ToJSON GrpcRouteMetadata where
  toJSON :: GrpcRouteMetadata -> Value
toJSON GrpcRouteMetadata' {Maybe Bool
Maybe GrpcRouteMetadataMatchMethod
Text
name :: Text
match :: Maybe GrpcRouteMetadataMatchMethod
invert :: Maybe Bool
$sel:name:GrpcRouteMetadata' :: GrpcRouteMetadata -> Text
$sel:match:GrpcRouteMetadata' :: GrpcRouteMetadata -> Maybe GrpcRouteMetadataMatchMethod
$sel:invert:GrpcRouteMetadata' :: GrpcRouteMetadata -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"invert" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
invert,
            (Text
"match" Text -> GrpcRouteMetadataMatchMethod -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (GrpcRouteMetadataMatchMethod -> Pair)
-> Maybe GrpcRouteMetadataMatchMethod -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe GrpcRouteMetadataMatchMethod
match,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )