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

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

-- | A complex type that contains zero or more @CacheBehavior@ elements.
--
-- /See:/ 'newCacheBehaviors' smart constructor.
data CacheBehaviors = CacheBehaviors'
  { -- | Optional: A complex type that contains cache behaviors for this
    -- distribution. If @Quantity@ is @0@, you can omit @Items@.
    CacheBehaviors -> Maybe [CacheBehavior]
items :: Prelude.Maybe [CacheBehavior],
    -- | The number of cache behaviors for this distribution.
    CacheBehaviors -> Int
quantity :: Prelude.Int
  }
  deriving (CacheBehaviors -> CacheBehaviors -> Bool
(CacheBehaviors -> CacheBehaviors -> Bool)
-> (CacheBehaviors -> CacheBehaviors -> Bool) -> Eq CacheBehaviors
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CacheBehaviors -> CacheBehaviors -> Bool
$c/= :: CacheBehaviors -> CacheBehaviors -> Bool
== :: CacheBehaviors -> CacheBehaviors -> Bool
$c== :: CacheBehaviors -> CacheBehaviors -> Bool
Prelude.Eq, ReadPrec [CacheBehaviors]
ReadPrec CacheBehaviors
Int -> ReadS CacheBehaviors
ReadS [CacheBehaviors]
(Int -> ReadS CacheBehaviors)
-> ReadS [CacheBehaviors]
-> ReadPrec CacheBehaviors
-> ReadPrec [CacheBehaviors]
-> Read CacheBehaviors
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CacheBehaviors]
$creadListPrec :: ReadPrec [CacheBehaviors]
readPrec :: ReadPrec CacheBehaviors
$creadPrec :: ReadPrec CacheBehaviors
readList :: ReadS [CacheBehaviors]
$creadList :: ReadS [CacheBehaviors]
readsPrec :: Int -> ReadS CacheBehaviors
$creadsPrec :: Int -> ReadS CacheBehaviors
Prelude.Read, Int -> CacheBehaviors -> ShowS
[CacheBehaviors] -> ShowS
CacheBehaviors -> String
(Int -> CacheBehaviors -> ShowS)
-> (CacheBehaviors -> String)
-> ([CacheBehaviors] -> ShowS)
-> Show CacheBehaviors
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CacheBehaviors] -> ShowS
$cshowList :: [CacheBehaviors] -> ShowS
show :: CacheBehaviors -> String
$cshow :: CacheBehaviors -> String
showsPrec :: Int -> CacheBehaviors -> ShowS
$cshowsPrec :: Int -> CacheBehaviors -> ShowS
Prelude.Show, (forall x. CacheBehaviors -> Rep CacheBehaviors x)
-> (forall x. Rep CacheBehaviors x -> CacheBehaviors)
-> Generic CacheBehaviors
forall x. Rep CacheBehaviors x -> CacheBehaviors
forall x. CacheBehaviors -> Rep CacheBehaviors x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CacheBehaviors x -> CacheBehaviors
$cfrom :: forall x. CacheBehaviors -> Rep CacheBehaviors x
Prelude.Generic)

-- |
-- Create a value of 'CacheBehaviors' 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:
--
-- 'items', 'cacheBehaviors_items' - Optional: A complex type that contains cache behaviors for this
-- distribution. If @Quantity@ is @0@, you can omit @Items@.
--
-- 'quantity', 'cacheBehaviors_quantity' - The number of cache behaviors for this distribution.
newCacheBehaviors ::
  -- | 'quantity'
  Prelude.Int ->
  CacheBehaviors
newCacheBehaviors :: Int -> CacheBehaviors
newCacheBehaviors Int
pQuantity_ =
  CacheBehaviors' :: Maybe [CacheBehavior] -> Int -> CacheBehaviors
CacheBehaviors'
    { $sel:items:CacheBehaviors' :: Maybe [CacheBehavior]
items = Maybe [CacheBehavior]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:CacheBehaviors' :: Int
quantity = Int
pQuantity_
    }

