{-# 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.Route53Domains.Types.Nameserver
-- 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.Route53Domains.Types.Nameserver where

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

-- | Nameserver includes the following elements.
--
-- /See:/ 'newNameserver' smart constructor.
data Nameserver = Nameserver'
  { -- | Glue IP address of a name server entry. Glue IP addresses are required
    -- only when the name of the name server is a subdomain of the domain. For
    -- example, if your domain is example.com and the name server for the
    -- domain is ns.example.com, you need to specify the IP address for
    -- ns.example.com.
    --
    -- Constraints: The list can contain only one IPv4 and one IPv6 address.
    Nameserver -> Maybe [Text]
glueIps :: Prelude.Maybe [Prelude.Text],
    -- | The fully qualified host name of the name server.
    --
    -- Constraint: Maximum 255 characters
    Nameserver -> Text
name :: Prelude.Text
  }
  deriving (Nameserver -> Nameserver -> Bool
(Nameserver -> Nameserver -> Bool)
-> (Nameserver -> Nameserver -> Bool) -> Eq Nameserver
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Nameserver -> Nameserver -> Bool
$c/= :: Nameserver -> Nameserver -> Bool
== :: Nameserver -> Nameserver -> Bool
$c== :: Nameserver -> Nameserver -> Bool
Prelude.Eq, ReadPrec [Nameserver]
ReadPrec Nameserver
Int -> ReadS Nameserver
ReadS [Nameserver]
(Int -> ReadS Nameserver)
-> ReadS [Nameserver]
-> ReadPrec Nameserver
-> ReadPrec [Nameserver]
-> Read Nameserver
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Nameserver]
$creadListPrec :: ReadPrec [Nameserver]
readPrec :: ReadPrec Nameserver
$creadPrec :: ReadPrec Nameserver
readList :: ReadS [Nameserver]
$creadList :: ReadS [Nameserver]
readsPrec :: Int -> ReadS Nameserver
$creadsPrec :: Int -> ReadS Nameserver
Prelude.Read, Int -> Nameserver -> ShowS
[Nameserver] -> ShowS
Nameserver -> String
(Int -> Nameserver -> ShowS)
-> (Nameserver -> String)
-> ([Nameserver] -> ShowS)
-> Show Nameserver
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Nameserver] -> ShowS
$cshowList :: [Nameserver] -> ShowS
show :: Nameserver -> String
$cshow :: Nameserver -> String
showsPrec :: Int -> Nameserver -> ShowS
$cshowsPrec :: Int -> Nameserver -> ShowS
Prelude.Show, (forall x. Nameserver -> Rep Nameserver x)
-> (forall x. Rep Nameserver x -> Nameserver) -> Generic Nameserver
forall x. Rep Nameserver x -> Nameserver
forall x. Nameserver -> Rep Nameserver x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Nameserver x -> Nameserver
$cfrom :: forall x. Nameserver -> Rep Nameserver x
Prelude.Generic)

-- |
-- Create a value of 'Nameserver' 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:
--
-- 'glueIps', 'nameserver_glueIps' - Glue IP address of a name server entry. Glue IP addresses are required
-- only when the name of the name server is a subdomain of the domain. For
-- example, if your domain is example.com and the name server for the
-- domain is ns.example.com, you need to specify the IP address for
-- ns.example.com.
--
-- Constraints: The list can contain only one IPv4 and one IPv6 address.
--
-- 'name', 'nameserver_name' - The fully qualified host name of the name server.
--
-- Constraint: Maximum 255 characters
newNameserver ::
  -- | 'name'
  Prelude.Text ->
  Nameserver
newNameserver :: Text -> Nameserver
newNameserver Text
pName_ =
  Nameserver' :: Maybe [Text] -> Text -> Nameserver
Nameserver'
    { $sel:glueIps:Nameserver' :: Maybe [Text]
glueIps = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Nameserver' :: Text
name = Text
pName_
    }

-- | Glue IP address of a name server entry. Glue IP addresses are required
-- only when the name of the name server is a subdomain of the domain. For
-- example, if your domain is example.com and the name server for the
-- domain is ns.example.com, you need to specify the IP address for
-- ns.example.com.
--
-- Constraints: The list can contain only one IPv4 and one IPv6 address.
nameserver_glueIps :: Lens.Lens' Nameserver (Prelude.Maybe [Prelude.Text])
nameserver_glueIps :: (Maybe [Text] -> f (Maybe [Text])) -> Nameserver -> f Nameserver
nameserver_glueIps = (Nameserver -> Maybe [Text])
-> (Nameserver -> Maybe [Text] -> Nameserver)
-> Lens Nameserver Nameserver (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Nameserver' {Maybe [Text]
glueIps :: Maybe [Text]
$sel:glueIps:Nameserver' :: Nameserver -> Maybe [Text]
glueIps} -> Maybe [Text]
glueIps) (\s :: Nameserver
s@Nameserver' {} Maybe [Text]
a -> Nameserver
s {$sel:glueIps:Nameserver' :: Maybe [Text]
glueIps = Maybe [Text]
a} :: Nameserver) ((Maybe [Text] -> f (Maybe [Text])) -> Nameserver -> f Nameserver)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> Nameserver
-> f Nameserver
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The fully qualified host name of the name server.
--
-- Constraint: Maximum 255 characters
nameserver_name :: Lens.Lens' Nameserver Prelude.Text
nameserver_name :: (Text -> f Text) -> Nameserver -> f Nameserver
nameserver_name = (Nameserver -> Text)
-> (Nameserver -> Text -> Nameserver)
-> Lens Nameserver Nameserver Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Nameserver' {Text
name :: Text
$sel:name:Nameserver' :: Nameserver -> Text
name} -> Text
name) (\s :: Nameserver
s@Nameserver' {} Text
a -> Nameserver
s {$sel:name:Nameserver' :: Text
name = Text
a} :: Nameserver)

instance Core.FromJSON Nameserver where
  parseJSON :: Value -> Parser Nameserver
parseJSON =
    String
-> (Object -> Parser Nameserver) -> Value -> Parser Nameserver
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Nameserver"
      ( \Object
x ->
          Maybe [Text] -> Text -> Nameserver
Nameserver'
            (Maybe [Text] -> Text -> Nameserver)
-> Parser (Maybe [Text]) -> Parser (Text -> Nameserver)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"GlueIps" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> Nameserver) -> Parser Text -> Parser Nameserver
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
      )

instance Prelude.Hashable Nameserver

instance Prelude.NFData Nameserver

instance Core.ToJSON Nameserver where
  toJSON :: Nameserver -> Value
toJSON Nameserver' {Maybe [Text]
Text
name :: Text
glueIps :: Maybe [Text]
$sel:name:Nameserver' :: Nameserver -> Text
$sel:glueIps:Nameserver' :: Nameserver -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"GlueIps" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
glueIps,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )