{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:items:OriginGroups' :: Maybe [OriginGroup]
items = 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 :: Lens' OriginGroups (Maybe [OriginGroup])
originGroups_items = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' OriginGroups Int
originGroups_quantity = 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 Data.FromXML OriginGroups where
  parseXML :: [Node] -> Either String OriginGroups
parseXML [Node]
x =
    Maybe [OriginGroup] -> Int -> OriginGroups
OriginGroups'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Items"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"OriginGroup")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Quantity")

instance Prelude.Hashable OriginGroups where
  hashWithSalt :: Int -> OriginGroups -> Int
hashWithSalt Int
_salt OriginGroups' {Int
Maybe [OriginGroup]
quantity :: Int
items :: Maybe [OriginGroup]
$sel:quantity:OriginGroups' :: OriginGroups -> Int
$sel:items:OriginGroups' :: OriginGroups -> Maybe [OriginGroup]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [OriginGroup]
items
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
quantity

instance Prelude.NFData OriginGroups where
  rnf :: OriginGroups -> ()
rnf OriginGroups' {Int
Maybe [OriginGroup]
quantity :: Int
items :: Maybe [OriginGroup]
$sel:quantity:OriginGroups' :: OriginGroups -> Int
$sel:items:OriginGroups' :: OriginGroups -> Maybe [OriginGroup]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [OriginGroup]
items
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
quantity

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