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

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

-- | A complex type that contains the list of Custom Headers for each origin.
--
-- /See:/ 'newCustomHeaders' smart constructor.
data CustomHeaders = CustomHeaders'
  { -- | __Optional__: A list that contains one @OriginCustomHeader@ element for
    -- each custom header that you want CloudFront to forward to the origin. If
    -- Quantity is @0@, omit @Items@.
    CustomHeaders -> Maybe [OriginCustomHeader]
items :: Prelude.Maybe [OriginCustomHeader],
    -- | The number of custom headers, if any, for this distribution.
    CustomHeaders -> Int
quantity :: Prelude.Int
  }
  deriving (CustomHeaders -> CustomHeaders -> Bool
(CustomHeaders -> CustomHeaders -> Bool)
-> (CustomHeaders -> CustomHeaders -> Bool) -> Eq CustomHeaders
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomHeaders -> CustomHeaders -> Bool
$c/= :: CustomHeaders -> CustomHeaders -> Bool
== :: CustomHeaders -> CustomHeaders -> Bool
$c== :: CustomHeaders -> CustomHeaders -> Bool
Prelude.Eq, ReadPrec [CustomHeaders]
ReadPrec CustomHeaders
Int -> ReadS CustomHeaders
ReadS [CustomHeaders]
(Int -> ReadS CustomHeaders)
-> ReadS [CustomHeaders]
-> ReadPrec CustomHeaders
-> ReadPrec [CustomHeaders]
-> Read CustomHeaders
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomHeaders]
$creadListPrec :: ReadPrec [CustomHeaders]
readPrec :: ReadPrec CustomHeaders
$creadPrec :: ReadPrec CustomHeaders
readList :: ReadS [CustomHeaders]
$creadList :: ReadS [CustomHeaders]
readsPrec :: Int -> ReadS CustomHeaders
$creadsPrec :: Int -> ReadS CustomHeaders
Prelude.Read, Int -> CustomHeaders -> ShowS
[CustomHeaders] -> ShowS
CustomHeaders -> String
(Int -> CustomHeaders -> ShowS)
-> (CustomHeaders -> String)
-> ([CustomHeaders] -> ShowS)
-> Show CustomHeaders
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomHeaders] -> ShowS
$cshowList :: [CustomHeaders] -> ShowS
show :: CustomHeaders -> String
$cshow :: CustomHeaders -> String
showsPrec :: Int -> CustomHeaders -> ShowS
$cshowsPrec :: Int -> CustomHeaders -> ShowS
Prelude.Show, (forall x. CustomHeaders -> Rep CustomHeaders x)
-> (forall x. Rep CustomHeaders x -> CustomHeaders)
-> Generic CustomHeaders
forall x. Rep CustomHeaders x -> CustomHeaders
forall x. CustomHeaders -> Rep CustomHeaders x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomHeaders x -> CustomHeaders
$cfrom :: forall x. CustomHeaders -> Rep CustomHeaders x
Prelude.Generic)

-- |
-- Create a value of 'CustomHeaders' 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', 'customHeaders_items' - __Optional__: A list that contains one @OriginCustomHeader@ element for
-- each custom header that you want CloudFront to forward to the origin. If
-- Quantity is @0@, omit @Items@.
--
-- 'quantity', 'customHeaders_quantity' - The number of custom headers, if any, for this distribution.
newCustomHeaders ::
  -- | 'quantity'
  Prelude.Int ->
  CustomHeaders
newCustomHeaders :: Int -> CustomHeaders
newCustomHeaders Int
pQuantity_ =
  CustomHeaders' :: Maybe [OriginCustomHeader] -> Int -> CustomHeaders
CustomHeaders'
    { $sel:items:CustomHeaders' :: Maybe [OriginCustomHeader]
items = Maybe [OriginCustomHeader]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:CustomHeaders' :: Int
quantity = Int
pQuantity_
    }

-- | __Optional__: A list that contains one @OriginCustomHeader@ element for
-- each custom header that you want CloudFront to forward to the origin. If
-- Quantity is @0@, omit @Items@.
customHeaders_items :: Lens.Lens' CustomHeaders (Prelude.Maybe [OriginCustomHeader])
customHeaders_items :: (Maybe [OriginCustomHeader] -> f (Maybe [OriginCustomHeader]))
-> CustomHeaders -> f CustomHeaders
customHeaders_items = (CustomHeaders -> Maybe [OriginCustomHeader])
-> (CustomHeaders -> Maybe [OriginCustomHeader] -> CustomHeaders)
-> Lens
     CustomHeaders
     CustomHeaders
     (Maybe [OriginCustomHeader])
     (Maybe [OriginCustomHeader])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomHeaders' {Maybe [OriginCustomHeader]
items :: Maybe [OriginCustomHeader]
$sel:items:CustomHeaders' :: CustomHeaders -> Maybe [OriginCustomHeader]
items} -> Maybe [OriginCustomHeader]
items) (\s :: CustomHeaders
s@CustomHeaders' {} Maybe [OriginCustomHeader]
a -> CustomHeaders
s {$sel:items:CustomHeaders' :: Maybe [OriginCustomHeader]
items = Maybe [OriginCustomHeader]
a} :: CustomHeaders) ((Maybe [OriginCustomHeader] -> f (Maybe [OriginCustomHeader]))
 -> CustomHeaders -> f CustomHeaders)
-> ((Maybe [OriginCustomHeader] -> f (Maybe [OriginCustomHeader]))
    -> Maybe [OriginCustomHeader] -> f (Maybe [OriginCustomHeader]))
-> (Maybe [OriginCustomHeader] -> f (Maybe [OriginCustomHeader]))
-> CustomHeaders
-> f CustomHeaders
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [OriginCustomHeader]
  [OriginCustomHeader]
  [OriginCustomHeader]
  [OriginCustomHeader]
-> Iso
     (Maybe [OriginCustomHeader])
     (Maybe [OriginCustomHeader])
     (Maybe [OriginCustomHeader])
     (Maybe [OriginCustomHeader])
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
  [OriginCustomHeader]
  [OriginCustomHeader]
  [OriginCustomHeader]
  [OriginCustomHeader]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of custom headers, if any, for this distribution.
customHeaders_quantity :: Lens.Lens' CustomHeaders Prelude.Int
customHeaders_quantity :: (Int -> f Int) -> CustomHeaders -> f CustomHeaders
customHeaders_quantity = (CustomHeaders -> Int)
-> (CustomHeaders -> Int -> CustomHeaders)
-> Lens CustomHeaders CustomHeaders Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomHeaders' {Int
quantity :: Int
$sel:quantity:CustomHeaders' :: CustomHeaders -> Int
quantity} -> Int
quantity) (\s :: CustomHeaders
s@CustomHeaders' {} Int
a -> CustomHeaders
s {$sel:quantity:CustomHeaders' :: Int
quantity = Int
a} :: CustomHeaders)

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

instance Prelude.NFData CustomHeaders

instance Core.ToXML CustomHeaders where
  toXML :: CustomHeaders -> XML
toXML CustomHeaders' {Int
Maybe [OriginCustomHeader]
quantity :: Int
items :: Maybe [OriginCustomHeader]
$sel:quantity:CustomHeaders' :: CustomHeaders -> Int
$sel:items:CustomHeaders' :: CustomHeaders -> Maybe [OriginCustomHeader]
..} =
    [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 -> [OriginCustomHeader] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"OriginCustomHeader"
                ([OriginCustomHeader] -> XML)
-> Maybe [OriginCustomHeader] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [OriginCustomHeader]
items
            ),
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]