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

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

-- | A complex type that contains information about CNAMEs (alternate domain
-- names), if any, for this distribution.
--
-- /See:/ 'newAliases' smart constructor.
data Aliases = Aliases'
  { -- | A complex type that contains the CNAME aliases, if any, that you want to
    -- associate with this distribution.
    Aliases -> Maybe [Text]
items :: Prelude.Maybe [Prelude.Text],
    -- | The number of CNAME aliases, if any, that you want to associate with
    -- this distribution.
    Aliases -> Int
quantity :: Prelude.Int
  }
  deriving (Aliases -> Aliases -> Bool
(Aliases -> Aliases -> Bool)
-> (Aliases -> Aliases -> Bool) -> Eq Aliases
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Aliases -> Aliases -> Bool
$c/= :: Aliases -> Aliases -> Bool
== :: Aliases -> Aliases -> Bool
$c== :: Aliases -> Aliases -> Bool
Prelude.Eq, ReadPrec [Aliases]
ReadPrec Aliases
Int -> ReadS Aliases
ReadS [Aliases]
(Int -> ReadS Aliases)
-> ReadS [Aliases]
-> ReadPrec Aliases
-> ReadPrec [Aliases]
-> Read Aliases
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Aliases]
$creadListPrec :: ReadPrec [Aliases]
readPrec :: ReadPrec Aliases
$creadPrec :: ReadPrec Aliases
readList :: ReadS [Aliases]
$creadList :: ReadS [Aliases]
readsPrec :: Int -> ReadS Aliases
$creadsPrec :: Int -> ReadS Aliases
Prelude.Read, Int -> Aliases -> ShowS
[Aliases] -> ShowS
Aliases -> String
(Int -> Aliases -> ShowS)
-> (Aliases -> String) -> ([Aliases] -> ShowS) -> Show Aliases
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Aliases] -> ShowS
$cshowList :: [Aliases] -> ShowS
show :: Aliases -> String
$cshow :: Aliases -> String
showsPrec :: Int -> Aliases -> ShowS
$cshowsPrec :: Int -> Aliases -> ShowS
Prelude.Show, (forall x. Aliases -> Rep Aliases x)
-> (forall x. Rep Aliases x -> Aliases) -> Generic Aliases
forall x. Rep Aliases x -> Aliases
forall x. Aliases -> Rep Aliases x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Aliases x -> Aliases
$cfrom :: forall x. Aliases -> Rep Aliases x
Prelude.Generic)

-- |
-- Create a value of 'Aliases' 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', 'aliases_items' - A complex type that contains the CNAME aliases, if any, that you want to
-- associate with this distribution.
--
-- 'quantity', 'aliases_quantity' - The number of CNAME aliases, if any, that you want to associate with
-- this distribution.
newAliases ::
  -- | 'quantity'
  Prelude.Int ->
  Aliases
newAliases :: Int -> Aliases
newAliases Int
pQuantity_ =
  Aliases' :: Maybe [Text] -> Int -> Aliases
Aliases'
    { $sel:items:Aliases' :: Maybe [Text]
items = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:Aliases' :: Int
quantity = Int
pQuantity_
    }

-- | A complex type that contains the CNAME aliases, if any, that you want to
-- associate with this distribution.
aliases_items :: Lens.Lens' Aliases (Prelude.Maybe [Prelude.Text])
aliases_items :: (Maybe [Text] -> f (Maybe [Text])) -> Aliases -> f Aliases
aliases_items = (Aliases -> Maybe [Text])
-> (Aliases -> Maybe [Text] -> Aliases)
-> Lens Aliases Aliases (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Aliases' {Maybe [Text]
items :: Maybe [Text]
$sel:items:Aliases' :: Aliases -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: Aliases
s@Aliases' {} Maybe [Text]
a -> Aliases
s {$sel:items:Aliases' :: Maybe [Text]
items = Maybe [Text]
a} :: Aliases) ((Maybe [Text] -> f (Maybe [Text])) -> Aliases -> f Aliases)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Aliases
-> f Aliases
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 CNAME aliases, if any, that you want to associate with
-- this distribution.
aliases_quantity :: Lens.Lens' Aliases Prelude.Int
aliases_quantity :: (Int -> f Int) -> Aliases -> f Aliases
aliases_quantity = (Aliases -> Int)
-> (Aliases -> Int -> Aliases) -> Lens Aliases Aliases Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Aliases' {Int
quantity :: Int
$sel:quantity:Aliases' :: Aliases -> Int
quantity} -> Int
quantity) (\s :: Aliases
s@Aliases' {} Int
a -> Aliases
s {$sel:quantity:Aliases' :: Int
quantity = Int
a} :: Aliases)

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

instance Prelude.NFData Aliases

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