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

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

-- | Contains information about the origins for this distribution.
--
-- /See:/ 'newOrigins' smart constructor.
data Origins = Origins'
  { -- | The number of origins for this distribution.
    Origins -> Int
quantity :: Prelude.Int,
    -- | A list of origins.
    Origins -> NonEmpty Origin
items :: Prelude.NonEmpty Origin
  }
  deriving (Origins -> Origins -> Bool
(Origins -> Origins -> Bool)
-> (Origins -> Origins -> Bool) -> Eq Origins
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Origins -> Origins -> Bool
$c/= :: Origins -> Origins -> Bool
== :: Origins -> Origins -> Bool
$c== :: Origins -> Origins -> Bool
Prelude.Eq, ReadPrec [Origins]
ReadPrec Origins
Int -> ReadS Origins
ReadS [Origins]
(Int -> ReadS Origins)
-> ReadS [Origins]
-> ReadPrec Origins
-> ReadPrec [Origins]
-> Read Origins
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Origins]
$creadListPrec :: ReadPrec [Origins]
readPrec :: ReadPrec Origins
$creadPrec :: ReadPrec Origins
readList :: ReadS [Origins]
$creadList :: ReadS [Origins]
readsPrec :: Int -> ReadS Origins
$creadsPrec :: Int -> ReadS Origins
Prelude.Read, Int -> Origins -> ShowS
[Origins] -> ShowS
Origins -> String
(Int -> Origins -> ShowS)
-> (Origins -> String) -> ([Origins] -> ShowS) -> Show Origins
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Origins] -> ShowS
$cshowList :: [Origins] -> ShowS
show :: Origins -> String
$cshow :: Origins -> String
showsPrec :: Int -> Origins -> ShowS
$cshowsPrec :: Int -> Origins -> ShowS
Prelude.Show, (forall x. Origins -> Rep Origins x)
-> (forall x. Rep Origins x -> Origins) -> Generic Origins
forall x. Rep Origins x -> Origins
forall x. Origins -> Rep Origins x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Origins x -> Origins
$cfrom :: forall x. Origins -> Rep Origins x
Prelude.Generic)

-- |
-- Create a value of 'Origins' 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:
--
-- 'quantity', 'origins_quantity' - The number of origins for this distribution.
--
-- 'items', 'origins_items' - A list of origins.
newOrigins ::
  -- | 'quantity'
  Prelude.Int ->
  -- | 'items'
  Prelude.NonEmpty Origin ->
  Origins
newOrigins :: Int -> NonEmpty Origin -> Origins
newOrigins Int
pQuantity_ NonEmpty Origin
pItems_ =
  Origins' :: Int -> NonEmpty Origin -> Origins
Origins'
    { $sel:quantity:Origins' :: Int
quantity = Int
pQuantity_,
      $sel:items:Origins' :: NonEmpty Origin
items = Tagged (NonEmpty Origin) (Identity (NonEmpty Origin))
-> Tagged (NonEmpty Origin) (Identity (NonEmpty Origin))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Origin) (Identity (NonEmpty Origin))
 -> Tagged (NonEmpty Origin) (Identity (NonEmpty Origin)))
-> NonEmpty Origin -> NonEmpty Origin
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Origin
pItems_
    }

-- | The number of origins for this distribution.
origins_quantity :: Lens.Lens' Origins Prelude.Int
origins_quantity :: (Int -> f Int) -> Origins -> f Origins
origins_quantity = (Origins -> Int)
-> (Origins -> Int -> Origins) -> Lens Origins Origins Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Origins' {Int
quantity :: Int
$sel:quantity:Origins' :: Origins -> Int
quantity} -> Int
quantity) (\s :: Origins
s@Origins' {} Int
a -> Origins
s {$sel:quantity:Origins' :: Int
quantity = Int
a} :: Origins)

-- | A list of origins.
origins_items :: Lens.Lens' Origins (Prelude.NonEmpty Origin)
origins_items :: (NonEmpty Origin -> f (NonEmpty Origin)) -> Origins -> f Origins
origins_items = (Origins -> NonEmpty Origin)
-> (Origins -> NonEmpty Origin -> Origins)
-> Lens Origins Origins (NonEmpty Origin) (NonEmpty Origin)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Origins' {NonEmpty Origin
items :: NonEmpty Origin
$sel:items:Origins' :: Origins -> NonEmpty Origin
items} -> NonEmpty Origin
items) (\s :: Origins
s@Origins' {} NonEmpty Origin
a -> Origins
s {$sel:items:Origins' :: NonEmpty Origin
items = NonEmpty Origin
a} :: Origins) ((NonEmpty Origin -> f (NonEmpty Origin)) -> Origins -> f Origins)
-> ((NonEmpty Origin -> f (NonEmpty Origin))
    -> NonEmpty Origin -> f (NonEmpty Origin))
-> (NonEmpty Origin -> f (NonEmpty Origin))
-> Origins
-> f Origins
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Origin -> f (NonEmpty Origin))
-> NonEmpty Origin -> f (NonEmpty Origin)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML Origins where
  parseXML :: [Node] -> Either String Origins
parseXML [Node]
x =
    Int -> NonEmpty Origin -> Origins
Origins'
      (Int -> NonEmpty Origin -> Origins)
-> Either String Int -> Either String (NonEmpty Origin -> Origins)
forall (f :: * -> *) a b. Functor 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")
      Either String (NonEmpty Origin -> Origins)
-> Either String (NonEmpty Origin) -> Either String Origins
forall (f :: * -> *) a b. Applicative f => 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 (NonEmpty Origin))
-> Either String (NonEmpty Origin)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String (NonEmpty Origin)
forall a. FromXML a => Text -> [Node] -> Either String (NonEmpty a)
Core.parseXMLList1 Text
"Origin"
                  )

instance Prelude.Hashable Origins

instance Prelude.NFData Origins

instance Core.ToXML Origins where
  toXML :: Origins -> XML
toXML Origins' {Int
NonEmpty Origin
items :: NonEmpty Origin
quantity :: Int
$sel:items:Origins' :: Origins -> NonEmpty Origin
$sel:quantity:Origins' :: Origins -> Int
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity,
        Name
"Items" Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Name -> NonEmpty Origin -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Origin" NonEmpty Origin
items
      ]