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

import Amazonka.CloudFront.Types.OriginGroupFailoverCriteria
import Amazonka.CloudFront.Types.OriginGroupMembers
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An origin group includes two origins (a primary origin and a second
-- origin to failover to) and a failover criteria that you specify. You
-- create an origin group to support origin failover in CloudFront. When
-- you create or update a distribution, you can specifiy the origin group
-- instead of a single origin, and CloudFront will failover from the
-- primary origin to the second origin under the failover conditions that
-- you\'ve chosen.
--
-- /See:/ 'newOriginGroup' smart constructor.
data OriginGroup = OriginGroup'
  { -- | The origin group\'s ID.
    OriginGroup -> Text
id :: Prelude.Text,
    -- | A complex type that contains information about the failover criteria for
    -- an origin group.
    OriginGroup -> OriginGroupFailoverCriteria
failoverCriteria :: OriginGroupFailoverCriteria,
    -- | A complex type that contains information about the origins in an origin
    -- group.
    OriginGroup -> OriginGroupMembers
members :: OriginGroupMembers
  }
  deriving (OriginGroup -> OriginGroup -> Bool
(OriginGroup -> OriginGroup -> Bool)
-> (OriginGroup -> OriginGroup -> Bool) -> Eq OriginGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginGroup -> OriginGroup -> Bool
$c/= :: OriginGroup -> OriginGroup -> Bool
== :: OriginGroup -> OriginGroup -> Bool
$c== :: OriginGroup -> OriginGroup -> Bool
Prelude.Eq, ReadPrec [OriginGroup]
ReadPrec OriginGroup
Int -> ReadS OriginGroup
ReadS [OriginGroup]
(Int -> ReadS OriginGroup)
-> ReadS [OriginGroup]
-> ReadPrec OriginGroup
-> ReadPrec [OriginGroup]
-> Read OriginGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginGroup]
$creadListPrec :: ReadPrec [OriginGroup]
readPrec :: ReadPrec OriginGroup
$creadPrec :: ReadPrec OriginGroup
readList :: ReadS [OriginGroup]
$creadList :: ReadS [OriginGroup]
readsPrec :: Int -> ReadS OriginGroup
$creadsPrec :: Int -> ReadS OriginGroup
Prelude.Read, Int -> OriginGroup -> ShowS
[OriginGroup] -> ShowS
OriginGroup -> String
(Int -> OriginGroup -> ShowS)
-> (OriginGroup -> String)
-> ([OriginGroup] -> ShowS)
-> Show OriginGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginGroup] -> ShowS
$cshowList :: [OriginGroup] -> ShowS
show :: OriginGroup -> String
$cshow :: OriginGroup -> String
showsPrec :: Int -> OriginGroup -> ShowS
$cshowsPrec :: Int -> OriginGroup -> ShowS
Prelude.Show, (forall x. OriginGroup -> Rep OriginGroup x)
-> (forall x. Rep OriginGroup x -> OriginGroup)
-> Generic OriginGroup
forall x. Rep OriginGroup x -> OriginGroup
forall x. OriginGroup -> Rep OriginGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OriginGroup x -> OriginGroup
$cfrom :: forall x. OriginGroup -> Rep OriginGroup x
Prelude.Generic)

-- |
-- Create a value of 'OriginGroup' 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:
--
-- 'id', 'originGroup_id' - The origin group\'s ID.
--
-- 'failoverCriteria', 'originGroup_failoverCriteria' - A complex type that contains information about the failover criteria for
-- an origin group.
--
-- 'members', 'originGroup_members' - A complex type that contains information about the origins in an origin
-- group.
newOriginGroup ::
  -- | 'id'
  Prelude.Text ->
  -- | 'failoverCriteria'
  OriginGroupFailoverCriteria ->
  -- | 'members'
  OriginGroupMembers ->
  OriginGroup
newOriginGroup :: Text
-> OriginGroupFailoverCriteria -> OriginGroupMembers -> OriginGroup
newOriginGroup Text
pId_ OriginGroupFailoverCriteria
pFailoverCriteria_ OriginGroupMembers
pMembers_ =
  OriginGroup' :: Text
-> OriginGroupFailoverCriteria -> OriginGroupMembers -> OriginGroup
OriginGroup'
    { $sel:id:OriginGroup' :: Text
id = Text
pId_,
      $sel:failoverCriteria:OriginGroup' :: OriginGroupFailoverCriteria
failoverCriteria = OriginGroupFailoverCriteria
pFailoverCriteria_,
      $sel:members:OriginGroup' :: OriginGroupMembers
members = OriginGroupMembers
pMembers_
    }

