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

import Amazonka.CloudFront.Types.CookieNames
import Amazonka.CloudFront.Types.OriginRequestPolicyCookieBehavior
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that determines whether any cookies in viewer requests (and if
-- so, which cookies) are included in requests that CloudFront sends to the
-- origin.
--
-- /See:/ 'newOriginRequestPolicyCookiesConfig' smart constructor.
data OriginRequestPolicyCookiesConfig = OriginRequestPolicyCookiesConfig'
  { OriginRequestPolicyCookiesConfig -> Maybe CookieNames
cookies :: Prelude.Maybe CookieNames,
    -- | Determines whether cookies in viewer requests are included in requests
    -- that CloudFront sends to the origin. Valid values are:
    --
    -- -   @none@ – Cookies in viewer requests are not included in requests
    --     that CloudFront sends to the origin. Even when this field is set to
    --     @none@, any cookies that are listed in a @CachePolicy@ /are/
    --     included in origin requests.
    --
    -- -   @whitelist@ – The cookies in viewer requests that are listed in the
    --     @CookieNames@ type are included in requests that CloudFront sends to
    --     the origin.
    --
    -- -   @all@ – All cookies in viewer requests are included in requests that
    --     CloudFront sends to the origin.
    OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookieBehavior
cookieBehavior :: OriginRequestPolicyCookieBehavior
  }
  deriving (OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookiesConfig -> Bool
(OriginRequestPolicyCookiesConfig
 -> OriginRequestPolicyCookiesConfig -> Bool)
-> (OriginRequestPolicyCookiesConfig
    -> OriginRequestPolicyCookiesConfig -> Bool)
-> Eq OriginRequestPolicyCookiesConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookiesConfig -> Bool
$c/= :: OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookiesConfig -> Bool
== :: OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookiesConfig -> Bool
$c== :: OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookiesConfig -> Bool
Prelude.Eq, ReadPrec [OriginRequestPolicyCookiesConfig]
ReadPrec OriginRequestPolicyCookiesConfig
Int -> ReadS OriginRequestPolicyCookiesConfig
ReadS [OriginRequestPolicyCookiesConfig]
(Int -> ReadS OriginRequestPolicyCookiesConfig)
-> ReadS [OriginRequestPolicyCookiesConfig]
-> ReadPrec OriginRequestPolicyCookiesConfig
-> ReadPrec [OriginRequestPolicyCookiesConfig]
-> Read OriginRequestPolicyCookiesConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginRequestPolicyCookiesConfig]
$creadListPrec :: ReadPrec [OriginRequestPolicyCookiesConfig]
readPrec :: ReadPrec OriginRequestPolicyCookiesConfig
$creadPrec :: ReadPrec OriginRequestPolicyCookiesConfig
readList :: ReadS [OriginRequestPolicyCookiesConfig]
$creadList :: ReadS [OriginRequestPolicyCookiesConfig]
readsPrec :: Int -> ReadS OriginRequestPolicyCookiesConfig
$creadsPrec :: Int -> ReadS OriginRequestPolicyCookiesConfig
Prelude.Read, Int -> OriginRequestPolicyCookiesConfig -> ShowS
[OriginRequestPolicyCookiesConfig] -> ShowS
OriginRequestPolicyCookiesConfig -> String
(Int -> OriginRequestPolicyCookiesConfig -> ShowS)
-> (OriginRequestPolicyCookiesConfig -> String)
-> ([OriginRequestPolicyCookiesConfig] -> ShowS)
-> Show OriginRequestPolicyCookiesConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginRequestPolicyCookiesConfig] -> ShowS
$cshowList :: [OriginRequestPolicyCookiesConfig] -> ShowS
show :: OriginRequestPolicyCookiesConfig -> String
$cshow :: OriginRequestPolicyCookiesConfig -> String
showsPrec :: Int -> OriginRequestPolicyCookiesConfig -> ShowS
$cshowsPrec :: Int -> OriginRequestPolicyCookiesConfig -> ShowS
Prelude.Show, (forall x.
 OriginRequestPolicyCookiesConfig
 -> Rep OriginRequestPolicyCookiesConfig x)
-> (forall x.
    Rep OriginRequestPolicyCookiesConfig x
    -> OriginRequestPolicyCookiesConfig)
