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

import Amazonka.CloudFront.Types.CachePolicyConfig
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

-- | A cache policy.
--
-- When it\'s attached to a cache behavior, the cache policy determines the
-- following:
--
-- -   The values that CloudFront includes in the cache key. These values
--     can include HTTP headers, cookies, and URL query strings. CloudFront
--     uses the cache key to find an object in its cache that it can return
--     to the viewer.
--
-- -   The default, minimum, and maximum time to live (TTL) values that you
--     want objects to stay in the CloudFront cache.
--
-- The headers, cookies, and query strings that are included in the cache
-- key are automatically included in requests that CloudFront sends to the
-- origin. CloudFront sends a request when it can\'t find a valid object in
-- its cache that matches the request\'s cache key. If you want to send
-- values to the origin but /not/ include them in the cache key, use
-- @OriginRequestPolicy@.
--
-- /See:/ 'newCachePolicy' smart constructor.
data CachePolicy = CachePolicy'
  { -- | The unique identifier for the cache policy.
    CachePolicy -> Text
id :: Prelude.Text,
    -- | The date and time when the cache policy was last modified.
    CachePolicy -> ISO8601
lastModifiedTime :: Data.ISO8601,
    -- | The cache policy configuration.
    CachePolicy -> CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
  }
  deriving (CachePolicy -> CachePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachePolicy -> CachePolicy -> Bool
$c/= :: CachePolicy -> CachePolicy -> Bool
== :: CachePolicy -> CachePolicy -> Bool
$c== :: CachePolicy -> CachePolicy -> Bool
Prelude.Eq, ReadPrec [CachePolicy]
ReadPrec CachePolicy
Int -> ReadS CachePolicy
ReadS [CachePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachePolicy]
$creadListPrec :: ReadPrec [CachePolicy]
readPrec :: ReadPrec CachePolicy
$creadPrec :: ReadPrec CachePolicy
readList :: ReadS [CachePolicy]
$creadList :: ReadS [CachePolicy]
readsPrec :: Int -> ReadS CachePolicy
$creadsPrec :: Int -> ReadS CachePolicy
Prelude.Read, Int -> CachePolicy -> ShowS
[CachePolicy] -> ShowS
CachePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachePolicy] -> ShowS
$cshowList :: [CachePolicy] -> ShowS
show :: CachePolicy -> String
$cshow :: CachePolicy -> String
showsPrec :: Int -> CachePolicy -> ShowS
$cshowsPrec :: Int -> CachePolicy -> ShowS
Prelude.Show, forall x. Rep CachePolicy x -> CachePolicy
forall x. CachePolicy -> Rep CachePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CachePolicy x -> CachePolicy
$cfrom :: forall x. CachePolicy -> Rep CachePolicy x
Prelude.Generic)

-- |
-- Create a value of 'CachePolicy' 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:
--
-- 'id', 'cachePolicy_id' - The unique identifier for the cache policy.
--
-- 'lastModifiedTime', 'cachePolicy_lastModifiedTime' - The date and time when the cache policy was last modified.
--
-- 'cachePolicyConfig', 'cachePolicy_cachePolicyConfig' - The cache policy configuration.
newCachePolicy ::
  -- | 'id'
  Prelude.Text ->
  -- | 'lastModifiedTime'
  Prelude.UTCTime ->
  -- | 'cachePolicyConfig'
  CachePolicyConfig ->
  CachePolicy
newCachePolicy :: Text -> UTCTime -> CachePolicyConfig -> CachePolicy
newCachePolicy
  Text
pId_
  UTCTime
pLastModifiedTime_
  CachePolicyConfig
pCachePolicyConfig_ =
    CachePolicy'
      { $sel:id:CachePolicy' :: Text
id = Text
pId_,
        $sel:lastModifiedTime:CachePolicy' :: ISO8601
lastModifiedTime =
          forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pLastModifiedTime_,
        $sel:cachePolicyConfig:CachePolicy' :: CachePolicyConfig
cachePolicyConfig = CachePolicyConfig
pCachePolicyConfig_
      }

-- | The unique identifier for the cache policy.
cachePolicy_id :: Lens.Lens' CachePolicy Prelude.Text
cachePolicy_id :: Lens' CachePolicy Text
cachePolicy_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicy' {Text
id :: Text
$sel:id:CachePolicy' :: CachePolicy -> Text
id} -> Text
id) (\s :: CachePolicy
s@CachePolicy' {} Text
a -> CachePolicy
s {$sel:id:CachePolicy' :: Text
id = Text
a} :: CachePolicy)

-- | The date and time when the cache policy was last modified.
cachePolicy_lastModifiedTime :: Lens.Lens' CachePolicy Prelude.UTCTime
cachePolicy_lastModifiedTime :: Lens' CachePolicy UTCTime
cachePolicy_lastModifiedTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicy' {ISO8601
lastModifiedTime :: ISO8601
$sel:lastModifiedTime:CachePolicy' :: CachePolicy -> ISO8601
lastModifiedTime} -> ISO8601
lastModifiedTime) (\s :: CachePolicy
s@CachePolicy' {} ISO8601
a -> CachePolicy
s {$sel:lastModifiedTime:CachePolicy' :: ISO8601
lastModifiedTime = ISO8601
a} :: CachePolicy) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The cache policy configuration.
cachePolicy_cachePolicyConfig :: Lens.Lens' CachePolicy CachePolicyConfig
cachePolicy_cachePolicyConfig :: Lens' CachePolicy CachePolicyConfig
cachePolicy_cachePolicyConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicy' {CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
$sel:cachePolicyConfig:CachePolicy' :: CachePolicy -> CachePolicyConfig
cachePolicyConfig} -> CachePolicyConfig
cachePolicyConfig) (\s :: CachePolicy
s@CachePolicy' {} CachePolicyConfig
a -> CachePolicy
s {$sel:cachePolicyConfig:CachePolicy' :: CachePolicyConfig
cachePolicyConfig = CachePolicyConfig
a} :: CachePolicy)

instance Data.FromXML CachePolicy where
  parseXML :: [Node] -> Either String CachePolicy
parseXML [Node]
x =
    Text -> ISO8601 -> CachePolicyConfig -> CachePolicy
CachePolicy'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Id")
      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
"LastModifiedTime")
      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
"CachePolicyConfig")

instance Prelude.Hashable CachePolicy where
  hashWithSalt :: Int -> CachePolicy -> Int
hashWithSalt Int
_salt CachePolicy' {Text
ISO8601
CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
lastModifiedTime :: ISO8601
id :: Text
$sel:cachePolicyConfig:CachePolicy' :: CachePolicy -> CachePolicyConfig
$sel:lastModifiedTime:CachePolicy' :: CachePolicy -> ISO8601
$sel:id:CachePolicy' :: CachePolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ISO8601
lastModifiedTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CachePolicyConfig
cachePolicyConfig

instance Prelude.NFData CachePolicy where
  rnf :: CachePolicy -> ()
rnf CachePolicy' {Text
ISO8601
CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
lastModifiedTime :: ISO8601
id :: Text
$sel:cachePolicyConfig:CachePolicy' :: CachePolicy -> CachePolicyConfig
$sel:lastModifiedTime:CachePolicy' :: CachePolicy -> ISO8601
$sel:id:CachePolicy' :: CachePolicy -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ISO8601
lastModifiedTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CachePolicyConfig
cachePolicyConfig