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

import Amazonka.CloudFront.Types.CacheBehavior
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 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
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]
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
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. 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'
    { $sel:items:CacheBehaviors' :: Maybe [CacheBehavior]
items = 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 :: Lens' CacheBehaviors (Maybe [CacheBehavior])
cacheBehaviors_items = 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) 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

-- | The number of cache behaviors for this distribution.
cacheBehaviors_quantity :: Lens.Lens' CacheBehaviors Prelude.Int
cacheBehaviors_quantity :: Lens' CacheBehaviors Int
cacheBehaviors_quantity = 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 Data.FromXML CacheBehaviors where
  parseXML :: [Node] -> Either String CacheBehaviors
parseXML [Node]
x =
    Maybe [CacheBehavior] -> Int -> CacheBehaviors
CacheBehaviors'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Items"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"CacheBehavior")
                  )
      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
"Quantity")

instance Prelude.Hashable CacheBehaviors where
  hashWithSalt :: Int -> CacheBehaviors -> Int
hashWithSalt Int
_salt CacheBehaviors' {Int
Maybe [CacheBehavior]
quantity :: Int
items :: Maybe [CacheBehavior]
$sel:quantity:CacheBehaviors' :: CacheBehaviors -> Int
$sel:items:CacheBehaviors' :: CacheBehaviors -> Maybe [CacheBehavior]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [CacheBehavior]
items
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
quantity

instance Prelude.NFData CacheBehaviors where
  rnf :: CacheBehaviors -> ()
rnf CacheBehaviors' {Int
Maybe [CacheBehavior]
quantity :: Int
items :: Maybe [CacheBehavior]
$sel:quantity:CacheBehaviors' :: CacheBehaviors -> Int
$sel:items:CacheBehaviors' :: CacheBehaviors -> Maybe [CacheBehavior]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [CacheBehavior]
items
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
quantity

instance Data.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]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          forall a. ToXML a => Name -> a -> XML
Data.@= forall a. ToXML a => a -> XML
Data.toXML
            (forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"CacheBehavior" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CacheBehavior]
items),
        Name
"Quantity" forall a. ToXML a => Name -> a -> XML
Data.@= Int
quantity
      ]