{-# 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.AppMesh.Types.DnsServiceDiscovery
-- 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.AppMesh.Types.DnsServiceDiscovery where

import Amazonka.AppMesh.Types.DnsResponseType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the DNS service discovery information for your
-- virtual node.
--
-- /See:/ 'newDnsServiceDiscovery' smart constructor.
data DnsServiceDiscovery = DnsServiceDiscovery'
  { -- | Specifies the DNS response type for the virtual node.
    DnsServiceDiscovery -> Maybe DnsResponseType
responseType :: Prelude.Maybe DnsResponseType,
    -- | Specifies the DNS service discovery hostname for the virtual node.
    DnsServiceDiscovery -> Text
hostname :: Prelude.Text
  }
  deriving (DnsServiceDiscovery -> DnsServiceDiscovery -> Bool
(DnsServiceDiscovery -> DnsServiceDiscovery -> Bool)
-> (DnsServiceDiscovery -> DnsServiceDiscovery -> Bool)
-> Eq DnsServiceDiscovery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DnsServiceDiscovery -> DnsServiceDiscovery -> Bool
$c/= :: DnsServiceDiscovery -> DnsServiceDiscovery -> Bool
== :: DnsServiceDiscovery -> DnsServiceDiscovery -> Bool
$c== :: DnsServiceDiscovery -> DnsServiceDiscovery -> Bool
Prelude.Eq, ReadPrec [DnsServiceDiscovery]
ReadPrec DnsServiceDiscovery
Int -> ReadS DnsServiceDiscovery
ReadS [DnsServiceDiscovery]
(Int -> ReadS DnsServiceDiscovery)
-> ReadS [DnsServiceDiscovery]
-> ReadPrec DnsServiceDiscovery
-> ReadPrec [DnsServiceDiscovery]
-> Read DnsServiceDiscovery
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DnsServiceDiscovery]
$creadListPrec :: ReadPrec [DnsServiceDiscovery]
readPrec :: ReadPrec DnsServiceDiscovery
$creadPrec :: ReadPrec DnsServiceDiscovery
readList :: ReadS [DnsServiceDiscovery]
$creadList :: ReadS [DnsServiceDiscovery]
readsPrec :: Int -> ReadS DnsServiceDiscovery
$creadsPrec :: Int -> ReadS DnsServiceDiscovery
Prelude.Read, Int -> DnsServiceDiscovery -> ShowS
[DnsServiceDiscovery] -> ShowS
DnsServiceDiscovery -> String
(Int -> DnsServiceDiscovery -> ShowS)
-> (DnsServiceDiscovery -> String)
-> ([DnsServiceDiscovery] -> ShowS)
-> Show DnsServiceDiscovery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DnsServiceDiscovery] -> ShowS
$cshowList :: [DnsServiceDiscovery] -> ShowS
show :: DnsServiceDiscovery -> String
$cshow :: DnsServiceDiscovery -> String
showsPrec :: Int -> DnsServiceDiscovery -> ShowS
$cshowsPrec :: Int -> DnsServiceDiscovery -> ShowS
Prelude.Show, (forall x. DnsServiceDiscovery -> Rep DnsServiceDiscovery x)
-> (forall x. Rep DnsServiceDiscovery x -> DnsServiceDiscovery)
-> Generic DnsServiceDiscovery
forall x. Rep DnsServiceDiscovery x -> DnsServiceDiscovery
forall x. DnsServiceDiscovery -> Rep DnsServiceDiscovery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DnsServiceDiscovery x -> DnsServiceDiscovery
$cfrom :: forall x. DnsServiceDiscovery -> Rep DnsServiceDiscovery x
Prelude.Generic)

-- |
-- Create a value of 'DnsServiceDiscovery' 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:
--
-- 'responseType', 'dnsServiceDiscovery_responseType' - Specifies the DNS response type for the virtual node.
--
-- 'hostname', 'dnsServiceDiscovery_hostname' - Specifies the DNS service discovery hostname for the virtual node.
newDnsServiceDiscovery ::
  -- | 'hostname'
  Prelude.Text ->
  DnsServiceDiscovery
