{-# 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.Lightsail.Types.CookieObject
-- 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.Lightsail.Types.CookieObject where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types.ForwardValues
import qualified Amazonka.Prelude as Prelude

-- | Describes whether an Amazon Lightsail content delivery network (CDN)
-- distribution forwards cookies to the origin and, if so, which ones.
--
-- For the cookies that you specify, your distribution caches separate
-- versions of the specified content based on the cookie values in viewer
-- requests.
--
-- /See:/ 'newCookieObject' smart constructor.
data CookieObject = CookieObject'
  { -- | The specific cookies to forward to your distribution\'s origin.
    CookieObject -> Maybe [Text]
cookiesAllowList :: Prelude.Maybe [Prelude.Text],
    -- | Specifies which cookies to forward to the distribution\'s origin for a
    -- cache behavior: @all@, @none@, or @allow-list@ to forward only the
    -- cookies specified in the @cookiesAllowList@ parameter.
    CookieObject -> Maybe ForwardValues
option :: Prelude.Maybe ForwardValues
  }
  deriving (CookieObject -> CookieObject -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CookieObject -> CookieObject -> Bool
$c/= :: CookieObject -> CookieObject -> Bool
== :: CookieObject -> CookieObject -> Bool
$c== :: CookieObject -> CookieObject -> Bool
Prelude.Eq, ReadPrec [CookieObject]
ReadPrec CookieObject
Int -> ReadS CookieObject
ReadS [CookieObject]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CookieObject]
$creadListPrec :: ReadPrec [CookieObject]
readPrec :: ReadPrec CookieObject
$creadPrec :: ReadPrec CookieObject
readList :: ReadS [CookieObject]
$creadList :: ReadS [CookieObject]
readsPrec :: Int -> ReadS CookieObject
$creadsPrec :: Int -> ReadS CookieObject
Prelude.Read, Int -> CookieObject -> ShowS
[CookieObject] -> ShowS
CookieObject -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CookieObject] -> ShowS
$cshowList :: [CookieObject] -> ShowS
show :: CookieObject -> String
$cshow :: CookieObject -> String
showsPrec :: Int -> CookieObject -> ShowS
$cshowsPrec :: Int -> CookieObject -> ShowS
Prelude.Show, forall x. Rep CookieObject x -> CookieObject
forall x. CookieObject -> Rep CookieObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CookieObject x -> CookieObject
$cfrom :: forall x. CookieObject -> Rep CookieObject x
Prelude.Generic)

-- |
-- Create a value of 'CookieObject' 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:
--
-- 'cookiesAllowList', 'cookieObject_cookiesAllowList' - The specific cookies to forward to your distribution\'s origin.
--
-- 'option', 'cookieObject_option' - Specifies which cookies to forward to the distribution\'s origin for a
-- cache behavior: @all@, @none@, or @allow-list@ to forward only the
-- cookies specified in the @cookiesAllowList@ parameter.
newCookieObject ::
  CookieObject
newCookieObject :: CookieObject
newCookieObject =
  CookieObject'
    { $sel:cookiesAllowList:CookieObject' :: Maybe [Text]
cookiesAllowList = forall a. Maybe a
Prelude.Nothing,
      $sel:option:CookieObject' :: Maybe ForwardValues
option = forall a. Maybe a
Prelude.Nothing
    }

-- | The specific cookies to forward to your distribution\'s origin.
cookieObject_cookiesAllowList :: Lens.Lens' CookieObject (Prelude.Maybe [Prelude.Text])
cookieObject_cookiesAllowList :: Lens' CookieObject (Maybe [Text])
cookieObject_cookiesAllowList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieObject' {Maybe [Text]
cookiesAllowList :: Maybe [Text]
$sel:cookiesAllowList:CookieObject' :: CookieObject -> Maybe [Text]
cookiesAllowList} -> Maybe [Text]
cookiesAllowList) (\s :: CookieObject
s@CookieObject' {} Maybe [Text]
a -> CookieObject
s {$sel:cookiesAllowList:CookieObject' :: Maybe [Text]
cookiesAllowList = Maybe [Text]
a} :: CookieObject) 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

-- | Specifies which cookies to forward to the distribution\'s origin for a
-- cache behavior: @all@, @none@, or @allow-list@ to forward only the
-- cookies specified in the @cookiesAllowList@ parameter.
cookieObject_option :: Lens.Lens' CookieObject (Prelude.Maybe ForwardValues)
cookieObject_option :: Lens' CookieObject (Maybe ForwardValues)
cookieObject_option = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieObject' {Maybe ForwardValues
option :: Maybe ForwardValues
$sel:option:CookieObject' :: CookieObject -> Maybe ForwardValues
option} -> Maybe ForwardValues
option) (\s :: CookieObject
s@CookieObject' {} Maybe ForwardValues
a -> CookieObject
s {$sel:option:CookieObject' :: Maybe ForwardValues
option = Maybe ForwardValues
a} :: CookieObject)

instance Data.FromJSON CookieObject where
  parseJSON :: Value -> Parser CookieObject
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CookieObject"
      ( \Object
x ->
          Maybe [Text] -> Maybe ForwardValues -> CookieObject
CookieObject'
            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
"cookiesAllowList"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"option")
      )

instance Prelude.Hashable CookieObject where
  hashWithSalt :: Int -> CookieObject -> Int
hashWithSalt Int
_salt CookieObject' {Maybe [Text]
Maybe ForwardValues
option :: Maybe ForwardValues
cookiesAllowList :: Maybe [Text]
$sel:option:CookieObject' :: CookieObject -> Maybe ForwardValues
$sel:cookiesAllowList:CookieObject' :: CookieObject -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
cookiesAllowList
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ForwardValues
option

instance Prelude.NFData CookieObject where
  rnf :: CookieObject -> ()
rnf CookieObject' {Maybe [Text]
Maybe ForwardValues
option :: Maybe ForwardValues
cookiesAllowList :: Maybe [Text]
$sel:option:CookieObject' :: CookieObject -> Maybe ForwardValues
$sel:cookiesAllowList:CookieObject' :: CookieObject -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
cookiesAllowList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ForwardValues
option

instance Data.ToJSON CookieObject where
  toJSON :: CookieObject -> Value
toJSON CookieObject' {Maybe [Text]
Maybe ForwardValues
option :: Maybe ForwardValues
cookiesAllowList :: Maybe [Text]
$sel:option:CookieObject' :: CookieObject -> Maybe ForwardValues
$sel:cookiesAllowList:CookieObject' :: CookieObject -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"cookiesAllowList" 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]
cookiesAllowList,
            (Key
"option" 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 ForwardValues
option
          ]
      )