-> Generic OriginRequestPolicyCookiesConfig
forall x.
Rep OriginRequestPolicyCookiesConfig x
-> OriginRequestPolicyCookiesConfig
forall x.
OriginRequestPolicyCookiesConfig
-> Rep OriginRequestPolicyCookiesConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep OriginRequestPolicyCookiesConfig x
-> OriginRequestPolicyCookiesConfig
$cfrom :: forall x.
OriginRequestPolicyCookiesConfig
-> Rep OriginRequestPolicyCookiesConfig x
Prelude.Generic)

-- |
-- Create a value of 'OriginRequestPolicyCookiesConfig' 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:
--
-- 'cookies', 'originRequestPolicyCookiesConfig_cookies' - Undocumented member.
--
-- 'cookieBehavior', 'originRequestPolicyCookiesConfig_cookieBehavior' - Determines whether cookies in viewer requests are included in requests
-- that CloudFront sends to the origin. Valid values are:
--
-- -   @none@ – Cookies in viewer requests are not included in requests
--     that CloudFront sends to the origin. Even when this field is set to
--     @none@, any cookies that are listed in a @CachePolicy@ /are/
--     included in origin requests.
--
-- -   @whitelist@ – The cookies in viewer requests that are listed in the
--     @CookieNames@ type are included in requests that CloudFront sends to
--     the origin.
--
-- -   @all@ – All cookies in viewer requests are included in requests that
--     CloudFront sends to the origin.
newOriginRequestPolicyCookiesConfig ::
  -- | 'cookieBehavior'
  OriginRequestPolicyCookieBehavior ->
  OriginRequestPolicyCookiesConfig
newOriginRequestPolicyCookiesConfig :: OriginRequestPolicyCookieBehavior
-> OriginRequestPolicyCookiesConfig
newOriginRequestPolicyCookiesConfig OriginRequestPolicyCookieBehavior
pCookieBehavior_ =
  OriginRequestPolicyCookiesConfig' :: Maybe CookieNames
-> OriginRequestPolicyCookieBehavior
-> OriginRequestPolicyCookiesConfig
OriginRequestPolicyCookiesConfig'
    { $sel:cookies:OriginRequestPolicyCookiesConfig' :: Maybe CookieNames
cookies =
        Maybe CookieNames
forall a. Maybe a
Prelude.Nothing,
      $sel:cookieBehavior:OriginRequestPolicyCookiesConfig' :: OriginRequestPolicyCookieBehavior
cookieBehavior = OriginRequestPolicyCookieBehavior
pCookieBehavior_
    }

-- | Undocumented member.
originRequestPolicyCookiesConfig_cookies :: Lens.Lens' OriginRequestPolicyCookiesConfig (Prelude.Maybe CookieNames)
originRequestPolicyCookiesConfig_cookies :: (Maybe CookieNames -> f (Maybe CookieNames))
-> OriginRequestPolicyCookiesConfig
-> f OriginRequestPolicyCookiesConfig
originRequestPolicyCookiesConfig_cookies = (OriginRequestPolicyCookiesConfig -> Maybe CookieNames)
-> (OriginRequestPolicyCookiesConfig
    -> Maybe CookieNames -> OriginRequestPolicyCookiesConfig)
-> Lens
     OriginRequestPolicyCookiesConfig
     OriginRequestPolicyCookiesConfig
     (Maybe CookieNames)
     (Maybe CookieNames)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyCookiesConfig' {Maybe CookieNames
cookies :: Maybe CookieNames
$sel:cookies:OriginRequestPolicyCookiesConfig' :: OriginRequestPolicyCookiesConfig -> Maybe CookieNames
cookies} -> Maybe CookieNames
cookies) (\s :: OriginRequestPolicyCookiesConfig
s@OriginRequestPolicyCookiesConfig' {} Maybe CookieNames
a -> OriginRequestPolicyCookiesConfig
s {$sel:cookies:OriginRequestPolicyCookiesConfig' :: Maybe CookieNames
cookies = Maybe CookieNames
a} :: OriginRequestPolicyCookiesConfig)

