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

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

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

-- |
-- Create a value of 'HttpRouteHeader' 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', 'httpRouteHeader_invert' - Specify @True@ to match anything except the match criteria. The default
-- value is @False@.
--
-- 'match', 'httpRouteHeader_match' - The @HeaderMatchMethod@ object.
--
-- 'name', 'httpRouteHeader_name' - A name for the HTTP header in the client request that will be matched
-- on.
newHttpRouteHeader ::
  -- | 'name'
  Prelude.Text ->
  HttpRouteHeader
newHttpRouteHeader :: Text -> HttpRouteHeader
newHttpRouteHeader Text
pName_ =
  HttpRouteHeader' :: Maybe Bool -> Maybe HeaderMatchMethod -> Text -> HttpRouteHeader
HttpRouteHeader'
    { $sel:invert:HttpRouteHeader' :: Maybe Bool
invert = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:match:HttpRouteHeader' :: Maybe HeaderMatchMethod
match = Maybe HeaderMatchMethod
forall a. Maybe a
Prelude.Nothing,
      $sel:name:HttpRouteHeader' :: Text
name = Text
pName_
    }

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

-- | The @HeaderMatchMethod@ object.
httpRouteHeader_match :: Lens.Lens' HttpRouteHeader (Prelude.Maybe HeaderMatchMethod)
httpRouteHeader_match :: (Maybe HeaderMatchMethod -> f (Maybe HeaderMatchMethod))
-> HttpRouteHeader -> f HttpRouteHeader
httpRouteHeader_match = (HttpRouteHeader -> Maybe HeaderMatchMethod)
-> (HttpRouteHeader -> Maybe HeaderMatchMethod -> HttpRouteHeader)
-> Lens
     HttpRouteHeader
     HttpRouteHeader
     (Maybe HeaderMatchMethod)
     (Maybe HeaderMatchMethod)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpRouteHeader' {Maybe HeaderMatchMethod
match :: Maybe HeaderMatchMethod
$sel:match:HttpRouteHeader' :: HttpRouteHeader -> Maybe HeaderMatchMethod
match} -> Maybe HeaderMatchMethod
match) (\s :: HttpRouteHeader
s@HttpRouteHeader' {} Maybe HeaderMatchMethod
a -> HttpRouteHeader
s {$sel:match:HttpRouteHeader' :: Maybe HeaderMatchMethod
match = Maybe HeaderMatchMethod
a} :: HttpRouteHeader)

-- | A name for the HTTP header in the client request that will be matched
-- on.
httpRouteHeader_name :: Lens.Lens' HttpRouteHeader Prelude.Text
httpRouteHeader_name :: (Text -> f Text) -> HttpRouteHeader -> f HttpRouteHeader
httpRouteHeader_name = (HttpRouteHeader -> Text)
-> (HttpRouteHeader -> Text -> HttpRouteHeader)
-> Lens HttpRouteHeader HttpRouteHeader Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpRouteHeader' {Text
name :: Text
$sel:name:HttpRouteHeader' :: HttpRouteHeader -> Text
name} -> Text
name) (\s :: HttpRouteHeader
s@HttpRouteHeader' {} Text
a -> HttpRouteHeader
s {$sel:name:HttpRouteHeader' :: Text
name = Text
a} :: HttpRouteHeader)

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

instance Prelude.NFData HttpRouteHeader

instance Core.ToJSON HttpRouteHeader where
  toJSON :: HttpRouteHeader -> Value
toJSON HttpRouteHeader' {Maybe Bool
Maybe HeaderMatchMethod
Text
name :: Text
match :: Maybe HeaderMatchMethod
invert :: Maybe Bool
$sel:name:HttpRouteHeader' :: HttpRouteHeader -> Text
$sel:match:HttpRouteHeader' :: HttpRouteHeader -> Maybe HeaderMatchMethod
$sel:invert:HttpRouteHeader' :: HttpRouteHeader -> 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 -> HeaderMatchMethod -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HeaderMatchMethod -> Pair)
-> Maybe HeaderMatchMethod -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HeaderMatchMethod
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)
          ]
      )