{-# 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.ELBV2.Types.QueryStringConditionConfig
-- 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.ELBV2.Types.QueryStringConditionConfig where

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types.QueryStringKeyValuePair
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a query string condition.
--
-- The query string component of a URI starts after the first \'?\'
-- character and is terminated by either a \'#\' character or the end of
-- the URI. A typical query string contains key\/value pairs separated by
-- \'&\' characters. The allowed characters are specified by RFC 3986. Any
-- character can be percentage encoded.
--
-- /See:/ 'newQueryStringConditionConfig' smart constructor.
data QueryStringConditionConfig = QueryStringConditionConfig'
  { -- | One or more key\/value pairs or values to find in the query string. The
    -- maximum size of each string is 128 characters. The comparison is case
    -- insensitive. The following wildcard characters are supported: * (matches
    -- 0 or more characters) and ? (matches exactly 1 character). To search for
    -- a literal \'*\' or \'?\' character in a query string, you must escape
    -- these characters in @Values@ using a \'\\\' character.
    --
    -- If you specify multiple key\/value pairs or values, the condition is
    -- satisfied if one of them is found in the query string.
    QueryStringConditionConfig -> Maybe [QueryStringKeyValuePair]
values :: Prelude.Maybe [QueryStringKeyValuePair]
  }
  deriving (QueryStringConditionConfig -> QueryStringConditionConfig -> Bool
(QueryStringConditionConfig -> QueryStringConditionConfig -> Bool)
-> (QueryStringConditionConfig
    -> QueryStringConditionConfig -> Bool)
-> Eq QueryStringConditionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryStringConditionConfig -> QueryStringConditionConfig -> Bool
$c/= :: QueryStringConditionConfig -> QueryStringConditionConfig -> Bool
== :: QueryStringConditionConfig -> QueryStringConditionConfig -> Bool
$c== :: QueryStringConditionConfig -> QueryStringConditionConfig -> Bool
Prelude.Eq, ReadPrec [QueryStringConditionConfig]
ReadPrec QueryStringConditionConfig
Int -> ReadS QueryStringConditionConfig
ReadS [QueryStringConditionConfig]
(Int -> ReadS QueryStringConditionConfig)
-> ReadS [QueryStringConditionConfig]
-> ReadPrec QueryStringConditionConfig
-> ReadPrec [QueryStringConditionConfig]
-> Read QueryStringConditionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryStringConditionConfig]
$creadListPrec :: ReadPrec [QueryStringConditionConfig]
readPrec :: ReadPrec QueryStringConditionConfig
$creadPrec :: ReadPrec QueryStringConditionConfig
readList :: ReadS [QueryStringConditionConfig]
$creadList :: ReadS [QueryStringConditionConfig]
readsPrec :: Int -> ReadS QueryStringConditionConfig
$creadsPrec :: Int -> ReadS QueryStringConditionConfig
Prelude.Read, Int -> QueryStringConditionConfig -> ShowS
[QueryStringConditionConfig] -> ShowS
QueryStringConditionConfig -> String
(Int -> QueryStringConditionConfig -> ShowS)
-> (QueryStringConditionConfig -> String)
-> ([QueryStringConditionConfig] -> ShowS)
-> Show QueryStringConditionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryStringConditionConfig] -> ShowS
$cshowList :: [QueryStringConditionConfig] -> ShowS
show :: QueryStringConditionConfig -> String
$cshow :: QueryStringConditionConfig -> String
showsPrec :: Int -> QueryStringConditionConfig -> ShowS
$cshowsPrec :: Int -> QueryStringConditionConfig -> ShowS
Prelude.Show, (forall x.
 QueryStringConditionConfig -> Rep QueryStringConditionConfig x)
-> (forall x.
    Rep QueryStringConditionConfig x -> QueryStringConditionConfig)
-> Generic QueryStringConditionConfig
forall x.
Rep QueryStringConditionConfig x -> QueryStringConditionConfig
forall x.
QueryStringConditionConfig -> Rep QueryStringConditionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep QueryStringConditionConfig x -> QueryStringConditionConfig
$cfrom :: forall x.
QueryStringConditionConfig -> Rep QueryStringConditionConfig x
Prelude.Generic)

-- |
-- Create a value of 'QueryStringConditionConfig' 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:
--
-- 'values', 'queryStringConditionConfig_values' - One or more key\/value pairs or values to find in the query string. The
-- maximum size of each string is 128 characters. The comparison is case
-- insensitive. The following wildcard characters are supported: * (matches
-- 0 or more characters) and ? (matches exactly 1 character). To search for
-- a literal \'*\' or \'?\' character in a query string, you must escape
-- these characters in @Values@ using a \'\\\' character.
--
-- If you specify multiple key\/value pairs or values, the condition is
-- satisfied if one of them is found in the query string.
newQueryStringConditionConfig ::
  QueryStringConditionConfig
