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

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 representing the path to match in the request.
--
-- /See:/ 'newHttpPathMatch' smart constructor.
data HttpPathMatch = HttpPathMatch'
  { -- | The exact path to match on.
    HttpPathMatch -> Maybe Text
exact :: Prelude.Maybe Prelude.Text,
    -- | The regex used to match the path.
    HttpPathMatch -> Maybe Text
regex :: Prelude.Maybe Prelude.Text
  }
  deriving (HttpPathMatch -> HttpPathMatch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpPathMatch -> HttpPathMatch -> Bool
$c/= :: HttpPathMatch -> HttpPathMatch -> Bool
== :: HttpPathMatch -> HttpPathMatch -> Bool
$c== :: HttpPathMatch -> HttpPathMatch -> Bool
Prelude.Eq, ReadPrec [HttpPathMatch]
ReadPrec HttpPathMatch
Int -> ReadS HttpPathMatch
ReadS [HttpPathMatch]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpPathMatch]
$creadListPrec :: ReadPrec [HttpPathMatch]
readPrec :: ReadPrec HttpPathMatch
$creadPrec :: ReadPrec HttpPathMatch
readList :: ReadS [HttpPathMatch]
$creadList :: ReadS [HttpPathMatch]
readsPrec :: Int -> ReadS HttpPathMatch
$creadsPrec :: Int -> ReadS HttpPathMatch
Prelude.Read, Int -> HttpPathMatch -> ShowS
[HttpPathMatch] -> ShowS
HttpPathMatch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpPathMatch] -> ShowS
$cshowList :: [HttpPathMatch] -> ShowS
show :: HttpPathMatch -> String
$cshow :: HttpPathMatch -> String
showsPrec :: Int -> HttpPathMatch -> ShowS
$cshowsPrec :: Int -> HttpPathMatch -> ShowS
Prelude.Show, forall x. Rep HttpPathMatch x -> HttpPathMatch
forall x. HttpPathMatch -> Rep HttpPathMatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpPathMatch x -> HttpPathMatch
$cfrom :: forall x. HttpPathMatch -> Rep HttpPathMatch x
Prelude.Generic)

-- |
-- Create a value of 'HttpPathMatch' 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:
--
-- 'exact', 'httpPathMatch_exact' - The exact path to match on.
--
-- 'regex', 'httpPathMatch_regex' - The regex used to match the path.
newHttpPathMatch ::
  HttpPathMatch
newHttpPathMatch :: HttpPathMatch
newHttpPathMatch =
  HttpPathMatch'
    { $sel:exact:HttpPathMatch' :: Maybe Text
exact = forall a. Maybe a
Prelude.Nothing,
      $sel:regex:HttpPathMatch' :: Maybe Text
regex = forall a. Maybe a
Prelude.Nothing
    }

-- | The exact path to match on.
httpPathMatch_exact :: Lens.Lens' HttpPathMatch (Prelude.Maybe Prelude.Text)
httpPathMatch_exact :: Lens' HttpPathMatch (Maybe Text)
httpPathMatch_exact = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpPathMatch' {Maybe Text
exact :: Maybe Text
$sel:exact:HttpPathMatch' :: HttpPathMatch -> Maybe Text
exact} -> Maybe Text
exact) (\s :: HttpPathMatch
s@HttpPathMatch' {} Maybe Text
a -> HttpPathMatch
s {$sel:exact:HttpPathMatch' :: Maybe Text
exact = Maybe Text
a} :: HttpPathMatch)

-- | The regex used to match the path.
httpPathMatch_regex :: Lens.Lens' HttpPathMatch (Prelude.Maybe Prelude.Text)
httpPathMatch_regex :: Lens' HttpPathMatch (Maybe Text)
httpPathMatch_regex = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpPathMatch' {Maybe Text
regex :: Maybe Text
$sel:regex:HttpPathMatch' :: HttpPathMatch -> Maybe Text
regex} -> Maybe Text
regex) (\s :: HttpPathMatch
s@HttpPathMatch' {} Maybe Text
a -> HttpPathMatch
s {$sel:regex:HttpPathMatch' :: Maybe Text
regex = Maybe Text
a} :: HttpPathMatch)

instance Data.FromJSON HttpPathMatch where
  parseJSON :: Value -> Parser HttpPathMatch
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HttpPathMatch"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> HttpPathMatch
HttpPathMatch'
            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
"exact")
            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
"regex")
      )

instance Prelude.Hashable HttpPathMatch where
  hashWithSalt :: Int -> HttpPathMatch -> Int
hashWithSalt Int
_salt HttpPathMatch' {Maybe Text
regex :: Maybe Text
exact :: Maybe Text
$sel:regex:HttpPathMatch' :: HttpPathMatch -> Maybe Text
$sel:exact:HttpPathMatch' :: HttpPathMatch -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
exact
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
regex

instance Prelude.NFData HttpPathMatch where
  rnf :: HttpPathMatch -> ()
rnf HttpPathMatch' {Maybe Text
regex :: Maybe Text
exact :: Maybe Text
$sel:regex:HttpPathMatch' :: HttpPathMatch -> Maybe Text
$sel:exact:HttpPathMatch' :: HttpPathMatch -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
exact seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
regex

instance Data.ToJSON HttpPathMatch where
  toJSON :: HttpPathMatch -> Value
toJSON HttpPathMatch' {Maybe Text
regex :: Maybe Text
exact :: Maybe Text
$sel:regex:HttpPathMatch' :: HttpPathMatch -> Maybe Text
$sel:exact:HttpPathMatch' :: HttpPathMatch -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"exact" 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
exact,
            (Key
"regex" 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
regex
          ]
      )