newDnsServiceDiscovery :: Text -> DnsServiceDiscovery
newDnsServiceDiscovery Text
pHostname_ =
  DnsServiceDiscovery' :: Maybe DnsResponseType -> Text -> DnsServiceDiscovery
DnsServiceDiscovery'
    { $sel:responseType:DnsServiceDiscovery' :: Maybe DnsResponseType
responseType =
        Maybe DnsResponseType
forall a. Maybe a
Prelude.Nothing,
      $sel:hostname:DnsServiceDiscovery' :: Text
hostname = Text
pHostname_
    }

-- | Specifies the DNS response type for the virtual node.
dnsServiceDiscovery_responseType :: Lens.Lens' DnsServiceDiscovery (Prelude.Maybe DnsResponseType)
dnsServiceDiscovery_responseType :: (Maybe DnsResponseType -> f (Maybe DnsResponseType))
-> DnsServiceDiscovery -> f DnsServiceDiscovery
dnsServiceDiscovery_responseType = (DnsServiceDiscovery -> Maybe DnsResponseType)
-> (DnsServiceDiscovery
    -> Maybe DnsResponseType -> DnsServiceDiscovery)
-> Lens
     DnsServiceDiscovery
     DnsServiceDiscovery
     (Maybe DnsResponseType)
     (Maybe DnsResponseType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsServiceDiscovery' {Maybe DnsResponseType
responseType :: Maybe DnsResponseType
$sel:responseType:DnsServiceDiscovery' :: DnsServiceDiscovery -> Maybe DnsResponseType
responseType} -> Maybe DnsResponseType
responseType) (\s :: DnsServiceDiscovery
s@DnsServiceDiscovery' {} Maybe DnsResponseType
a -> DnsServiceDiscovery
s {$sel:responseType:DnsServiceDiscovery' :: Maybe DnsResponseType
responseType = Maybe DnsResponseType
a} :: DnsServiceDiscovery)

-- | Specifies the DNS service discovery hostname for the virtual node.
dnsServiceDiscovery_hostname :: Lens.Lens' DnsServiceDiscovery Prelude.Text
dnsServiceDiscovery_hostname :: (Text -> f Text) -> DnsServiceDiscovery -> f DnsServiceDiscovery
dnsServiceDiscovery_hostname = (DnsServiceDiscovery -> Text)
-> (DnsServiceDiscovery -> Text -> DnsServiceDiscovery)
-> Lens DnsServiceDiscovery DnsServiceDiscovery Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsServiceDiscovery' {Text
hostname :: Text
$sel:hostname:DnsServiceDiscovery' :: DnsServiceDiscovery -> Text
hostname} -> Text
hostname) (\s :: DnsServiceDiscovery
s@DnsServiceDiscovery' {} Text
a -> DnsServiceDiscovery
s {$sel:hostname:DnsServiceDiscovery' :: Text
hostname = Text
a} :: DnsServiceDiscovery)

instance Core.FromJSON DnsServiceDiscovery where
  parseJSON :: Value -> Parser DnsServiceDiscovery
parseJSON =
    String
-> (Object -> Parser DnsServiceDiscovery)
-> Value
-> Parser DnsServiceDiscovery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DnsServiceDiscovery"
      ( \Object
x ->
          Maybe DnsResponseType -> Text -> DnsServiceDiscovery
DnsServiceDiscovery'
            (Maybe DnsResponseType -> Text -> DnsServiceDiscovery)
-> Parser (Maybe DnsResponseType)
-> Parser (Text -> DnsServiceDiscovery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe DnsResponseType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"responseType")
            Parser (Text -> DnsServiceDiscovery)
-> Parser Text -> Parser DnsServiceDiscovery
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
"hostname")
      )

instance Prelude.Hashable DnsServiceDiscovery

instance Prelude.NFData DnsServiceDiscovery

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