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

import Amazonka.CloudFront.Types.CachePolicyConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 :: Core.ISO8601,
    -- | The cache policy configuration.
    CachePolicy -> CachePolicyConfig
cachePolicyConfig :: CachePolicyConfig
  }
  deriving (CachePolicy -> CachePolicy -> Bool
(CachePolicy -> CachePolicy -> Bool)
-> (CachePolicy -> CachePolicy -> Bool) -> Eq CachePolicy
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]
(Int -> ReadS CachePolicy)
-> ReadS [CachePolicy]
-> ReadPrec CachePolicy
-> ReadPrec [CachePolicy]
-> Read 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
(Int -> CachePolicy -> ShowS)
-> (CachePolicy -> String)
-> ([CachePolicy] -> ShowS)
-> Show CachePolicy
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. CachePolicy -> Rep CachePolicy x)
-> (forall x. Rep CachePolicy x -> CachePolicy)
-> Generic CachePolicy
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' :: Text -> ISO8601 -> CachePolicyConfig -> CachePolicy
CachePolicy'
      { $sel:id:CachePolicy' :: Text
id = Text
pId_,
        $sel:lastModifiedTime:CachePolicy' :: ISO8601
lastModifiedTime =
          Tagged UTCTime (Identity UTCTime)
-> Tagged ISO8601 (Identity ISO8601)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged ISO8601 (Identity ISO8601))
-> UTCTime -> ISO8601
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 :: (Text -> f Text) -> CachePolicy -> f CachePolicy
cachePolicy_id = (CachePolicy -> Text)
-> (CachePolicy -> Text -> CachePolicy)
-> Lens CachePolicy CachePolicy Text Text
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 :: (UTCTime -> f UTCTime) -> CachePolicy -> f CachePolicy
cachePolicy_lastModifiedTime = (CachePolicy -> ISO8601)
-> (CachePolicy -> ISO8601 -> CachePolicy)
-> Lens CachePolicy CachePolicy ISO8601 ISO8601
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) ((ISO8601 -> f ISO8601) -> CachePolicy -> f CachePolicy)
-> ((UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601)
-> (UTCTime -> f UTCTime)
-> CachePolicy
-> f CachePolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The cache policy configuration.
cachePolicy_cachePolicyConfig :: Lens.Lens' CachePolicy CachePolicyConfig
cachePolicy_cachePolicyConfig :: (CachePolicyConfig -> f CachePolicyConfig)
-> CachePolicy -> f CachePolicy
cachePolicy_cachePolicyConfig = (CachePolicy -> CachePolicyConfig)
-> (CachePolicy -> CachePolicyConfig -> CachePolicy)
-> Lens CachePolicy CachePolicy CachePolicyConfig 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 Core.FromXML CachePolicy where
  parseXML :: [Node] -> Either String CachePolicy
parseXML [Node]
x =
    Text -> ISO8601 -> CachePolicyConfig -> CachePolicy
CachePolicy'
      (Text -> ISO8601 -> CachePolicyConfig -> CachePolicy)
-> Either String Text
-> Either String (ISO8601 -> CachePolicyConfig -> CachePolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Id")
      Either String (ISO8601 -> CachePolicyConfig -> CachePolicy)
-> Either String ISO8601
-> Either String (CachePolicyConfig -> CachePolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String ISO8601
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"LastModifiedTime")
      Either String (CachePolicyConfig -> CachePolicy)
-> Either String CachePolicyConfig -> Either String CachePolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String CachePolicyConfig
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"CachePolicyConfig")

instance Prelude.Hashable CachePolicy

instance Prelude.NFData CachePolicy