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

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

-- | A complex type that contains zero or more @Tag@ elements.
--
-- /See:/ 'newTags' smart constructor.
data Tags = Tags'
  { -- | A complex type that contains @Tag@ elements.
    Tags -> Maybe [Tag]
items :: Prelude.Maybe [Tag]
  }
  deriving (Tags -> Tags -> Bool
(Tags -> Tags -> Bool) -> (Tags -> Tags -> Bool) -> Eq Tags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tags -> Tags -> Bool
$c/= :: Tags -> Tags -> Bool
== :: Tags -> Tags -> Bool
$c== :: Tags -> Tags -> Bool
Prelude.Eq, ReadPrec [Tags]
ReadPrec Tags
Int -> ReadS Tags
ReadS [Tags]
(Int -> ReadS Tags)
-> ReadS [Tags] -> ReadPrec Tags -> ReadPrec [Tags] -> Read Tags
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Tags]
$creadListPrec :: ReadPrec [Tags]
readPrec :: ReadPrec Tags
$creadPrec :: ReadPrec Tags
readList :: ReadS [Tags]
$creadList :: ReadS [Tags]
readsPrec :: Int -> ReadS Tags
$creadsPrec :: Int -> ReadS Tags
Prelude.Read, Int -> Tags -> ShowS
[Tags] -> ShowS
Tags -> String
(Int -> Tags -> ShowS)
-> (Tags -> String) -> ([Tags] -> ShowS) -> Show Tags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tags] -> ShowS
$cshowList :: [Tags] -> ShowS
show :: Tags -> String
$cshow :: Tags -> String
showsPrec :: Int -> Tags -> ShowS
$cshowsPrec :: Int -> Tags -> ShowS
Prelude.Show, (forall x. Tags -> Rep Tags x)
-> (forall x. Rep Tags x -> Tags) -> Generic Tags
forall x. Rep Tags x -> Tags
forall x. Tags -> Rep Tags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Tags x -> Tags
$cfrom :: forall x. Tags -> Rep Tags x
Prelude.Generic)

-- |
-- Create a value of 'Tags' 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', 'tags_items' - A complex type that contains @Tag@ elements.
newTags ::
  Tags
newTags :: Tags
newTags = Tags' :: Maybe [Tag] -> Tags
Tags' {$sel:items:Tags' :: Maybe [Tag]
items = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing}

-- | A complex type that contains @Tag@ elements.
tags_items :: Lens.Lens' Tags (Prelude.Maybe [Tag])
tags_items :: (Maybe [Tag] -> f (Maybe [Tag])) -> Tags -> f Tags
tags_items = (Tags -> Maybe [Tag])
-> (Tags -> Maybe [Tag] -> Tags)
-> Lens Tags Tags (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tags' {Maybe [Tag]
items :: Maybe [Tag]
$sel:items:Tags' :: Tags -> Maybe [Tag]
items} -> Maybe [Tag]
items) (\s :: Tags
s@Tags' {} Maybe [Tag]
a -> Tags
s {$sel:items:Tags' :: Maybe [Tag]
items = Maybe [Tag]
a} :: Tags) ((Maybe [Tag] -> f (Maybe [Tag])) -> Tags -> f Tags)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> Tags
-> f Tags
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Tags

instance Prelude.NFData Tags

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