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

import Amazonka.CloudFront.Types.Method
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type that controls whether CloudFront caches the response to
-- requests using the specified HTTP methods. There are two choices:
--
-- -   CloudFront caches responses to @GET@ and @HEAD@ requests.
--
-- -   CloudFront caches responses to @GET@, @HEAD@, and @OPTIONS@
--     requests.
--
-- If you pick the second choice for your Amazon S3 Origin, you may need to
-- forward Access-Control-Request-Method, Access-Control-Request-Headers,
-- and Origin headers for the responses to be cached correctly.
--
-- /See:/ 'newCachedMethods' smart constructor.
data CachedMethods = CachedMethods'
  { -- | The number of HTTP methods for which you want CloudFront to cache
    -- responses. Valid values are @2@ (for caching responses to @GET@ and
    -- @HEAD@ requests) and @3@ (for caching responses to @GET@, @HEAD@, and
    -- @OPTIONS@ requests).
    CachedMethods -> Int
quantity :: Prelude.Int,
    -- | A complex type that contains the HTTP methods that you want CloudFront
    -- to cache responses to.
    CachedMethods -> [Method]
items :: [Method]
  }
  deriving (CachedMethods -> CachedMethods -> Bool
(CachedMethods -> CachedMethods -> Bool)
-> (CachedMethods -> CachedMethods -> Bool) -> Eq CachedMethods
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachedMethods -> CachedMethods -> Bool
$c/= :: CachedMethods -> CachedMethods -> Bool
== :: CachedMethods -> CachedMethods -> Bool
$c== :: CachedMethods -> CachedMethods -> Bool
Prelude.Eq, ReadPrec [CachedMethods]
ReadPrec CachedMethods
Int -> ReadS CachedMethods
ReadS [CachedMethods]
(Int -> ReadS CachedMethods)
-> ReadS [CachedMethods]
-> ReadPrec CachedMethods
-> ReadPrec [CachedMethods]
-> Read CachedMethods
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachedMethods]
$creadListPrec :: ReadPrec [CachedMethods]
readPrec :: ReadPrec CachedMethods
$creadPrec :: ReadPrec CachedMethods
readList :: ReadS [CachedMethods]
$creadList :: ReadS [CachedMethods]
readsPrec :: Int -> ReadS CachedMethods
$creadsPrec :: Int -> ReadS CachedMethods
Prelude.Read, Int -> CachedMethods -> ShowS
[CachedMethods] -> ShowS
CachedMethods -> String
(Int -> CachedMethods -> ShowS)
-> (CachedMethods -> String)
-> ([CachedMethods] -> ShowS)
-> Show CachedMethods
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachedMethods] -> ShowS
$cshowList :: [CachedMethods] -> ShowS
show :: CachedMethods -> String
$cshow :: CachedMethods -> String
showsPrec :: Int -> CachedMethods -> ShowS
$cshowsPrec :: Int -> CachedMethods -> ShowS
Prelude.Show, (forall x. CachedMethods -> Rep CachedMethods x)
-> (forall x. Rep CachedMethods x -> CachedMethods)
-> Generic CachedMethods
forall x. Rep CachedMethods x -> CachedMethods
forall x. CachedMethods -> Rep CachedMethods x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CachedMethods x -> CachedMethods
$cfrom :: forall x. CachedMethods -> Rep CachedMethods x
Prelude.Generic)

-- |
-- Create a value of 'CachedMethods' 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:
--
-- 'quantity', 'cachedMethods_quantity' - The number of HTTP methods for which you want CloudFront to cache
-- responses. Valid values are @2@ (for caching responses to @GET@ and
-- @HEAD@ requests) and @3@ (for caching responses to @GET@, @HEAD@, and
-- @OPTIONS@ requests).
--
-- 'items', 'cachedMethods_items' - A complex type that contains the HTTP methods that you want CloudFront
-- to cache responses to.
newCachedMethods ::
  -- | 'quantity'
  Prelude.Int ->
  CachedMethods
newCachedMethods :: Int -> CachedMethods
newCachedMethods Int
pQuantity_ =
  CachedMethods' :: Int -> [Method] -> CachedMethods
CachedMethods'
    { $sel:quantity:CachedMethods' :: Int
quantity = Int
pQuantity_,
      $sel:items:CachedMethods' :: [Method]
items = [Method]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The number of HTTP methods for which you want CloudFront to cache
-- responses. Valid values are @2@ (for caching responses to @GET@ and
-- @HEAD@ requests) and @3@ (for caching responses to @GET@, @HEAD@, and
-- @OPTIONS@ requests).
cachedMethods_quantity :: Lens.Lens' CachedMethods Prelude.Int
cachedMethods_quantity :: (Int -> f Int) -> CachedMethods -> f CachedMethods
cachedMethods_quantity = (CachedMethods -> Int)
-> (CachedMethods -> Int -> CachedMethods)
-> Lens CachedMethods CachedMethods Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachedMethods' {Int
quantity :: Int
$sel:quantity:CachedMethods' :: CachedMethods -> Int
quantity} -> Int
quantity) (\s :: CachedMethods
s@CachedMethods' {} Int
a -> CachedMethods
s {$sel:quantity:CachedMethods' :: Int
quantity = Int
a} :: CachedMethods)

-- | A complex type that contains the HTTP methods that you want CloudFront
-- to cache responses to.
cachedMethods_items :: Lens.Lens' CachedMethods [Method]
cachedMethods_items :: ([Method] -> f [Method]) -> CachedMethods -> f CachedMethods
cachedMethods_items = (CachedMethods -> [Method])
-> (CachedMethods -> [Method] -> CachedMethods)
-> Lens CachedMethods CachedMethods [Method] [Method]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachedMethods' {[Method]
items :: [Method]
$sel:items:CachedMethods' :: CachedMethods -> [Method]
items} -> [Method]
items) (\s :: CachedMethods
s@CachedMethods' {} [Method]
a -> CachedMethods
s {$sel:items:CachedMethods' :: [Method]
items = [Method]
a} :: CachedMethods) (([Method] -> f [Method]) -> CachedMethods -> f CachedMethods)
-> (([Method] -> f [Method]) -> [Method] -> f [Method])
-> ([Method] -> f [Method])
-> CachedMethods
-> f CachedMethods
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Method] -> f [Method]) -> [Method] -> f [Method]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML CachedMethods where
  parseXML :: [Node] -> Either String CachedMethods
parseXML [Node]
x =
    Int -> [Method] -> CachedMethods
CachedMethods'
      (Int -> [Method] -> CachedMethods)
-> Either String Int -> Either String ([Method] -> CachedMethods)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Int
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Quantity")
      Either String ([Method] -> CachedMethods)
-> Either String [Method] -> Either String CachedMethods
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Items" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String [Method]) -> Either String [Method]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [Method]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Method"
                  )

instance Prelude.Hashable CachedMethods

instance Prelude.NFData CachedMethods

instance Core.ToXML CachedMethods where
  toXML :: CachedMethods -> XML
toXML CachedMethods' {Int
[Method]
items :: [Method]
quantity :: Int
$sel:items:CachedMethods' :: CachedMethods -> [Method]
$sel:quantity:CachedMethods' :: CachedMethods -> Int
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity,
        Name
"Items" Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Name -> [Method] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Method" [Method]
items
      ]