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

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

-- | An object that represents the method and value to match with the header
-- value sent in a request. Specify one match method.
--
-- /See:/ 'newHeaderMatchMethod' smart constructor.
data HeaderMatchMethod = HeaderMatchMethod'
  { -- | The value sent by the client must end with the specified characters.
    HeaderMatchMethod -> Maybe Text
suffix :: Prelude.Maybe Prelude.Text,
    -- | The value sent by the client must include the specified characters.
    HeaderMatchMethod -> Maybe Text
regex :: Prelude.Maybe Prelude.Text,
    -- | The value sent by the client must begin with the specified characters.
    HeaderMatchMethod -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | An object that represents the range of values to match on.
    HeaderMatchMethod -> Maybe MatchRange
range :: Prelude.Maybe MatchRange,
    -- | The value sent by the client must match the specified value exactly.
    HeaderMatchMethod -> Maybe Text
exact :: Prelude.Maybe Prelude.Text
  }
  deriving (HeaderMatchMethod -> HeaderMatchMethod -> Bool
(HeaderMatchMethod -> HeaderMatchMethod -> Bool)
-> (HeaderMatchMethod -> HeaderMatchMethod -> Bool)
-> Eq HeaderMatchMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeaderMatchMethod -> HeaderMatchMethod -> Bool
$c/= :: HeaderMatchMethod -> HeaderMatchMethod -> Bool
== :: HeaderMatchMethod -> HeaderMatchMethod -> Bool
$c== :: HeaderMatchMethod -> HeaderMatchMethod -> Bool
Prelude.Eq, ReadPrec [HeaderMatchMethod]
ReadPrec HeaderMatchMethod
Int -> ReadS HeaderMatchMethod
ReadS [HeaderMatchMethod]
(Int -> ReadS HeaderMatchMethod)
-> ReadS [HeaderMatchMethod]
-> ReadPrec HeaderMatchMethod
-> ReadPrec [HeaderMatchMethod]
-> Read HeaderMatchMethod
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HeaderMatchMethod]
$creadListPrec :: ReadPrec [HeaderMatchMethod]
readPrec :: ReadPrec HeaderMatchMethod
$creadPrec :: ReadPrec HeaderMatchMethod
readList :: ReadS [HeaderMatchMethod]
$creadList :: ReadS [HeaderMatchMethod]
readsPrec :: Int -> ReadS HeaderMatchMethod
$creadsPrec :: Int -> ReadS HeaderMatchMethod
Prelude.Read, Int -> HeaderMatchMethod -> ShowS
[HeaderMatchMethod] -> ShowS
HeaderMatchMethod -> String
(Int -> HeaderMatchMethod -> ShowS)
-> (HeaderMatchMethod -> String)
-> ([HeaderMatchMethod] -> ShowS)
-> Show HeaderMatchMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderMatchMethod] -> ShowS
$cshowList :: [HeaderMatchMethod] -> ShowS
show :: HeaderMatchMethod -> String
$cshow :: HeaderMatchMethod -> String
showsPrec :: Int -> HeaderMatchMethod -> ShowS
$cshowsPrec :: Int -> HeaderMatchMethod -> ShowS
Prelude.Show, (forall x. HeaderMatchMethod -> Rep HeaderMatchMethod x)
-> (forall x. Rep HeaderMatchMethod x -> HeaderMatchMethod)
-> Generic HeaderMatchMethod
forall x. Rep HeaderMatchMethod x -> HeaderMatchMethod
forall x. HeaderMatchMethod -> Rep HeaderMatchMethod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HeaderMatchMethod x -> HeaderMatchMethod
$cfrom :: forall x. HeaderMatchMethod -> Rep HeaderMatchMethod x
Prelude.Generic)

-- |
-- Create a value of 'HeaderMatchMethod' 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:
--
-- 'suffix', 'headerMatchMethod_suffix' - The value sent by the client must end with the specified characters.
--
-- 'regex', 'headerMatchMethod_regex' - The value sent by the client must include the specified characters.
--
-- 'prefix', 'headerMatchMethod_prefix' - The value sent by the client must begin with the specified characters.
--
-- 'range', 'headerMatchMethod_range' - An object that represents the range of values to match on.
--
-- 'exact', 'headerMatchMethod_exact' - The value sent by the client must match the specified value exactly.
newHeaderMatchMethod ::
  HeaderMatchMethod
newHeaderMatchMethod :: HeaderMatchMethod
newHeaderMatchMethod =
  HeaderMatchMethod' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe MatchRange
