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

import Amazonka.AppMesh.Types.GrpcRouteMetadata
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 criteria for determining a request match.
--
-- /See:/ 'newGrpcRouteMatch' smart constructor.
data GrpcRouteMatch = GrpcRouteMatch'
  { -- | An object that represents the data to match from the request.
    GrpcRouteMatch -> Maybe (NonEmpty GrpcRouteMetadata)
metadata :: Prelude.Maybe (Prelude.NonEmpty GrpcRouteMetadata),
    -- | The method name to match from the request. If you specify a name, you
    -- must also specify a @serviceName@.
    GrpcRouteMatch -> Maybe Text
methodName :: Prelude.Maybe Prelude.Text,
    -- | The port number to match on.
    GrpcRouteMatch -> Maybe Natural
port :: Prelude.Maybe Prelude.Natural,
    -- | The fully qualified domain name for the service to match from the
    -- request.
    GrpcRouteMatch -> Maybe Text
serviceName :: Prelude.Maybe Prelude.Text
  }
  deriving (GrpcRouteMatch -> GrpcRouteMatch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GrpcRouteMatch -> GrpcRouteMatch -> Bool
$c/= :: GrpcRouteMatch -> GrpcRouteMatch -> Bool
== :: GrpcRouteMatch -> GrpcRouteMatch -> Bool
$c== :: GrpcRouteMatch -> GrpcRouteMatch -> Bool
Prelude.Eq, ReadPrec [GrpcRouteMatch]
ReadPrec GrpcRouteMatch
Int -> ReadS GrpcRouteMatch
ReadS [GrpcRouteMatch]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GrpcRouteMatch]
$creadListPrec :: ReadPrec [GrpcRouteMatch]
readPrec :: ReadPrec GrpcRouteMatch
$creadPrec :: ReadPrec GrpcRouteMatch
readList :: ReadS [GrpcRouteMatch]
$creadList :: ReadS [GrpcRouteMatch]
readsPrec :: Int -> ReadS GrpcRouteMatch
$creadsPrec :: Int -> ReadS GrpcRouteMatch
Prelude.Read, Int -> GrpcRouteMatch -> ShowS
[GrpcRouteMatch] -> ShowS
GrpcRouteMatch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GrpcRouteMatch] -> ShowS
$cshowList :: [GrpcRouteMatch] -> ShowS
show :: GrpcRouteMatch -> String
$cshow :: GrpcRouteMatch -> String
showsPrec :: Int -> GrpcRouteMatch -> ShowS
$cshowsPrec :: Int -> GrpcRouteMatch -> ShowS
Prelude.Show, forall x. Rep GrpcRouteMatch x -> GrpcRouteMatch
forall x. GrpcRouteMatch -> Rep GrpcRouteMatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GrpcRouteMatch x -> GrpcRouteMatch
$cfrom :: forall x. GrpcRouteMatch -> Rep GrpcRouteMatch x
Prelude.Generic)

-- |
-- Create a value of 'GrpcRouteMatch' 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:
--
-- 'metadata', 'grpcRouteMatch_metadata' - An object that represents the data to match from the request.
--
-- 'methodName', 'grpcRouteMatch_methodName' - The method name to match from the request. If you specify a name, you
-- must also specify a @serviceName@.
--
-- 'port', 'grpcRouteMatch_port' - The port number to match on.
--
-- 'serviceName', 'grpcRouteMatch_serviceName' - The fully qualified domain name for the service to match from the
-- request.
newGrpcRouteMatch ::
  GrpcRouteMatch
newGrpcRouteMatch :: GrpcRouteMatch
newGrpcRouteMatch =
  GrpcRouteMatch'
    { $sel:metadata:GrpcRouteMatch' :: Maybe (NonEmpty GrpcRouteMetadata)
metadata = forall a. Maybe a
Prelude.Nothing,
      $sel:methodName:GrpcRouteMatch' :: Maybe Text
methodName = forall a. Maybe a
Prelude.Nothing,
      $sel:port:GrpcRouteMatch' :: Maybe Natural
port = forall a. Maybe a
Prelude.Nothing,
      $sel:serviceName:GrpcRouteMatch' :: Maybe Text
serviceName = forall a. Maybe a
Prelude.Nothing
    }

