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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object representing the path to match in the request.
--
-- /See:/ 'newHttpPathMatch' smart constructor.
data HttpPathMatch = HttpPathMatch'
  { -- | The regex used to match the path.
    HttpPathMatch -> Maybe Text
regex :: Prelude.Maybe Prelude.Text,
    -- | The exact path to match on.
    HttpPathMatch -> Maybe Text
exact :: Prelude.Maybe Prelude.Text
  }
  deriving (HttpPathMatch -> HttpPathMatch -> Bool
(HttpPathMatch -> HttpPathMatch -> Bool)
-> (HttpPathMatch -> HttpPathMatch -> Bool) -> Eq HttpPathMatch
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]
(Int -> ReadS HttpPathMatch)
-> ReadS [HttpPathMatch]
-> ReadPrec HttpPathMatch
-> ReadPrec [HttpPathMatch]
-> Read 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
(Int -> HttpPathMatch -> ShowS)
-> (HttpPathMatch -> String)
-> ([HttpPathMatch] -> ShowS)
-> Show HttpPathMatch
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. HttpPathMatch -> Rep HttpPathMatch x)
-> (forall x. Rep HttpPathMatch x -> HttpPathMatch)
-> Generic HttpPathMatch
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:
--
-- 'regex', 'httpPathMatch_regex' - The regex used to match the path.
--
-- 'exact', 'httpPathMatch_exact' - The exact path to match on.
newHttpPathMatch ::
  HttpPathMatch
newHttpPathMatch :: HttpPathMatch
newHttpPathMatch =
  HttpPathMatch' :: Maybe Text -> Maybe Text -> HttpPathMatch
HttpPathMatch'
    { $sel:regex:HttpPathMatch' :: Maybe Text
regex = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:exact:HttpPathMatch' :: Maybe Text
exact = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The regex used to match the path.
httpPathMatch_regex :: Lens.Lens' HttpPathMatch (Prelude.Maybe Prelude.Text)
httpPathMatch_regex :: (Maybe Text -> f (Maybe Text)) -> HttpPathMatch -> f HttpPathMatch
httpPathMatch_regex = (HttpPathMatch -> Maybe Text)
-> (HttpPathMatch -> Maybe Text -> HttpPathMatch)
-> Lens HttpPathMatch HttpPathMatch (Maybe Text) (Maybe Text)
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)

-- | The exact path to match on.
httpPathMatch_exact :: Lens.Lens' HttpPathMatch (Prelude.Maybe Prelude.Text)
httpPathMatch_exact :: (Maybe Text -> f (Maybe Text)) -> HttpPathMatch -> f HttpPathMatch
httpPathMatch_exact = (HttpPathMatch -> Maybe Text)
-> (HttpPathMatch -> Maybe Text -> HttpPathMatch)
-> Lens HttpPathMatch HttpPathMatch (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON HttpPathMatch where
  parseJSON :: Value -> Parser HttpPathMatch
parseJSON =
    String
-> (Object -> Parser HttpPathMatch)
-> Value
-> Parser HttpPathMatch
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpPathMatch"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> HttpPathMatch
HttpPathMatch'
            (Maybe Text -> Maybe Text -> HttpPathMatch)
-> Parser (Maybe Text) -> Parser (Maybe Text -> HttpPathMatch)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"regex")
            Parser (Maybe Text -> HttpPathMatch)
-> Parser (Maybe Text) -> Parser HttpPathMatch
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"exact")
      )

instance Prelude.Hashable HttpPathMatch

instance Prelude.NFData HttpPathMatch

instance Core.ToJSON HttpPathMatch where
  toJSON :: HttpPathMatch -> Value
toJSON HttpPathMatch' {Maybe Text
exact :: Maybe Text
regex :: Maybe Text
$sel:exact:HttpPathMatch' :: HttpPathMatch -> Maybe Text
$sel:regex:HttpPathMatch' :: HttpPathMatch -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"regex" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
regex,
            (Text
"exact" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
exact
          ]
      )