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

import Amazonka.CloudFront.Types.OriginCustomHeader
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 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
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, Int -> CustomHeaders -> ShowS
[CustomHeaders] -> ShowS
CustomHeaders -> String
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. 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'
    { $sel:items:CustomHeaders' :: Maybe [OriginCustomHeader]
items = 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 :: Lens' CustomHeaders (Maybe [OriginCustomHeader])
customHeaders_items = 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) 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 custom headers, if any, for this distribution.
customHeaders_quantity :: Lens.Lens' CustomHeaders Prelude.Int
customHeaders_quantity :: Lens' CustomHeaders Int
customHeaders_quantity = 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 Data.FromXML CustomHeaders where
  parseXML :: [Node] -> Either String CustomHeaders
parseXML [Node]
x =
    Maybe [OriginCustomHeader] -> Int -> CustomHeaders
CustomHeaders'
      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
"OriginCustomHeader")
                  )
      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 CustomHeaders where
  hashWithSalt :: Int -> CustomHeaders -> Int
hashWithSalt Int
_salt CustomHeaders' {Int
Maybe [OriginCustomHeader]
quantity :: Int
items :: Maybe [OriginCustomHeader]
$sel:quantity:CustomHeaders' :: CustomHeaders -> Int
$sel:items:CustomHeaders' :: CustomHeaders -> Maybe [OriginCustomHeader]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [OriginCustomHeader]
items
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
quantity

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

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