{-# 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.Route53.Types.DelegationSet
-- 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.Route53.Types.DelegationSet where

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

-- | A complex type that lists the name servers in a delegation set, as well
-- as the @CallerReference@ and the @ID@ for the delegation set.
--
-- /See:/ 'newDelegationSet' smart constructor.
data DelegationSet = DelegationSet'
  { -- | The ID that Amazon Route 53 assigns to a reusable delegation set.
    DelegationSet -> Maybe ResourceId
id :: Prelude.Maybe ResourceId,
    -- | The value that you specified for @CallerReference@ when you created the
    -- reusable delegation set.
    DelegationSet -> Maybe Text
callerReference :: Prelude.Maybe Prelude.Text,
    -- | A complex type that contains a list of the authoritative name servers
    -- for a hosted zone or for a reusable delegation set.
    DelegationSet -> NonEmpty Text
nameServers :: Prelude.NonEmpty Prelude.Text
  }
  deriving (DelegationSet -> DelegationSet -> Bool
(DelegationSet -> DelegationSet -> Bool)
-> (DelegationSet -> DelegationSet -> Bool) -> Eq DelegationSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DelegationSet -> DelegationSet -> Bool
$c/= :: DelegationSet -> DelegationSet -> Bool
== :: DelegationSet -> DelegationSet -> Bool
$c== :: DelegationSet -> DelegationSet -> Bool
Prelude.Eq, ReadPrec [DelegationSet]
ReadPrec DelegationSet
Int -> ReadS DelegationSet
ReadS [DelegationSet]
(Int -> ReadS DelegationSet)
-> ReadS [DelegationSet]
-> ReadPrec DelegationSet
-> ReadPrec [DelegationSet]
-> Read DelegationSet
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DelegationSet]
$creadListPrec :: ReadPrec [DelegationSet]
readPrec :: ReadPrec DelegationSet
$creadPrec :: ReadPrec DelegationSet
readList :: ReadS [DelegationSet]
$creadList :: ReadS [DelegationSet]
readsPrec :: Int -> ReadS DelegationSet
$creadsPrec :: Int -> ReadS DelegationSet
Prelude.Read, Int -> DelegationSet -> ShowS
[DelegationSet] -> ShowS
DelegationSet -> String
(Int -> DelegationSet -> ShowS)
-> (DelegationSet -> String)
-> ([DelegationSet] -> ShowS)
-> Show DelegationSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DelegationSet] -> ShowS
$cshowList :: [DelegationSet] -> ShowS
show :: DelegationSet -> String
$cshow :: DelegationSet -> String
showsPrec :: Int -> DelegationSet -> ShowS
$cshowsPrec :: Int -> DelegationSet -> ShowS
Prelude.Show, (forall x. DelegationSet -> Rep DelegationSet x)
-> (forall x. Rep DelegationSet x -> DelegationSet)
-> Generic DelegationSet
forall x. Rep DelegationSet x -> DelegationSet
forall x. DelegationSet -> Rep DelegationSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DelegationSet x -> DelegationSet
$cfrom :: forall x. DelegationSet -> Rep DelegationSet x
Prelude.Generic)

-- |
-- Create a value of 'DelegationSet' 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', 'delegationSet_id' - The ID that Amazon Route 53 assigns to a reusable delegation set.
--
-- 'callerReference', 'delegationSet_callerReference' - The value that you specified for @CallerReference@ when you created the
-- reusable delegation set.
--
-- 'nameServers', 'delegationSet_nameServers' - A complex type that contains a list of the authoritative name servers
-- for a hosted zone or for a reusable delegation set.
newDelegationSet ::
  -- | 'nameServers'
  Prelude.NonEmpty Prelude.Text ->
  DelegationSet
newDelegationSet :: NonEmpty Text -> DelegationSet
newDelegationSet NonEmpty Text
pNameServers_ =
  DelegationSet' :: Maybe ResourceId -> Maybe Text -> NonEmpty Text -> DelegationSet
DelegationSet'
    { $sel:id:DelegationSet' :: Maybe ResourceId
id = Maybe ResourceId
forall a. Maybe a
Prelude.Nothing,
      $sel:callerReference:DelegationSet' :: Maybe Text
callerReference = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:nameServers:DelegationSet' :: NonEmpty Text
nameServers = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pNameServers_
    }

