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

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

-- | An object that represents the query parameter in the request.
--
-- /See:/ 'newHttpQueryParameter' smart constructor.
data HttpQueryParameter = HttpQueryParameter'
  { -- | The query parameter to match on.
    HttpQueryParameter -> Maybe QueryParameterMatch
match :: Prelude.Maybe QueryParameterMatch,
    -- | A name for the query parameter that will be matched on.
    HttpQueryParameter -> Text
name :: Prelude.Text
  }
  deriving (HttpQueryParameter -> HttpQueryParameter -> Bool
(HttpQueryParameter -> HttpQueryParameter -> Bool)
-> (HttpQueryParameter -> HttpQueryParameter -> Bool)
-> Eq HttpQueryParameter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpQueryParameter -> HttpQueryParameter -> Bool
$c/= :: HttpQueryParameter -> HttpQueryParameter -> Bool
== :: HttpQueryParameter -> HttpQueryParameter -> Bool
$c== :: HttpQueryParameter -> HttpQueryParameter -> Bool
Prelude.Eq, ReadPrec [HttpQueryParameter]
ReadPrec HttpQueryParameter
Int -> ReadS HttpQueryParameter
ReadS [HttpQueryParameter]
(Int -> ReadS HttpQueryParameter)
-> ReadS [HttpQueryParameter]
-> ReadPrec HttpQueryParameter
-> ReadPrec [HttpQueryParameter]
-> Read HttpQueryParameter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpQueryParameter]
$creadListPrec :: ReadPrec [HttpQueryParameter]
readPrec :: ReadPrec HttpQueryParameter
$creadPrec :: ReadPrec HttpQueryParameter
readList :: ReadS [HttpQueryParameter]
$creadList :: ReadS [HttpQueryParameter]
readsPrec :: Int -> ReadS HttpQueryParameter
$creadsPrec :: Int -> ReadS HttpQueryParameter
Prelude.Read, Int -> HttpQueryParameter -> ShowS
[HttpQueryParameter] -> ShowS
HttpQueryParameter -> String
(Int -> HttpQueryParameter -> ShowS)
-> (HttpQueryParameter -> String)
-> ([HttpQueryParameter] -> ShowS)
-> Show HttpQueryParameter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpQueryParameter] -> ShowS
$cshowList :: [HttpQueryParameter] -> ShowS
show :: HttpQueryParameter -> String
$cshow :: HttpQueryParameter -> String
showsPrec :: Int -> HttpQueryParameter -> ShowS
$cshowsPrec :: Int -> HttpQueryParameter -> ShowS
Prelude.Show, (forall x. HttpQueryParameter -> Rep HttpQueryParameter x)
-> (forall x. Rep HttpQueryParameter x -> HttpQueryParameter)
-> Generic HttpQueryParameter
forall x. Rep HttpQueryParameter x -> HttpQueryParameter
forall x. HttpQueryParameter -> Rep HttpQueryParameter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpQueryParameter x -> HttpQueryParameter
$cfrom :: forall x. HttpQueryParameter -> Rep HttpQueryParameter x
Prelude.Generic)

-- |
-- Create a value of 'HttpQueryParameter' 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:
--
-- 'match', 'httpQueryParameter_match' - The query parameter to match on.
--
-- 'name', 'httpQueryParameter_name' - A name for the query parameter that will be matched on.
newHttpQueryParameter ::
  -- | 'name'
  Prelude.Text ->
  HttpQueryParameter
newHttpQueryParameter :: Text -> HttpQueryParameter
newHttpQueryParameter Text
pName_ =
  HttpQueryParameter' :: Maybe QueryParameterMatch -> Text -> HttpQueryParameter
HttpQueryParameter'
    { $sel:match:HttpQueryParameter' :: Maybe QueryParameterMatch
match = Maybe QueryParameterMatch
forall a. Maybe a
Prelude.Nothing,
      $sel:name:HttpQueryParameter' :: Text
name = Text
pName_
    }

-- | The query parameter to match on.
httpQueryParameter_match :: Lens.Lens' HttpQueryParameter (Prelude.Maybe QueryParameterMatch)
httpQueryParameter_match :: (Maybe QueryParameterMatch -> f (Maybe QueryParameterMatch))
-> HttpQueryParameter -> f HttpQueryParameter
httpQueryParameter_match = (HttpQueryParameter -> Maybe QueryParameterMatch)
-> (HttpQueryParameter
    -> Maybe QueryParameterMatch -> HttpQueryParameter)
-> Lens
     HttpQueryParameter
     HttpQueryParameter
     (Maybe QueryParameterMatch)
     (Maybe QueryParameterMatch)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpQueryParameter' {Maybe QueryParameterMatch
match :: Maybe QueryParameterMatch
$sel:match:HttpQueryParameter' :: HttpQueryParameter -> Maybe QueryParameterMatch
match} -> Maybe QueryParameterMatch
match) (\s :: HttpQueryParameter
s@HttpQueryParameter' {} Maybe QueryParameterMatch
a -> HttpQueryParameter
s {$sel:match:HttpQueryParameter' :: Maybe QueryParameterMatch
match = Maybe QueryParameterMatch
a} :: HttpQueryParameter)

-- | A name for the query parameter that will be matched on.
httpQueryParameter_name :: Lens.Lens' HttpQueryParameter Prelude.Text
httpQueryParameter_name :: (Text -> f Text) -> HttpQueryParameter -> f HttpQueryParameter
httpQueryParameter_name = (HttpQueryParameter -> Text)
-> (HttpQueryParameter -> Text -> HttpQueryParameter)
-> Lens HttpQueryParameter HttpQueryParameter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpQueryParameter' {Text
name :: Text
$sel:name:HttpQueryParameter' :: HttpQueryParameter -> Text
name} -> Text
name) (\s :: HttpQueryParameter
s@HttpQueryParameter' {} Text
a -> HttpQueryParameter
s {$sel:name:HttpQueryParameter' :: Text
name = Text
a} :: HttpQueryParameter)

instance Core.FromJSON HttpQueryParameter where
  parseJSON :: Value -> Parser HttpQueryParameter
parseJSON =
    String
-> (Object -> Parser HttpQueryParameter)
-> Value
-> Parser HttpQueryParameter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HttpQueryParameter"
      ( \Object
x ->
          Maybe QueryParameterMatch -> Text -> HttpQueryParameter
HttpQueryParameter'
            (Maybe QueryParameterMatch -> Text -> HttpQueryParameter)
-> Parser (Maybe QueryParameterMatch)
-> Parser (Text -> HttpQueryParameter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe QueryParameterMatch)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"match") Parser (Text -> HttpQueryParameter)
-> Parser Text -> Parser HttpQueryParameter
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 HttpQueryParameter

instance Prelude.NFData HttpQueryParameter

instance Core.ToJSON HttpQueryParameter where
  toJSON :: HttpQueryParameter -> Value
toJSON HttpQueryParameter' {Maybe QueryParameterMatch
Text
name :: Text
match :: Maybe QueryParameterMatch
$sel:name:HttpQueryParameter' :: HttpQueryParameter -> Text
$sel:match:HttpQueryParameter' :: HttpQueryParameter -> Maybe QueryParameterMatch
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"match" Text -> QueryParameterMatch -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (QueryParameterMatch -> Pair)
-> Maybe QueryParameterMatch -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe QueryParameterMatch
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)
          ]
      )