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

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

-- | A complex data type for the origin groups specified for a distribution.
--
-- /See:/ 'newOriginGroups' smart constructor.
data OriginGroups = OriginGroups'
  { -- | The items (origin groups) in a distribution.
    OriginGroups -> Maybe [OriginGroup]
items :: Prelude.Maybe [OriginGroup],
    -- | The number of origin groups.
    OriginGroups -> Int
quantity :: Prelude.Int
  }
  deriving (OriginGroups -> OriginGroups -> Bool
(OriginGroups -> OriginGroups -> Bool)
-> (OriginGroups -> OriginGroups -> Bool) -> Eq OriginGroups
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginGroups -> OriginGroups -> Bool
$c/= :: OriginGroups -> OriginGroups -> Bool
== :: OriginGroups -> OriginGroups -> Bool
$c== :: OriginGroups -> OriginGroups -> Bool
Prelude.Eq, ReadPrec [OriginGroups]
ReadPrec OriginGroups
Int -> ReadS OriginGroups
ReadS [OriginGroups]
(Int -> ReadS OriginGroups)
-> ReadS [OriginGroups]
-> ReadPrec OriginGroups
-> ReadPrec [OriginGroups]
-> Read OriginGroups
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginGroups]
$creadListPrec :: ReadPrec [OriginGroups]
readPrec :: ReadPrec OriginGroups
$creadPrec :: ReadPrec OriginGroups
readList :: ReadS [OriginGroups]
$creadList :: ReadS [OriginGroups]
readsPrec :: Int -> ReadS OriginGroups
$creadsPrec :: Int -> ReadS OriginGroups
Prelude.Read, Int -> OriginGroups -> ShowS
[OriginGroups] -> ShowS
OriginGroups -> String
(Int -> OriginGroups -> ShowS)
-> (OriginGroups -> String)
-> ([OriginGroups] -> ShowS)
-> Show OriginGroups
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginGroups] -> ShowS
$cshowList :: [OriginGroups] -> ShowS
show :: OriginGroups -> String
$cshow :: OriginGroups -> String
showsPrec :: Int -> OriginGroups -> ShowS
$cshowsPrec :: Int -> OriginGroups -> ShowS
Prelude.Show, (forall x. OriginGroups -> Rep OriginGroups x)
-> (forall x. Rep OriginGroups x -> OriginGroups)
-> Generic OriginGroups
forall x. Rep OriginGroups x -> OriginGroups
forall x. OriginGroups -> Rep OriginGroups x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OriginGroups x -> OriginGroups
$cfrom :: forall x. OriginGroups -> Rep OriginGroups x
Prelude.Generic)

-- |
-- Create a value of 'OriginGroups' 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', 'originGroups_items' - The items (origin groups) in a distribution.
--
-- 'quantity', 'originGroups_quantity' - The number of origin groups.
newOriginGroups ::
  -- | 'quantity'
  Prelude.Int ->
  OriginGroups
newOriginGroups :: Int -> OriginGroups
newOriginGroups Int
pQuantity_ =
  OriginGroups' :: Maybe [OriginGroup] -> Int -> OriginGroups
OriginGroups'
    { $sel:items:OriginGroups' :: Maybe [OriginGroup]
items = Maybe [OriginGroup]
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:OriginGroups' :: Int
quantity = Int
pQuantity_
    }

-- | The items (origin groups) in a distribution.
originGroups_items :: Lens.Lens' OriginGroups (Prelude.Maybe [OriginGroup])
originGroups_items :: (Maybe [OriginGroup] -> f (Maybe [OriginGroup]))
-> OriginGroups -> f OriginGroups
originGroups_items = (OriginGroups -> Maybe [OriginGroup])
-> (OriginGroups -> Maybe [OriginGroup] -> OriginGroups)
-> Lens
     OriginGroups
     OriginGroups
     (Maybe [OriginGroup])
     (Maybe [OriginGroup])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginGroups' {Maybe [OriginGroup]
items :: Maybe [OriginGroup]
$sel:items:OriginGroups' :: OriginGroups -> Maybe [OriginGroup]
items} -> Maybe [OriginGroup]
items) (\s :: OriginGroups
s@OriginGroups' {} Maybe [OriginGroup]
a -> OriginGroups
s {$sel:items:OriginGroups' :: Maybe [OriginGroup]
items = Maybe [OriginGroup]
a} :: OriginGroups) ((Maybe [OriginGroup] -> f (Maybe [OriginGroup]))
 -> OriginGroups -> f OriginGroups)
-> ((Maybe [OriginGroup] -> f (Maybe [OriginGroup]))
    -> Maybe [OriginGroup] -> f (Maybe [OriginGroup]))
-> (Maybe [OriginGroup] -> f (Maybe [OriginGroup]))
-> OriginGroups
-> f OriginGroups
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [OriginGroup] [OriginGroup] [OriginGroup] [OriginGroup]
-> Iso
     (Maybe [OriginGroup])
     (Maybe [OriginGroup])
     (Maybe [OriginGroup])
     (Maybe [OriginGroup])
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 [OriginGroup] [OriginGroup] [OriginGroup] [OriginGroup]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of origin groups.
originGroups_quantity :: Lens.Lens' OriginGroups Prelude.Int
originGroups_quantity :: (Int -> f Int) -> OriginGroups -> f OriginGroups
originGroups_quantity = (OriginGroups -> Int)
-> (OriginGroups -> Int -> OriginGroups)
-> Lens OriginGroups OriginGroups Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginGroups' {Int
quantity :: Int
$sel:quantity:OriginGroups' :: OriginGroups -> Int
quantity} -> Int
quantity) (\s :: OriginGroups
s@OriginGroups' {} Int
a -> OriginGroups
s {$sel:quantity:OriginGroups' :: Int
quantity = Int
a} :: OriginGroups)

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

instance Prelude.NFData OriginGroups

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