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

import Amazonka.CloudFront.Types.CachePolicyQueryStringBehavior
import Amazonka.CloudFront.Types.QueryStringNames
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that determines whether any URL query strings in viewer
-- requests (and if so, which query strings) are included in the cache key
-- and automatically included in requests that CloudFront sends to the
-- origin.
--
-- /See:/ 'newCachePolicyQueryStringsConfig' smart constructor.
data CachePolicyQueryStringsConfig = CachePolicyQueryStringsConfig'
  { -- | Contains the specific query strings in viewer requests that either
    -- /__are__/ or /__are not__/ included in the cache key and automatically
    -- included in requests that CloudFront sends to the origin. The behavior
    -- depends on whether the @QueryStringBehavior@ field in the
    -- @CachePolicyQueryStringsConfig@ type is set to @whitelist@ (the listed
    -- query strings /__are__/ included) or @allExcept@ (the listed query
    -- strings /__are not__/ included, but all other query strings are).
    CachePolicyQueryStringsConfig -> Maybe QueryStringNames
queryStrings :: Prelude.Maybe QueryStringNames,
    -- | Determines whether any URL query strings in viewer requests are included
    -- in the cache key and automatically included in requests that CloudFront
    -- sends to the origin. Valid values are:
    --
    -- -   @none@ – Query strings in viewer requests are not included in the
    --     cache key and are not automatically included in requests that
    --     CloudFront sends to the origin. Even when this field is set to
    --     @none@, any query strings that are listed in an
    --     @OriginRequestPolicy@ /are/ included in origin requests.
    --
    -- -   @whitelist@ – The query strings in viewer requests that are listed
    --     in the @QueryStringNames@ type are included in the cache key and
    --     automatically included in requests that CloudFront sends to the
    --     origin.
    --
    -- -   @allExcept@ – All query strings in viewer requests that are
    --     /__not__/ listed in the @QueryStringNames@ type are included in the
    --     cache key and automatically included in requests that CloudFront
    --     sends to the origin.
    --
    -- -   @all@ – All query strings in viewer requests are included in the
    --     cache key and are automatically included in requests that CloudFront
    --     sends to the origin.
    CachePolicyQueryStringsConfig -> CachePolicyQueryStringBehavior
queryStringBehavior :: CachePolicyQueryStringBehavior
  }
  deriving (CachePolicyQueryStringsConfig
-> CachePolicyQueryStringsConfig -> Bool
(CachePolicyQueryStringsConfig
 -> CachePolicyQueryStringsConfig -> Bool)
-> (CachePolicyQueryStringsConfig
    -> CachePolicyQueryStringsConfig -> Bool)
-> Eq CachePolicyQueryStringsConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachePolicyQueryStringsConfig
-> CachePolicyQueryStringsConfig -> Bool
$c/= :: CachePolicyQueryStringsConfig
-> CachePolicyQueryStringsConfig -> Bool
== :: CachePolicyQueryStringsConfig
-> CachePolicyQueryStringsConfig -> Bool
$c== :: CachePolicyQueryStringsConfig
-> CachePolicyQueryStringsConfig -> Bool
Prelude.Eq, ReadPrec [CachePolicyQueryStringsConfig]
ReadPrec CachePolicyQueryStringsConfig
Int -> ReadS CachePolicyQueryStringsConfig
ReadS [CachePolicyQueryStringsConfig]
(Int -> ReadS CachePolicyQueryStringsConfig)
-> ReadS [CachePolicyQueryStringsConfig]
-> ReadPrec CachePolicyQueryStringsConfig
-> ReadPrec [CachePolicyQueryStringsConfig]
-> Read CachePolicyQueryStringsConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachePolicyQueryStringsConfig]
$creadListPrec :: ReadPrec [CachePolicyQueryStringsConfig]
readPrec :: ReadPrec CachePolicyQueryStringsConfig
$creadPrec :: ReadPrec CachePolicyQueryStringsConfig
readList :: ReadS [CachePolicyQueryStringsConfig]
$creadList :: ReadS [CachePolicyQueryStringsConfig]
readsPrec :: Int -> ReadS CachePolicyQueryStringsConfig
$creadsPrec :: Int -> ReadS CachePolicyQueryStringsConfig
Prelude.Read, Int -> CachePolicyQueryStringsConfig -> ShowS
[CachePolicyQueryStringsConfig] -> ShowS
CachePolicyQueryStringsConfig -> String
(Int -> CachePolicyQueryStringsConfig -> ShowS)
-> (CachePolicyQueryStringsConfig -> String)
-> ([CachePolicyQueryStringsConfig] -> ShowS)
-> Show CachePolicyQueryStringsConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachePolicyQueryStringsConfig] -> ShowS
$cshowList :: [CachePolicyQueryStringsConfig] -> ShowS
show :: CachePolicyQueryStringsConfig -> String
$cshow :: CachePolicyQueryStringsConfig -> String
showsPrec :: Int -> CachePolicyQueryStringsConfig -> ShowS
$cshowsPrec :: Int -> CachePolicyQueryStringsConfig -> ShowS
Prelude.Show, (forall x.
 CachePolicyQueryStringsConfig
 -> Rep CachePolicyQueryStringsConfig x)
