{-# 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.CloudFront.Types.QueryStringCacheKeys
-- 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.CloudFront.Types.QueryStringCacheKeys where

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

-- | This field is deprecated. We recommend that you use a cache policy or an
-- origin request policy instead of this field.
--
-- If you want to include query strings in the cache key, use
-- @QueryStringsConfig@ in a cache policy. See @CachePolicy@.
--
-- If you want to send query strings to the origin but not include them in
-- the cache key, use @QueryStringsConfig@ in an origin request policy. See
-- @OriginRequestPolicy@.
--
-- A complex type that contains information about the query string
-- parameters that you want CloudFront to use for caching for a cache
-- behavior.
--
-- /See:/ 'newQueryStringCacheKeys' smart constructor.
data QueryStringCacheKeys = QueryStringCacheKeys'
  { -- | A list that contains the query string parameters that you want
    -- CloudFront to use as a basis for caching for a cache behavior. If
    -- @Quantity@ is 0, you can omit @Items@.
    QueryStringCacheKeys -> Maybe [Text]
items :: Prelude.Maybe [Prelude.Text],
    -- | The number of @whitelisted@ query string parameters for a cache
    -- behavior.
    QueryStringCacheKeys -> Int
quantity :: Prelude.Int
  }
  deriving (QueryStringCacheKeys -> QueryStringCacheKeys -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryStringCacheKeys -> QueryStringCacheKeys -> Bool
$c/= :: QueryStringCacheKeys -> QueryStringCacheKeys -> Bool
== :: QueryStringCacheKeys -> QueryStringCacheKeys -> Bool
$c== :: QueryStringCacheKeys -> QueryStringCacheKeys -> Bool
Prelude.Eq, ReadPrec [QueryStringCacheKeys]
ReadPrec QueryStringCacheKeys
Int -> ReadS QueryStringCacheKeys
ReadS [QueryStringCacheKeys]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryStringCacheKeys]
$creadListPrec :: ReadPrec [QueryStringCacheKeys]
readPrec :: ReadPrec QueryStringCacheKeys
$creadPrec :: ReadPrec QueryStringCacheKeys
readList :: ReadS [QueryStringCacheKeys]
$creadList :: ReadS [QueryStringCacheKeys]
readsPrec :: Int -> ReadS QueryStringCacheKeys
$creadsPrec :: Int -> ReadS QueryStringCacheKeys
Prelude.Read, Int -> QueryStringCacheKeys -> ShowS
[QueryStringCacheKeys] -> ShowS
QueryStringCacheKeys -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryStringCacheKeys] -> ShowS
$cshowList :: [QueryStringCacheKeys] -> ShowS
show :: QueryStringCacheKeys -> String
$cshow :: QueryStringCacheKeys -> String
showsPrec :: Int -> QueryStringCacheKeys -> ShowS
$cshowsPrec :: Int -> QueryStringCacheKeys -> ShowS
Prelude.Show, forall x. Rep QueryStringCacheKeys x -> QueryStringCacheKeys
forall x. QueryStringCacheKeys -> Rep QueryStringCacheKeys x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueryStringCacheKeys x -> QueryStringCacheKeys
$cfrom :: forall x. QueryStringCacheKeys -> Rep QueryStringCacheKeys x
Prelude.Generic)

-- |
-- Create a value of 'QueryStringCacheKeys' 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:
--
-- 'items', 'queryStringCacheKeys_items' - A list that contains the query string parameters that you want
-- CloudFront to use as a basis for caching for a cache behavior. If
-- @Quantity@ is 0, you can omit @Items@.
--
-- 'quantity', 'queryStringCacheKeys_quantity' - The number of @whitelisted@ query string parameters for a cache
-- behavior.
newQueryStringCacheKeys ::
  -- | 'quantity'
  Prelude.Int ->
  QueryStringCacheKeys
newQueryStringCacheKeys :: Int -> QueryStringCacheKeys
newQueryStringCacheKeys Int
pQuantity_ =
  QueryStringCacheKeys'
    { $sel:items:QueryStringCacheKeys' :: Maybe [Text]
items = forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:QueryStringCacheKeys' :: Int
quantity = Int
pQuantity_
    }

-- | A list that contains the query string parameters that you want
-- CloudFront to use as a basis for caching for a cache behavior. If
-- @Quantity@ is 0, you can omit @Items@.
queryStringCacheKeys_items :: Lens.Lens' QueryStringCacheKeys (Prelude.Maybe [Prelude.Text])
queryStringCacheKeys_items :: Lens' QueryStringCacheKeys (Maybe [Text])
queryStringCacheKeys_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryStringCacheKeys' {Maybe [Text]
items :: Maybe [Text]
$sel:items:QueryStringCacheKeys' :: QueryStringCacheKeys -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: QueryStringCacheKeys
s@QueryStringCacheKeys' {} Maybe [Text]
a -> QueryStringCacheKeys
s {$sel:items:QueryStringCacheKeys' :: Maybe [Text]
items = Maybe [Text]
a} :: QueryStringCacheKeys) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of @whitelisted@ query string parameters for a cache
-- behavior.
queryStringCacheKeys_quantity :: Lens.Lens' QueryStringCacheKeys Prelude.Int
queryStringCacheKeys_quantity :: Lens' QueryStringCacheKeys Int
queryStringCacheKeys_quantity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryStringCacheKeys' {Int
quantity :: Int
$sel:quantity:QueryStringCacheKeys' :: QueryStringCacheKeys -> Int
quantity} -> Int
quantity) (\s :: QueryStringCacheKeys
s@QueryStringCacheKeys' {} Int
a -> QueryStringCacheKeys
s {$sel:quantity:QueryStringCacheKeys' :: Int
quantity = Int
a} :: QueryStringCacheKeys)

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

instance Prelude.Hashable QueryStringCacheKeys where
  hashWithSalt :: Int -> QueryStringCacheKeys -> Int
hashWithSalt Int
_salt QueryStringCacheKeys' {Int
Maybe [Text]
quantity :: Int
items :: Maybe [Text]
$sel:quantity:QueryStringCacheKeys' :: QueryStringCacheKeys -> Int
$sel:items:QueryStringCacheKeys' :: QueryStringCacheKeys -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
items
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
quantity

instance Prelude.NFData QueryStringCacheKeys where
  rnf :: QueryStringCacheKeys -> ()
rnf QueryStringCacheKeys' {Int
Maybe [Text]
quantity :: Int
items :: Maybe [Text]
$sel:quantity:QueryStringCacheKeys' :: QueryStringCacheKeys -> Int
$sel:items:QueryStringCacheKeys' :: QueryStringCacheKeys -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
items
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
quantity

instance Data.ToXML QueryStringCacheKeys where
  toXML :: QueryStringCacheKeys -> XML
toXML QueryStringCacheKeys' {Int
Maybe [Text]
quantity :: Int
items :: Maybe [Text]
$sel:quantity:QueryStringCacheKeys' :: QueryStringCacheKeys -> Int
$sel:items:QueryStringCacheKeys' :: QueryStringCacheKeys -> Maybe [Text]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          forall a. ToXML a => Name -> a -> XML
Data.@= forall a. ToXML a => a -> XML
Data.toXML (forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"Name" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
items),
        Name
"Quantity" forall a. ToXML a => Name -> a -> XML
Data.@= Int
quantity
      ]