-- | Optional: A complex type that contains cache behaviors for this
-- distribution. If @Quantity@ is @0@, you can omit @Items@.
cacheBehaviors_items :: Lens.Lens' CacheBehaviors (Prelude.Maybe [CacheBehavior])
cacheBehaviors_items :: (Maybe [CacheBehavior] -> f (Maybe [CacheBehavior]))
-> CacheBehaviors -> f CacheBehaviors
cacheBehaviors_items = (CacheBehaviors -> Maybe [CacheBehavior])
-> (CacheBehaviors -> Maybe [CacheBehavior] -> CacheBehaviors)
-> Lens
     CacheBehaviors
     CacheBehaviors
     (Maybe [CacheBehavior])
     (Maybe [CacheBehavior])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CacheBehaviors' {Maybe [CacheBehavior]
items :: Maybe [CacheBehavior]
$sel:items:CacheBehaviors' :: CacheBehaviors -> Maybe [CacheBehavior]
items} -> Maybe [CacheBehavior]
items) (\s :: CacheBehaviors
s@CacheBehaviors' {} Maybe [CacheBehavior]
a -> CacheBehaviors
s {$sel:items:CacheBehaviors' :: Maybe [CacheBehavior]
items = Maybe [CacheBehavior]
a} :: CacheBehaviors) ((Maybe [CacheBehavior] -> f (Maybe [CacheBehavior]))
 -> CacheBehaviors -> f CacheBehaviors)
-> ((Maybe [CacheBehavior] -> f (Maybe [CacheBehavior]))
    -> Maybe [CacheBehavior] -> f (Maybe [CacheBehavior]))
-> (Maybe [CacheBehavior] -> f (Maybe [CacheBehavior]))
-> CacheBehaviors
-> f CacheBehaviors
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [CacheBehavior] [CacheBehavior] [CacheBehavior] [CacheBehavior]
-> Iso
     (Maybe [CacheBehavior])
     (Maybe [CacheBehavior])
     (Maybe [CacheBehavior])
     (Maybe [CacheBehavior])
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 AnIso
  [CacheBehavior] [CacheBehavior] [CacheBehavior] [CacheBehavior]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of cache behaviors for this distribution.
cacheBehaviors_quantity :: Lens.Lens' CacheBehaviors Prelude.Int
cacheBehaviors_quantity :: (Int -> f Int) -> CacheBehaviors -> f CacheBehaviors
cacheBehaviors_quantity = (CacheBehaviors -> Int)
-> (CacheBehaviors -> Int -> CacheBehaviors)
-> Lens CacheBehaviors CacheBehaviors Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CacheBehaviors' {Int
quantity :: Int
$sel:quantity:CacheBehaviors' :: CacheBehaviors -> Int
quantity} -> Int
quantity) (\s :: CacheBehaviors
s@CacheBehaviors' {} Int
a -> CacheBehaviors
s {$sel:quantity:CacheBehaviors' :: Int
quantity = Int
a} :: CacheBehaviors)

instance Core.FromXML CacheBehaviors where
  parseXML :: [Node] -> Either String CacheBehaviors
parseXML [Node]
x =
    Maybe [CacheBehavior] -> Int -> CacheBehaviors
CacheBehaviors'
      (Maybe [CacheBehavior] -> Int -> CacheBehaviors)
-> Either String (Maybe [CacheBehavior])
-> Either String (Int -> CacheBehaviors)
forall (f :: * -> *) a b. Functor 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 (Maybe [CacheBehavior]))
-> Either String (Maybe [CacheBehavior])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [CacheBehavior])
-> [Node] -> Either String (Maybe [CacheBehavior])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [CacheBehavior]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"CacheBehavior")
                  )
      Either String (Int -> CacheBehaviors)
-> Either String Int -> Either String CacheBehaviors
forall (f :: * -> *) a b. Applicative f => 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")

instance Prelude.Hashable CacheBehaviors

instance Prelude.NFData CacheBehaviors

instance Core.ToXML CacheBehaviors where
  toXML :: CacheBehaviors -> XML
toXML CacheBehaviors' {Int
Maybe [CacheBehavior]
quantity :: Int
items :: Maybe [CacheBehavior]
$sel:quantity:CacheBehaviors' :: CacheBehaviors -> Int
$sel:items:CacheBehaviors' :: CacheBehaviors -> Maybe [CacheBehavior]
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML
            (Name -> [CacheBehavior] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"CacheBehavior" ([CacheBehavior] -> XML) -> Maybe [CacheBehavior] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CacheBehavior]
items),
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]