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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains a list of HTTP header names.
--
-- /See:/ 'newHeaders' smart constructor.
data Headers = Headers'
  { -- | A list of HTTP header names.
    Headers -> Maybe [Text]
items :: Prelude.Maybe [Prelude.Text],
    -- | The number of header names in the @Items@ list.
    Headers -> Int
quantity :: Prelude.Int
  }
  deriving (Headers -> Headers -> Bool
(Headers -> Headers -> Bool)
-> (Headers -> Headers -> Bool) -> Eq Headers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Headers -> Headers -> Bool
$c/= :: Headers -> Headers -> Bool
== :: Headers -> Headers -> Bool
$c== :: Headers -> Headers -> Bool
Prelude.Eq, ReadPrec [Headers]
ReadPrec Headers
Int -> ReadS Headers
ReadS [Headers]
(Int -> ReadS Headers)
-> ReadS [Headers]
-> ReadPrec Headers
-> ReadPrec [Headers]
-> Read Headers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Headers]
$creadListPrec :: ReadPrec [Headers]
readPrec :: ReadPrec Headers
$creadPrec :: ReadPrec Headers
readList :: ReadS [Headers]
$creadList :: ReadS [Headers]
readsPrec :: Int -> ReadS Headers
$creadsPrec :: Int -> ReadS Headers
Prelude.Read, Int -> Headers -> ShowS
[Headers] -> ShowS
Headers -> String
(Int -> Headers -> ShowS)
-> (Headers -> String) -> ([Headers] -> ShowS) -> Show Headers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Headers] -> ShowS
$cshowList :: [Headers] -> ShowS
show :: Headers -> String
$cshow :: Headers -> String
showsPrec :: Int -> Headers -> ShowS
$cshowsPrec :: Int -> Headers -> ShowS
Prelude.Show, (forall x. Headers -> Rep Headers x)
-> (forall x. Rep Headers x -> Headers) -> Generic Headers
forall x. Rep Headers x -> Headers
forall x. Headers -> Rep Headers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Headers x -> Headers
$cfrom :: forall x. Headers -> Rep Headers x
Prelude.Generic)

-- |
-- Create a value of 'Headers' 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', 'headers_items' - A list of HTTP header names.
--
-- 'quantity', 'headers_quantity' - The number of header names in the @Items@ list.
newHeaders ::
  -- | 'quantity'
  Prelude.Int ->
  Headers
newHeaders :: Int -> Headers
newHeaders Int
pQuantity_ =
  Headers' :: Maybe [Text] -> Int -> Headers
Headers'
    { $sel:items:Headers' :: Maybe [Text]
items = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:Headers' :: Int
quantity = Int
pQuantity_
    }

-- | A list of HTTP header names.
headers_items :: Lens.Lens' Headers (Prelude.Maybe [Prelude.Text])
headers_items :: (Maybe [Text] -> f (Maybe [Text])) -> Headers -> f Headers
headers_items = (Headers -> Maybe [Text])
-> (Headers -> Maybe [Text] -> Headers)
-> Lens Headers Headers (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Headers' {Maybe [Text]
items :: Maybe [Text]
$sel:items:Headers' :: Headers -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: Headers
s@Headers' {} Maybe [Text]
a -> Headers
s {$sel:items:Headers' :: Maybe [Text]
items = Maybe [Text]
a} :: Headers) ((Maybe [Text] -> f (Maybe [Text])) -> Headers -> f Headers)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Headers
-> f Headers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of header names in the @Items@ list.
headers_quantity :: Lens.Lens' Headers Prelude.Int
headers_quantity :: (Int -> f Int) -> Headers -> f Headers
headers_quantity = (Headers -> Int)
-> (Headers -> Int -> Headers) -> Lens Headers Headers Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Headers' {Int
quantity :: Int
$sel:quantity:Headers' :: Headers -> Int
quantity} -> Int
quantity) (\s :: Headers
s@Headers' {} Int
a -> Headers
s {$sel:quantity:Headers' :: Int
quantity = Int
a} :: Headers)

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

instance Prelude.NFData Headers

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