-> Maybe Text
-> HeaderMatchMethod
HeaderMatchMethod'
    { $sel:suffix:HeaderMatchMethod' :: Maybe Text
suffix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:regex:HeaderMatchMethod' :: Maybe Text
regex = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:prefix:HeaderMatchMethod' :: Maybe Text
prefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:range:HeaderMatchMethod' :: Maybe MatchRange
range = Maybe MatchRange
forall a. Maybe a
Prelude.Nothing,
      $sel:exact:HeaderMatchMethod' :: Maybe Text
exact = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The value sent by the client must end with the specified characters.
headerMatchMethod_suffix :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_suffix :: (Maybe Text -> f (Maybe Text))
-> HeaderMatchMethod -> f HeaderMatchMethod
headerMatchMethod_suffix = (HeaderMatchMethod -> Maybe Text)
-> (HeaderMatchMethod -> Maybe Text -> HeaderMatchMethod)
-> Lens
     HeaderMatchMethod HeaderMatchMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderMatchMethod' {Maybe Text
suffix :: Maybe Text
$sel:suffix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
suffix} -> Maybe Text
suffix) (\s :: HeaderMatchMethod
s@HeaderMatchMethod' {} Maybe Text
a -> HeaderMatchMethod
s {$sel:suffix:HeaderMatchMethod' :: Maybe Text
suffix = Maybe Text
a} :: HeaderMatchMethod)

-- | The value sent by the client must include the specified characters.
headerMatchMethod_regex :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_regex :: (Maybe Text -> f (Maybe Text))
-> HeaderMatchMethod -> f HeaderMatchMethod
headerMatchMethod_regex = (HeaderMatchMethod -> Maybe Text)
-> (HeaderMatchMethod -> Maybe Text -> HeaderMatchMethod)
-> Lens
     HeaderMatchMethod HeaderMatchMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderMatchMethod' {Maybe Text
regex :: Maybe Text
$sel:regex:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
regex} -> Maybe Text
regex) (\s :: HeaderMatchMethod
s@HeaderMatchMethod' {} Maybe Text
a -> HeaderMatchMethod
s {$sel:regex:HeaderMatchMethod' :: Maybe Text
regex = Maybe Text
a} :: HeaderMatchMethod)

-- | The value sent by the client must begin with the specified characters.
headerMatchMethod_prefix :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_prefix :: (Maybe Text -> f (Maybe Text))
-> HeaderMatchMethod -> f HeaderMatchMethod
headerMatchMethod_prefix = (HeaderMatchMethod -> Maybe Text)
-> (HeaderMatchMethod -> Maybe Text -> HeaderMatchMethod)
-> Lens
     HeaderMatchMethod HeaderMatchMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderMatchMethod' {Maybe Text
prefix :: Maybe Text
$sel:prefix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: HeaderMatchMethod
s@HeaderMatchMethod' {} Maybe Text
a -> HeaderMatchMethod
s {$sel:prefix:HeaderMatchMethod' :: Maybe Text
prefix = Maybe Text
a} :: HeaderMatchMethod)

-- | An object that represents the range of values to match on.
headerMatchMethod_range :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe MatchRange)
headerMatchMethod_range :: (Maybe MatchRange -> f (Maybe MatchRange))
-> HeaderMatchMethod -> f HeaderMatchMethod
headerMatchMethod_range = (HeaderMatchMethod -> Maybe MatchRange)
-> (HeaderMatchMethod -> Maybe MatchRange -> HeaderMatchMethod)
-> Lens
     HeaderMatchMethod
     HeaderMatchMethod
     (Maybe MatchRange)
     (Maybe MatchRange)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderMatchMethod' {Maybe MatchRange
range :: Maybe MatchRange
$sel:range:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe MatchRange
range} -> Maybe MatchRange
range) (\s :: HeaderMatchMethod
s@HeaderMatchMethod' {} Maybe MatchRange
a -> HeaderMatchMethod
s {$sel:range:HeaderMatchMethod' :: Maybe MatchRange
range = Maybe MatchRange
a} :: HeaderMatchMethod)

-- | The value sent by the client must match the specified value exactly.
headerMatchMethod_exact :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_exact :: (Maybe Text -> f (Maybe Text))
-> HeaderMatchMethod -> f HeaderMatchMethod
headerMatchMethod_exact = (HeaderMatchMethod -> Maybe Text)
-> (HeaderMatchMethod -> Maybe Text -> HeaderMatchMethod)
-> Lens
     HeaderMatchMethod HeaderMatchMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderMatchMethod' {Maybe Text
exact :: Maybe Text
$sel:exact:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
exact} -> Maybe Text
exact) (\s :: HeaderMatchMethod
s@HeaderMatchMethod' {} Maybe Text
a -> HeaderMatchMethod
s {$sel:exact:HeaderMatchMethod' :: Maybe Text
exact = Maybe Text
a} :: HeaderMatchMethod)

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

instance Prelude.NFData HeaderMatchMethod

instance Core.ToJSON HeaderMatchMethod where
  toJSON :: HeaderMatchMethod -> Value
toJSON HeaderMatchMethod' {Maybe Text
Maybe MatchRange
exact :: Maybe Text
range :: Maybe MatchRange
prefix :: Maybe Text
regex :: Maybe Text
suffix :: Maybe Text
$sel:exact:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:range:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe MatchRange
$sel:prefix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:regex:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:suffix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"suffix" 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
suffix,
            (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
"prefix" 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
prefix,
            (Text
"range" Text -> MatchRange -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (MatchRange -> Pair) -> Maybe MatchRange -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MatchRange
range,
            (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
          ]
      )