-- | An object that represents the data to match from the request.
grpcRouteMatch_metadata :: Lens.Lens' GrpcRouteMatch (Prelude.Maybe (Prelude.NonEmpty GrpcRouteMetadata))
grpcRouteMatch_metadata :: Lens' GrpcRouteMatch (Maybe (NonEmpty GrpcRouteMetadata))
grpcRouteMatch_metadata = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMatch' {Maybe (NonEmpty GrpcRouteMetadata)
metadata :: Maybe (NonEmpty GrpcRouteMetadata)
$sel:metadata:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe (NonEmpty GrpcRouteMetadata)
metadata} -> Maybe (NonEmpty GrpcRouteMetadata)
metadata) (\s :: GrpcRouteMatch
s@GrpcRouteMatch' {} Maybe (NonEmpty GrpcRouteMetadata)
a -> GrpcRouteMatch
s {$sel:metadata:GrpcRouteMatch' :: Maybe (NonEmpty GrpcRouteMetadata)
metadata = Maybe (NonEmpty GrpcRouteMetadata)
a} :: GrpcRouteMatch) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The method name to match from the request. If you specify a name, you
-- must also specify a @serviceName@.
grpcRouteMatch_methodName :: Lens.Lens' GrpcRouteMatch (Prelude.Maybe Prelude.Text)
grpcRouteMatch_methodName :: Lens' GrpcRouteMatch (Maybe Text)
grpcRouteMatch_methodName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMatch' {Maybe Text
methodName :: Maybe Text
$sel:methodName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
methodName} -> Maybe Text
methodName) (\s :: GrpcRouteMatch
s@GrpcRouteMatch' {} Maybe Text
a -> GrpcRouteMatch
s {$sel:methodName:GrpcRouteMatch' :: Maybe Text
methodName = Maybe Text
a} :: GrpcRouteMatch)

-- | The port number to match on.
grpcRouteMatch_port :: Lens.Lens' GrpcRouteMatch (Prelude.Maybe Prelude.Natural)
grpcRouteMatch_port :: Lens' GrpcRouteMatch (Maybe Natural)
grpcRouteMatch_port = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMatch' {Maybe Natural
port :: Maybe Natural
$sel:port:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Natural
port} -> Maybe Natural
port) (\s :: GrpcRouteMatch
s@GrpcRouteMatch' {} Maybe Natural
a -> GrpcRouteMatch
s {$sel:port:GrpcRouteMatch' :: Maybe Natural
port = Maybe Natural
a} :: GrpcRouteMatch)

-- | The fully qualified domain name for the service to match from the
-- request.
grpcRouteMatch_serviceName :: Lens.Lens' GrpcRouteMatch (Prelude.Maybe Prelude.Text)
grpcRouteMatch_serviceName :: Lens' GrpcRouteMatch (Maybe Text)
grpcRouteMatch_serviceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GrpcRouteMatch' {Maybe Text
serviceName :: Maybe Text
$sel:serviceName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
serviceName} -> Maybe Text
serviceName) (\s :: GrpcRouteMatch
s@GrpcRouteMatch' {} Maybe Text
a -> GrpcRouteMatch
s {$sel:serviceName:GrpcRouteMatch' :: Maybe Text
serviceName = Maybe Text
a} :: GrpcRouteMatch)

instance Data.FromJSON GrpcRouteMatch where
  parseJSON :: Value -> Parser GrpcRouteMatch
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"GrpcRouteMatch"
      ( \Object
x ->
          Maybe (NonEmpty GrpcRouteMetadata)
-> Maybe Text -> Maybe Natural -> Maybe Text -> GrpcRouteMatch
GrpcRouteMatch'
            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
"metadata")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"methodName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"port")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"serviceName")
      )

instance Prelude.Hashable GrpcRouteMatch where
  hashWithSalt :: Int -> GrpcRouteMatch -> Int
hashWithSalt Int
_salt GrpcRouteMatch' {Maybe Natural
Maybe (NonEmpty GrpcRouteMetadata)
Maybe Text
serviceName :: Maybe Text
port :: Maybe Natural
methodName :: Maybe Text
metadata :: Maybe (NonEmpty GrpcRouteMetadata)
$sel:serviceName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
$sel:port:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Natural
$sel:methodName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
$sel:metadata:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe (NonEmpty GrpcRouteMetadata)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty GrpcRouteMetadata)
metadata
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
methodName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
port
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
serviceName

instance Prelude.NFData GrpcRouteMatch where
  rnf :: GrpcRouteMatch -> ()
rnf GrpcRouteMatch' {Maybe Natural
Maybe (NonEmpty GrpcRouteMetadata)
Maybe Text
serviceName :: Maybe Text
port :: Maybe Natural
methodName :: Maybe Text
metadata :: Maybe (NonEmpty GrpcRouteMetadata)
$sel:serviceName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
$sel:port:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Natural
$sel:methodName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
$sel:metadata:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe (NonEmpty GrpcRouteMetadata)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty GrpcRouteMetadata)
metadata
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
methodName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
port
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
serviceName

instance Data.ToJSON GrpcRouteMatch where
  toJSON :: GrpcRouteMatch -> Value
toJSON GrpcRouteMatch' {Maybe Natural
Maybe (NonEmpty GrpcRouteMetadata)
Maybe Text
serviceName :: Maybe Text
port :: Maybe Natural
methodName :: Maybe Text
metadata :: Maybe (NonEmpty GrpcRouteMetadata)
$sel:serviceName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
$sel:port:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Natural
$sel:methodName:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe Text
$sel:metadata:GrpcRouteMatch' :: GrpcRouteMatch -> Maybe (NonEmpty GrpcRouteMetadata)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"metadata" 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 (NonEmpty GrpcRouteMetadata)
metadata,
            (Key
"methodName" 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 Text
methodName,
            (Key
"port" 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 Natural
port,
            (Key
"serviceName" 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 Text
serviceName
          ]
      )