newQueryStringConditionConfig :: QueryStringConditionConfig
newQueryStringConditionConfig =
  QueryStringConditionConfig' :: Maybe [QueryStringKeyValuePair] -> QueryStringConditionConfig
QueryStringConditionConfig'
    { $sel:values:QueryStringConditionConfig' :: Maybe [QueryStringKeyValuePair]
values =
        Maybe [QueryStringKeyValuePair]
forall a. Maybe a
Prelude.Nothing
    }

-- | One or more key\/value pairs or values to find in the query string. The
-- maximum size of each string is 128 characters. The comparison is case
-- insensitive. The following wildcard characters are supported: * (matches
-- 0 or more characters) and ? (matches exactly 1 character). To search for
-- a literal \'*\' or \'?\' character in a query string, you must escape
-- these characters in @Values@ using a \'\\\' character.
--
-- If you specify multiple key\/value pairs or values, the condition is
-- satisfied if one of them is found in the query string.
queryStringConditionConfig_values :: Lens.Lens' QueryStringConditionConfig (Prelude.Maybe [QueryStringKeyValuePair])
queryStringConditionConfig_values :: (Maybe [QueryStringKeyValuePair]
 -> f (Maybe [QueryStringKeyValuePair]))
-> QueryStringConditionConfig -> f QueryStringConditionConfig
queryStringConditionConfig_values = (QueryStringConditionConfig -> Maybe [QueryStringKeyValuePair])
-> (QueryStringConditionConfig
    -> Maybe [QueryStringKeyValuePair] -> QueryStringConditionConfig)
-> Lens
     QueryStringConditionConfig
     QueryStringConditionConfig
     (Maybe [QueryStringKeyValuePair])
     (Maybe [QueryStringKeyValuePair])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryStringConditionConfig' {Maybe [QueryStringKeyValuePair]
values :: Maybe [QueryStringKeyValuePair]
$sel:values:QueryStringConditionConfig' :: QueryStringConditionConfig -> Maybe [QueryStringKeyValuePair]
values} -> Maybe [QueryStringKeyValuePair]
values) (\s :: QueryStringConditionConfig
s@QueryStringConditionConfig' {} Maybe [QueryStringKeyValuePair]
a -> QueryStringConditionConfig
s {$sel:values:QueryStringConditionConfig' :: Maybe [QueryStringKeyValuePair]
values = Maybe [QueryStringKeyValuePair]
a} :: QueryStringConditionConfig) ((Maybe [QueryStringKeyValuePair]
  -> f (Maybe [QueryStringKeyValuePair]))
 -> QueryStringConditionConfig -> f QueryStringConditionConfig)
-> ((Maybe [QueryStringKeyValuePair]
     -> f (Maybe [QueryStringKeyValuePair]))
    -> Maybe [QueryStringKeyValuePair]
    -> f (Maybe [QueryStringKeyValuePair]))
-> (Maybe [QueryStringKeyValuePair]
    -> f (Maybe [QueryStringKeyValuePair]))
-> QueryStringConditionConfig
-> f QueryStringConditionConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [QueryStringKeyValuePair]
  [QueryStringKeyValuePair]
  [QueryStringKeyValuePair]
  [QueryStringKeyValuePair]
-> Iso
     (Maybe [QueryStringKeyValuePair])
     (Maybe [QueryStringKeyValuePair])
     (Maybe [QueryStringKeyValuePair])
     (Maybe [QueryStringKeyValuePair])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [QueryStringKeyValuePair]
  [QueryStringKeyValuePair]
  [QueryStringKeyValuePair]
  [QueryStringKeyValuePair]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML QueryStringConditionConfig where
  parseXML :: [Node] -> Either String QueryStringConditionConfig
parseXML [Node]
x =
    Maybe [QueryStringKeyValuePair] -> QueryStringConditionConfig
QueryStringConditionConfig'
      (Maybe [QueryStringKeyValuePair] -> QueryStringConditionConfig)
-> Either String (Maybe [QueryStringKeyValuePair])
-> Either String QueryStringConditionConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Values" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [QueryStringKeyValuePair]))
-> Either String (Maybe [QueryStringKeyValuePair])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [QueryStringKeyValuePair])
-> [Node] -> Either String (Maybe [QueryStringKeyValuePair])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [QueryStringKeyValuePair]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )

instance Prelude.Hashable QueryStringConditionConfig

instance Prelude.NFData QueryStringConditionConfig

instance Core.ToQuery QueryStringConditionConfig where
  toQuery :: QueryStringConditionConfig -> QueryString
toQuery QueryStringConditionConfig' {Maybe [QueryStringKeyValuePair]
values :: Maybe [QueryStringKeyValuePair]
$sel:values:QueryStringConditionConfig' :: QueryStringConditionConfig -> Maybe [QueryStringKeyValuePair]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Values"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [QueryStringKeyValuePair] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([QueryStringKeyValuePair] -> QueryString)
-> Maybe [QueryStringKeyValuePair] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [QueryStringKeyValuePair]
values)
      ]