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

import Amazonka.AppMesh.Types.MatchRange
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 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 match the specified value exactly.
    HeaderMatchMethod -> Maybe Text
exact :: 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 include the specified characters.
    HeaderMatchMethod -> Maybe Text
regex :: Prelude.Maybe Prelude.Text,
    -- | The value sent by the client must end with the specified characters.
    HeaderMatchMethod -> Maybe Text
suffix :: Prelude.Maybe Prelude.Text
  }
  deriving (HeaderMatchMethod -> HeaderMatchMethod -> Bool
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]
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
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. 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:
--
-- 'exact', 'headerMatchMethod_exact' - The value sent by the client must match the specified value exactly.
--
-- '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.
--
-- 'regex', 'headerMatchMethod_regex' - The value sent by the client must include the specified characters.
--
-- 'suffix', 'headerMatchMethod_suffix' - The value sent by the client must end with the specified characters.
newHeaderMatchMethod ::
  HeaderMatchMethod
newHeaderMatchMethod :: HeaderMatchMethod
newHeaderMatchMethod =
  HeaderMatchMethod'
    { $sel:exact:HeaderMatchMethod' :: Maybe Text
exact = forall a. Maybe a
Prelude.Nothing,
      $sel:prefix:HeaderMatchMethod' :: Maybe Text
prefix = forall a. Maybe a
Prelude.Nothing,
      $sel:range:HeaderMatchMethod' :: Maybe MatchRange
range = forall a. Maybe a
Prelude.Nothing,
      $sel:regex:HeaderMatchMethod' :: Maybe Text
regex = forall a. Maybe a
Prelude.Nothing,
      $sel:suffix:HeaderMatchMethod' :: Maybe Text
suffix = forall a. Maybe a
Prelude.Nothing
    }

-- | The value sent by the client must match the specified value exactly.
headerMatchMethod_exact :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_exact :: Lens' HeaderMatchMethod (Maybe Text)
headerMatchMethod_exact = 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)

-- | The value sent by the client must begin with the specified characters.
headerMatchMethod_prefix :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_prefix :: Lens' HeaderMatchMethod (Maybe Text)
headerMatchMethod_prefix = 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 :: Lens' HeaderMatchMethod (Maybe MatchRange)
headerMatchMethod_range = 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 include the specified characters.
headerMatchMethod_regex :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_regex :: Lens' HeaderMatchMethod (Maybe Text)
headerMatchMethod_regex = 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 end with the specified characters.
headerMatchMethod_suffix :: Lens.Lens' HeaderMatchMethod (Prelude.Maybe Prelude.Text)
headerMatchMethod_suffix :: Lens' HeaderMatchMethod (Maybe Text)
headerMatchMethod_suffix = 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)

instance Data.FromJSON HeaderMatchMethod where
  parseJSON :: Value -> Parser HeaderMatchMethod
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HeaderMatchMethod"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe MatchRange
-> Maybe Text
-> Maybe Text
-> HeaderMatchMethod
HeaderMatchMethod'
            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
"prefix")
            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
"range")
            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")
            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
"suffix")
      )

instance Prelude.Hashable HeaderMatchMethod where
  hashWithSalt :: Int -> HeaderMatchMethod -> Int
hashWithSalt Int
_salt HeaderMatchMethod' {Maybe Text
Maybe MatchRange
suffix :: Maybe Text
regex :: Maybe Text
range :: Maybe MatchRange
prefix :: Maybe Text
exact :: Maybe Text
$sel:suffix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:regex:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:range:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe MatchRange
$sel:prefix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:exact:HeaderMatchMethod' :: HeaderMatchMethod -> 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
prefix
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MatchRange
range
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
regex
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
suffix

instance Prelude.NFData HeaderMatchMethod where
  rnf :: HeaderMatchMethod -> ()
rnf HeaderMatchMethod' {Maybe Text
Maybe MatchRange
suffix :: Maybe Text
regex :: Maybe Text
range :: Maybe MatchRange
prefix :: Maybe Text
exact :: Maybe Text
$sel:suffix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:regex:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:range:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe MatchRange
$sel:prefix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:exact:HeaderMatchMethod' :: HeaderMatchMethod -> 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
prefix
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe MatchRange
range
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
regex
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
suffix

instance Data.ToJSON HeaderMatchMethod where
  toJSON :: HeaderMatchMethod -> Value
toJSON HeaderMatchMethod' {Maybe Text
Maybe MatchRange
suffix :: Maybe Text
regex :: Maybe Text
range :: Maybe MatchRange
prefix :: Maybe Text
exact :: Maybe Text
$sel:suffix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:regex:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:range:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe MatchRange
$sel:prefix:HeaderMatchMethod' :: HeaderMatchMethod -> Maybe Text
$sel:exact:HeaderMatchMethod' :: HeaderMatchMethod -> 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
"prefix" 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
prefix,
            (Key
"range" 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 MatchRange
range,
            (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,
            (Key
"suffix" 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
suffix
          ]
      )