-> (forall x.
    Rep CachePolicyQueryStringsConfig x
    -> CachePolicyQueryStringsConfig)
-> Generic CachePolicyQueryStringsConfig
forall x.
Rep CachePolicyQueryStringsConfig x
-> CachePolicyQueryStringsConfig
forall x.
CachePolicyQueryStringsConfig
-> Rep CachePolicyQueryStringsConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CachePolicyQueryStringsConfig x
-> CachePolicyQueryStringsConfig
$cfrom :: forall x.
CachePolicyQueryStringsConfig
-> Rep CachePolicyQueryStringsConfig x
Prelude.Generic)

-- |
-- Create a value of 'CachePolicyQueryStringsConfig' 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:
--
-- 'queryStrings', 'cachePolicyQueryStringsConfig_queryStrings' - Contains the specific query strings in viewer requests that either
-- /__are__/ or /__are not__/ included in the cache key and automatically
-- included in requests that CloudFront sends to the origin. The behavior
-- depends on whether the @QueryStringBehavior@ field in the
-- @CachePolicyQueryStringsConfig@ type is set to @whitelist@ (the listed
-- query strings /__are__/ included) or @allExcept@ (the listed query
-- strings /__are not__/ included, but all other query strings are).
--
-- 'queryStringBehavior', 'cachePolicyQueryStringsConfig_queryStringBehavior' - Determines whether any URL query strings in viewer requests are included
-- in the cache key and automatically included in requests that CloudFront
-- sends to the origin. Valid values are:
--
-- -   @none@ – Query strings in viewer requests are not included in the
--     cache key and are not automatically included in requests that
--     CloudFront sends to the origin. Even when this field is set to
--     @none@, any query strings that are listed in an
--     @OriginRequestPolicy@ /are/ included in origin requests.
--
-- -   @whitelist@ – The query strings in viewer requests that are listed
--     in the @QueryStringNames@ type are included in the cache key and
--     automatically included in requests that CloudFront sends to the
--     origin.
--
-- -   @allExcept@ – All query strings in viewer requests that are
--     /__not__/ listed in the @QueryStringNames@ type are included in the
--     cache key and automatically included in requests that CloudFront
--     sends to the origin.
--
-- -   @all@ – All query strings in viewer requests are included in the
--     cache key and are automatically included in requests that CloudFront
--     sends to the origin.
newCachePolicyQueryStringsConfig ::
  -- | 'queryStringBehavior'
  CachePolicyQueryStringBehavior ->
  CachePolicyQueryStringsConfig
newCachePolicyQueryStringsConfig :: CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig
newCachePolicyQueryStringsConfig
  CachePolicyQueryStringBehavior
pQueryStringBehavior_ =
    CachePolicyQueryStringsConfig' :: Maybe QueryStringNames
-> CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig
CachePolicyQueryStringsConfig'
      { $sel:queryStrings:CachePolicyQueryStringsConfig' :: Maybe QueryStringNames
queryStrings =
          Maybe QueryStringNames
forall a. Maybe a
Prelude.Nothing,
        $sel:queryStringBehavior:CachePolicyQueryStringsConfig' :: CachePolicyQueryStringBehavior
queryStringBehavior = CachePolicyQueryStringBehavior
pQueryStringBehavior_
      }

-- | Contains the specific query strings in viewer requests that either
-- /__are__/ or /__are not__/ included in the cache key and automatically
-- included in requests that CloudFront sends to the origin. The behavior
-- depends on whether the @QueryStringBehavior@ field in the
-- @CachePolicyQueryStringsConfig@ type is set to @whitelist@ (the listed
-- query strings /__are__/ included) or @allExcept@ (the listed query
-- strings /__are not__/ included, but all other query strings are).
cachePolicyQueryStringsConfig_queryStrings :: Lens.Lens' CachePolicyQueryStringsConfig (Prelude.Maybe QueryStringNames)
cachePolicyQueryStringsConfig_queryStrings :: (Maybe QueryStringNames -> f (Maybe QueryStringNames))
-> CachePolicyQueryStringsConfig -> f CachePolicyQueryStringsConfig
cachePolicyQueryStringsConfig_queryStrings = (CachePolicyQueryStringsConfig -> Maybe QueryStringNames)
-> (CachePolicyQueryStringsConfig
    -> Maybe QueryStringNames -> CachePolicyQueryStringsConfig)
-> Lens
     CachePolicyQueryStringsConfig
     CachePolicyQueryStringsConfig
     (Maybe QueryStringNames)
     (Maybe QueryStringNames)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicyQueryStringsConfig' {Maybe QueryStringNames