-- | The origin group\'s ID.
originGroup_id :: Lens.Lens' OriginGroup Prelude.Text
originGroup_id :: (Text -> f Text) -> OriginGroup -> f OriginGroup
originGroup_id = (OriginGroup -> Text)
-> (OriginGroup -> Text -> OriginGroup)
-> Lens OriginGroup OriginGroup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginGroup' {Text
id :: Text
$sel:id:OriginGroup' :: OriginGroup -> Text
id} -> Text
id) (\s :: OriginGroup
s@OriginGroup' {} Text
a -> OriginGroup
s {$sel:id:OriginGroup' :: Text
id = Text
a} :: OriginGroup)

-- | A complex type that contains information about the failover criteria for
-- an origin group.
originGroup_failoverCriteria :: Lens.Lens' OriginGroup OriginGroupFailoverCriteria
originGroup_failoverCriteria :: (OriginGroupFailoverCriteria -> f OriginGroupFailoverCriteria)
-> OriginGroup -> f OriginGroup
originGroup_failoverCriteria = (OriginGroup -> OriginGroupFailoverCriteria)
-> (OriginGroup -> OriginGroupFailoverCriteria -> OriginGroup)
-> Lens
     OriginGroup
     OriginGroup
     OriginGroupFailoverCriteria
     OriginGroupFailoverCriteria
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginGroup' {OriginGroupFailoverCriteria
failoverCriteria :: OriginGroupFailoverCriteria
$sel:failoverCriteria:OriginGroup' :: OriginGroup -> OriginGroupFailoverCriteria
failoverCriteria} -> OriginGroupFailoverCriteria
failoverCriteria) (\s :: OriginGroup
s@OriginGroup' {} OriginGroupFailoverCriteria
a -> OriginGroup
s {$sel:failoverCriteria:OriginGroup' :: OriginGroupFailoverCriteria
failoverCriteria = OriginGroupFailoverCriteria
a} :: OriginGroup)

-- | A complex type that contains information about the origins in an origin
-- group.
originGroup_members :: Lens.Lens' OriginGroup OriginGroupMembers
originGroup_members :: (OriginGroupMembers -> f OriginGroupMembers)
-> OriginGroup -> f OriginGroup
originGroup_members = (OriginGroup -> OriginGroupMembers)
-> (OriginGroup -> OriginGroupMembers -> OriginGroup)
-> Lens
     OriginGroup OriginGroup OriginGroupMembers OriginGroupMembers
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginGroup' {OriginGroupMembers
members :: OriginGroupMembers
$sel:members:OriginGroup' :: OriginGroup -> OriginGroupMembers
members} -> OriginGroupMembers
members) (\s :: OriginGroup
s@OriginGroup' {} OriginGroupMembers
a -> OriginGroup
s {$sel:members:OriginGroup' :: OriginGroupMembers
members = OriginGroupMembers
a} :: OriginGroup)

instance Core.FromXML OriginGroup where
  parseXML :: [Node] -> Either String OriginGroup
parseXML [Node]
x =
    Text
-> OriginGroupFailoverCriteria -> OriginGroupMembers -> OriginGroup
OriginGroup'
      (Text
 -> OriginGroupFailoverCriteria
 -> OriginGroupMembers
 -> OriginGroup)
-> Either String Text
-> Either
     String
     (OriginGroupFailoverCriteria -> OriginGroupMembers -> OriginGroup)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Id")
      Either
  String
  (OriginGroupFailoverCriteria -> OriginGroupMembers -> OriginGroup)
-> Either String OriginGroupFailoverCriteria
-> Either String (OriginGroupMembers -> OriginGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginGroupFailoverCriteria
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"FailoverCriteria")
      Either String (OriginGroupMembers -> OriginGroup)
-> Either String OriginGroupMembers -> Either String OriginGroup
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginGroupMembers
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Members")

instance Prelude.Hashable OriginGroup

instance Prelude.NFData OriginGroup

instance Core.ToXML OriginGroup where
  toXML :: OriginGroup -> XML
toXML OriginGroup' {Text
OriginGroupMembers
OriginGroupFailoverCriteria
members :: OriginGroupMembers
failoverCriteria :: OriginGroupFailoverCriteria
id :: Text
$sel:members:OriginGroup' :: OriginGroup -> OriginGroupMembers
$sel:failoverCriteria:OriginGroup' :: OriginGroup -> OriginGroupFailoverCriteria
$sel:id:OriginGroup' :: OriginGroup -> Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Id" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
id,
        Name
"FailoverCriteria" Name -> OriginGroupFailoverCriteria -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginGroupFailoverCriteria
failoverCriteria,
        Name
"Members" Name -> OriginGroupMembers -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginGroupMembers
members
      ]