-- | The ID that Amazon Route 53 assigns to a reusable delegation set.
delegationSet_id :: Lens.Lens' DelegationSet (Prelude.Maybe ResourceId)
delegationSet_id :: (Maybe ResourceId -> f (Maybe ResourceId))
-> DelegationSet -> f DelegationSet
delegationSet_id = (DelegationSet -> Maybe ResourceId)
-> (DelegationSet -> Maybe ResourceId -> DelegationSet)
-> Lens
     DelegationSet DelegationSet (Maybe ResourceId) (Maybe ResourceId)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DelegationSet' {Maybe ResourceId
id :: Maybe ResourceId
$sel:id:DelegationSet' :: DelegationSet -> Maybe ResourceId
id} -> Maybe ResourceId
id) (\s :: DelegationSet
s@DelegationSet' {} Maybe ResourceId
a -> DelegationSet
s {$sel:id:DelegationSet' :: Maybe ResourceId
id = Maybe ResourceId
a} :: DelegationSet)

-- | The value that you specified for @CallerReference@ when you created the
-- reusable delegation set.
delegationSet_callerReference :: Lens.Lens' DelegationSet (Prelude.Maybe Prelude.Text)
delegationSet_callerReference :: (Maybe Text -> f (Maybe Text)) -> DelegationSet -> f DelegationSet
delegationSet_callerReference = (DelegationSet -> Maybe Text)
-> (DelegationSet -> Maybe Text -> DelegationSet)
-> Lens DelegationSet DelegationSet (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DelegationSet' {Maybe Text
callerReference :: Maybe Text
$sel:callerReference:DelegationSet' :: DelegationSet -> Maybe Text
callerReference} -> Maybe Text
callerReference) (\s :: DelegationSet
s@DelegationSet' {} Maybe Text
a -> DelegationSet
s {$sel:callerReference:DelegationSet' :: Maybe Text
callerReference = Maybe Text
a} :: DelegationSet)

-- | A complex type that contains a list of the authoritative name servers
-- for a hosted zone or for a reusable delegation set.
delegationSet_nameServers :: Lens.Lens' DelegationSet (Prelude.NonEmpty Prelude.Text)
delegationSet_nameServers :: (NonEmpty Text -> f (NonEmpty Text))
-> DelegationSet -> f DelegationSet
delegationSet_nameServers = (DelegationSet -> NonEmpty Text)
-> (DelegationSet -> NonEmpty Text -> DelegationSet)
-> Lens DelegationSet DelegationSet (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DelegationSet' {NonEmpty Text
nameServers :: NonEmpty Text
$sel:nameServers:DelegationSet' :: DelegationSet -> NonEmpty Text
nameServers} -> NonEmpty Text
nameServers) (\s :: DelegationSet
s@DelegationSet' {} NonEmpty Text
a -> DelegationSet
s {$sel:nameServers:DelegationSet' :: NonEmpty Text
nameServers = NonEmpty Text
a} :: DelegationSet) ((NonEmpty Text -> f (NonEmpty Text))
 -> DelegationSet -> f DelegationSet)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> DelegationSet
-> f DelegationSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML DelegationSet where
  parseXML :: [Node] -> Either String DelegationSet
parseXML [Node]
x =
    Maybe ResourceId -> Maybe Text -> NonEmpty Text -> DelegationSet
DelegationSet'
      (Maybe ResourceId -> Maybe Text -> NonEmpty Text -> DelegationSet)
-> Either String (Maybe ResourceId)
-> Either String (Maybe Text -> NonEmpty Text -> DelegationSet)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe ResourceId)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Id")
      Either String (Maybe Text -> NonEmpty Text -> DelegationSet)
-> Either String (Maybe Text)
-> Either String (NonEmpty Text -> DelegationSet)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"CallerReference")
      Either String (NonEmpty Text -> DelegationSet)
-> Either String (NonEmpty Text) -> Either String DelegationSet
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
"NameServers" 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 Text))
-> Either String (NonEmpty Text)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String (NonEmpty Text)
forall a. FromXML a => Text -> [Node] -> Either String (NonEmpty a)
Core.parseXMLList1 Text
"NameServer"
                  )

instance Prelude.Hashable DelegationSet

instance Prelude.NFData DelegationSet