-- | Determines whether cookies in viewer requests are included in requests
-- that CloudFront sends to the origin. Valid values are:
--
-- -   @none@ – Cookies in viewer requests are not included in requests
--     that CloudFront sends to the origin. Even when this field is set to
--     @none@, any cookies that are listed in a @CachePolicy@ /are/
--     included in origin requests.
--
-- -   @whitelist@ – The cookies in viewer requests that are listed in the
--     @CookieNames@ type are included in requests that CloudFront sends to
--     the origin.
--
-- -   @all@ – All cookies in viewer requests are included in requests that
--     CloudFront sends to the origin.
originRequestPolicyCookiesConfig_cookieBehavior :: Lens.Lens' OriginRequestPolicyCookiesConfig OriginRequestPolicyCookieBehavior
originRequestPolicyCookiesConfig_cookieBehavior :: (OriginRequestPolicyCookieBehavior
 -> f OriginRequestPolicyCookieBehavior)
-> OriginRequestPolicyCookiesConfig
-> f OriginRequestPolicyCookiesConfig
originRequestPolicyCookiesConfig_cookieBehavior = (OriginRequestPolicyCookiesConfig
 -> OriginRequestPolicyCookieBehavior)
-> (OriginRequestPolicyCookiesConfig
    -> OriginRequestPolicyCookieBehavior
    -> OriginRequestPolicyCookiesConfig)
-> Lens
     OriginRequestPolicyCookiesConfig
     OriginRequestPolicyCookiesConfig
     OriginRequestPolicyCookieBehavior
     OriginRequestPolicyCookieBehavior
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyCookiesConfig' {OriginRequestPolicyCookieBehavior
cookieBehavior :: OriginRequestPolicyCookieBehavior
$sel:cookieBehavior:OriginRequestPolicyCookiesConfig' :: OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookieBehavior
cookieBehavior} -> OriginRequestPolicyCookieBehavior
cookieBehavior) (\s :: OriginRequestPolicyCookiesConfig
s@OriginRequestPolicyCookiesConfig' {} OriginRequestPolicyCookieBehavior
a -> OriginRequestPolicyCookiesConfig
s {$sel:cookieBehavior:OriginRequestPolicyCookiesConfig' :: OriginRequestPolicyCookieBehavior
cookieBehavior = OriginRequestPolicyCookieBehavior
a} :: OriginRequestPolicyCookiesConfig)

instance
  Core.FromXML
    OriginRequestPolicyCookiesConfig
  where
  parseXML :: [Node] -> Either String OriginRequestPolicyCookiesConfig
parseXML [Node]
x =
    Maybe CookieNames
-> OriginRequestPolicyCookieBehavior
-> OriginRequestPolicyCookiesConfig
OriginRequestPolicyCookiesConfig'
      (Maybe CookieNames
 -> OriginRequestPolicyCookieBehavior
 -> OriginRequestPolicyCookiesConfig)
-> Either String (Maybe CookieNames)
-> Either
     String
     (OriginRequestPolicyCookieBehavior
      -> OriginRequestPolicyCookiesConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe CookieNames)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Cookies")
      Either
  String
  (OriginRequestPolicyCookieBehavior
   -> OriginRequestPolicyCookiesConfig)
-> Either String OriginRequestPolicyCookieBehavior
-> Either String OriginRequestPolicyCookiesConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginRequestPolicyCookieBehavior
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"CookieBehavior")

instance
  Prelude.Hashable
    OriginRequestPolicyCookiesConfig

instance
  Prelude.NFData
    OriginRequestPolicyCookiesConfig

instance Core.ToXML OriginRequestPolicyCookiesConfig where
  toXML :: OriginRequestPolicyCookiesConfig -> XML
toXML OriginRequestPolicyCookiesConfig' {Maybe CookieNames
OriginRequestPolicyCookieBehavior
cookieBehavior :: OriginRequestPolicyCookieBehavior
cookies :: Maybe CookieNames
$sel:cookieBehavior:OriginRequestPolicyCookiesConfig' :: OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyCookieBehavior
$sel:cookies:OriginRequestPolicyCookiesConfig' :: OriginRequestPolicyCookiesConfig -> Maybe CookieNames
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Cookies" Name -> Maybe CookieNames -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe CookieNames
cookies,
        Name
"CookieBehavior" Name -> OriginRequestPolicyCookieBehavior -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginRequestPolicyCookieBehavior
cookieBehavior
      ]