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

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

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

-- |
-- Create a value of 'CookieNames' 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', 'cookieNames_items' - A list of cookie names.
--
-- 'quantity', 'cookieNames_quantity' - The number of cookie names in the @Items@ list.
newCookieNames ::
  -- | 'quantity'
  Prelude.Int ->
  CookieNames
newCookieNames :: Int -> CookieNames
newCookieNames Int
pQuantity_ =
  CookieNames' :: Maybe [Text] -> Int -> CookieNames
CookieNames'
    { $sel:items:CookieNames' :: Maybe [Text]
items = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:CookieNames' :: Int
quantity = Int
pQuantity_
    }

-- | A list of cookie names.
cookieNames_items :: Lens.Lens' CookieNames (Prelude.Maybe [Prelude.Text])
cookieNames_items :: (Maybe [Text] -> f (Maybe [Text])) -> CookieNames -> f CookieNames
cookieNames_items = (CookieNames -> Maybe [Text])
-> (CookieNames -> Maybe [Text] -> CookieNames)
-> Lens CookieNames CookieNames (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieNames' {Maybe [Text]
items :: Maybe [Text]
$sel:items:CookieNames' :: CookieNames -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: CookieNames
s@CookieNames' {} Maybe [Text]
a -> CookieNames
s {$sel:items:CookieNames' :: Maybe [Text]
items = Maybe [Text]
a} :: CookieNames) ((Maybe [Text] -> f (Maybe [Text]))
 -> CookieNames -> f CookieNames)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CookieNames
-> f CookieNames
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 cookie names in the @Items@ list.
cookieNames_quantity :: Lens.Lens' CookieNames Prelude.Int
cookieNames_quantity :: (Int -> f Int) -> CookieNames -> f CookieNames
cookieNames_quantity = (CookieNames -> Int)
-> (CookieNames -> Int -> CookieNames)
-> Lens CookieNames CookieNames Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieNames' {Int
quantity :: Int
$sel:quantity:CookieNames' :: CookieNames -> Int
quantity} -> Int
quantity) (\s :: CookieNames
s@CookieNames' {} Int
a -> CookieNames
s {$sel:quantity:CookieNames' :: Int
quantity = Int
a} :: CookieNames)

instance Core.FromXML CookieNames where
  parseXML :: [Node] -> Either String CookieNames
parseXML [Node]
x =
    Maybe [Text] -> Int -> CookieNames
CookieNames'
      (Maybe [Text] -> Int -> CookieNames)
-> Either String (Maybe [Text])
-> Either String (Int -> CookieNames)
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 -> CookieNames)
-> Either String Int -> Either String CookieNames
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 CookieNames

instance Prelude.NFData CookieNames

instance Core.ToXML CookieNames where
  toXML :: CookieNames -> XML
toXML CookieNames' {Int
Maybe [Text]
quantity :: Int
items :: Maybe [Text]
$sel:quantity:CookieNames' :: CookieNames -> Int
$sel:items:CookieNames' :: CookieNames -> 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
      ]