queryStrings :: Maybe QueryStringNames
$sel:queryStrings:CachePolicyQueryStringsConfig' :: CachePolicyQueryStringsConfig -> Maybe QueryStringNames
queryStrings} -> Maybe QueryStringNames
queryStrings) (\s :: CachePolicyQueryStringsConfig
s@CachePolicyQueryStringsConfig' {} Maybe QueryStringNames
a -> CachePolicyQueryStringsConfig
s {$sel:queryStrings:CachePolicyQueryStringsConfig' :: Maybe QueryStringNames
queryStrings = Maybe QueryStringNames
a} :: CachePolicyQueryStringsConfig)

-- | Determines whether any URL query strings in viewer requests are included
-- in the cache key and automatically included in requests that CloudFront
-- sends to the origin. Valid values are:
--
-- -   @none@ – Query strings in viewer requests are not included in the
--     cache key and are not automatically included in requests that
--     CloudFront sends to the origin. Even when this field is set to
--     @none@, any query strings that are listed in an
--     @OriginRequestPolicy@ /are/ included in origin requests.
--
-- -   @whitelist@ – The query strings in viewer requests that are listed
--     in the @QueryStringNames@ type are included in the cache key and
--     automatically included in requests that CloudFront sends to the
--     origin.
--
-- -   @allExcept@ – All query strings in viewer requests that are
--     /__not__/ listed in the @QueryStringNames@ type are included in the
--     cache key and automatically included in requests that CloudFront
--     sends to the origin.
--
-- -   @all@ – All query strings in viewer requests are included in the
--     cache key and are automatically included in requests that CloudFront
--     sends to the origin.
cachePolicyQueryStringsConfig_queryStringBehavior :: Lens.Lens' CachePolicyQueryStringsConfig CachePolicyQueryStringBehavior
cachePolicyQueryStringsConfig_queryStringBehavior :: (CachePolicyQueryStringBehavior
 -> f CachePolicyQueryStringBehavior)
-> CachePolicyQueryStringsConfig -> f CachePolicyQueryStringsConfig
cachePolicyQueryStringsConfig_queryStringBehavior = (CachePolicyQueryStringsConfig -> CachePolicyQueryStringBehavior)
-> (CachePolicyQueryStringsConfig
    -> CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig)
-> Lens
     CachePolicyQueryStringsConfig
     CachePolicyQueryStringsConfig
     CachePolicyQueryStringBehavior
     CachePolicyQueryStringBehavior
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicyQueryStringsConfig' {CachePolicyQueryStringBehavior
queryStringBehavior :: CachePolicyQueryStringBehavior
$sel:queryStringBehavior:CachePolicyQueryStringsConfig' :: CachePolicyQueryStringsConfig -> CachePolicyQueryStringBehavior
queryStringBehavior} -> CachePolicyQueryStringBehavior
queryStringBehavior) (\s :: CachePolicyQueryStringsConfig
s@CachePolicyQueryStringsConfig' {} CachePolicyQueryStringBehavior
a -> CachePolicyQueryStringsConfig
s {$sel:queryStringBehavior:CachePolicyQueryStringsConfig' :: CachePolicyQueryStringBehavior
queryStringBehavior = CachePolicyQueryStringBehavior
a} :: CachePolicyQueryStringsConfig)

instance Core.FromXML CachePolicyQueryStringsConfig where
  parseXML :: [Node] -> Either String CachePolicyQueryStringsConfig
parseXML [Node]
x =
    Maybe QueryStringNames
-> CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig
CachePolicyQueryStringsConfig'
      (Maybe QueryStringNames
 -> CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig)
-> Either String (Maybe QueryStringNames)
-> Either
     String
     (CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe QueryStringNames)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"QueryStrings")
      Either
  String
  (CachePolicyQueryStringBehavior -> CachePolicyQueryStringsConfig)
-> Either String CachePolicyQueryStringBehavior
-> Either String CachePolicyQueryStringsConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String CachePolicyQueryStringBehavior
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"QueryStringBehavior")

instance
  Prelude.Hashable
    CachePolicyQueryStringsConfig

instance Prelude.NFData CachePolicyQueryStringsConfig

instance Core.ToXML CachePolicyQueryStringsConfig where
  toXML :: CachePolicyQueryStringsConfig -> XML
toXML CachePolicyQueryStringsConfig' {Maybe QueryStringNames
CachePolicyQueryStringBehavior
queryStringBehavior :: CachePolicyQueryStringBehavior
queryStrings :: Maybe QueryStringNames
$sel:queryStringBehavior:CachePolicyQueryStringsConfig' :: CachePolicyQueryStringsConfig -> CachePolicyQueryStringBehavior
$sel:queryStrings:CachePolicyQueryStringsConfig' :: CachePolicyQueryStringsConfig -> Maybe QueryStringNames
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"QueryStrings" Name -> Maybe QueryStringNames -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe QueryStringNames
queryStrings,
        Name
"QueryStringBehavior" Name -> CachePolicyQueryStringBehavior -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= CachePolicyQueryStringBehavior
queryStringBehavior
      ]