{-# 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.Route53AutoNaming.Types.DnsConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Route53AutoNaming.Types.DnsConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.Route53AutoNaming.Types.DnsRecord
import Amazonka.Route53AutoNaming.Types.RoutingPolicy

-- | A complex type that contains information about the Amazon Route 53 DNS
-- records that you want Cloud Map to create when you register an instance.
--
-- The record types of a service can only be changed by deleting the
-- service and recreating it with a new @Dnsconfig@.
--
-- /See:/ 'newDnsConfig' smart constructor.
data DnsConfig = DnsConfig'
  { -- | /Use NamespaceId in
    -- <https://docs.aws.amazon.com/cloud-map/latest/api/API_Service.html Service>
    -- instead./
    --
    -- The ID of the namespace to use for DNS configuration.
    DnsConfig -> Maybe Text
namespaceId :: Prelude.Maybe Prelude.Text,
    -- | The routing policy that you want to apply to all Route 53 DNS records
    -- that Cloud Map creates when you register an instance and specify this
    -- service.
    --
    -- If you want to use this service to register instances that create alias
    -- records, specify @WEIGHTED@ for the routing policy.
    --
    -- You can specify the following values:
    --
    -- [MULTIVALUE]
    --     If you define a health check for the service and the health check is
    --     healthy, Route 53 returns the applicable value for up to eight
    --     instances.
    --
    --     For example, suppose that the service includes configurations for
    --     one @A@ record and a health check. You use the service to register
    --     10 instances. Route 53 responds to DNS queries with IP addresses for
    --     up to eight healthy instances. If fewer than eight instances are
    --     healthy, Route 53 responds to every DNS query with the IP addresses
    --     for all of the healthy instances.
    --
    --     If you don\'t define a health check for the service, Route 53
    --     assumes that all instances are healthy and returns the values for up
    --     to eight instances.
    --
    --     For more information about the multivalue routing policy, see
    --     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-multivalue Multivalue Answer Routing>
    --     in the /Route 53 Developer Guide/.
    --
    -- [WEIGHTED]
    --     Route 53 returns the applicable value from one randomly selected
    --     instance from among the instances that you registered using the same
    --     service. Currently, all records have the same weight, so you can\'t
    --     route more or less traffic to any instances.
    --
    --     For example, suppose that the service includes configurations for
    --     one @A@ record and a health check. You use the service to register
    --     10 instances. Route 53 responds to DNS queries with the IP address
    --     for one randomly selected instance from among the healthy instances.
    --     If no instances are healthy, Route 53 responds to DNS queries as if
    --     all of the instances were healthy.
    --
    --     If you don\'t define a health check for the service, Route 53
    --     assumes that all instances are healthy and returns the applicable
    --     value for one randomly selected instance.
    --
    --     For more information about the weighted routing policy, see
    --     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted Weighted Routing>
    --     in the /Route 53 Developer Guide/.
    DnsConfig -> Maybe RoutingPolicy
routingPolicy :: Prelude.Maybe RoutingPolicy,
    -- | An array that contains one @DnsRecord@ object for each Route 53 DNS
    -- record that you want Cloud Map to create when you register an instance.
    DnsConfig -> [DnsRecord]
dnsRecords :: [DnsRecord]
  }
  deriving (DnsConfig -> DnsConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DnsConfig -> DnsConfig -> Bool
$c/= :: DnsConfig -> DnsConfig -> Bool
== :: DnsConfig -> DnsConfig -> Bool
$c== :: DnsConfig -> DnsConfig -> Bool
Prelude.Eq, ReadPrec [DnsConfig]
ReadPrec DnsConfig
Int -> ReadS DnsConfig
ReadS [DnsConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DnsConfig]
$creadListPrec :: ReadPrec [DnsConfig]
readPrec :: ReadPrec DnsConfig
$creadPrec :: ReadPrec DnsConfig
readList :: ReadS [DnsConfig]
$creadList :: ReadS [DnsConfig]
readsPrec :: Int -> ReadS DnsConfig
$creadsPrec :: Int -> ReadS DnsConfig
Prelude.Read, Int -> DnsConfig -> ShowS
[DnsConfig] -> ShowS
DnsConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DnsConfig] -> ShowS
$cshowList :: [DnsConfig] -> ShowS
show :: DnsConfig -> String
$cshow :: DnsConfig -> String
showsPrec :: Int -> DnsConfig -> ShowS
$cshowsPrec :: Int -> DnsConfig -> ShowS
Prelude.Show, forall x. Rep DnsConfig x -> DnsConfig
forall x. DnsConfig -> Rep DnsConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DnsConfig x -> DnsConfig
$cfrom :: forall x. DnsConfig -> Rep DnsConfig x
Prelude.Generic)

-- |
-- Create a value of 'DnsConfig' 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:
--
-- 'namespaceId', 'dnsConfig_namespaceId' - /Use NamespaceId in
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_Service.html Service>
-- instead./
--
-- The ID of the namespace to use for DNS configuration.
--
-- 'routingPolicy', 'dnsConfig_routingPolicy' - The routing policy that you want to apply to all Route 53 DNS records
-- that Cloud Map creates when you register an instance and specify this
-- service.
--
-- If you want to use this service to register instances that create alias
-- records, specify @WEIGHTED@ for the routing policy.
--
-- You can specify the following values:
--
-- [MULTIVALUE]
--     If you define a health check for the service and the health check is
--     healthy, Route 53 returns the applicable value for up to eight
--     instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with IP addresses for
--     up to eight healthy instances. If fewer than eight instances are
--     healthy, Route 53 responds to every DNS query with the IP addresses
--     for all of the healthy instances.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the values for up
--     to eight instances.
--
--     For more information about the multivalue routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-multivalue Multivalue Answer Routing>
--     in the /Route 53 Developer Guide/.
--
-- [WEIGHTED]
--     Route 53 returns the applicable value from one randomly selected
--     instance from among the instances that you registered using the same
--     service. Currently, all records have the same weight, so you can\'t
--     route more or less traffic to any instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with the IP address
--     for one randomly selected instance from among the healthy instances.
--     If no instances are healthy, Route 53 responds to DNS queries as if
--     all of the instances were healthy.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the applicable
--     value for one randomly selected instance.
--
--     For more information about the weighted routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted Weighted Routing>
--     in the /Route 53 Developer Guide/.
--
-- 'dnsRecords', 'dnsConfig_dnsRecords' - An array that contains one @DnsRecord@ object for each Route 53 DNS
-- record that you want Cloud Map to create when you register an instance.
newDnsConfig ::
  DnsConfig
newDnsConfig :: DnsConfig
newDnsConfig =
  DnsConfig'
    { $sel:namespaceId:DnsConfig' :: Maybe Text
namespaceId = forall a. Maybe a
Prelude.Nothing,
      $sel:routingPolicy:DnsConfig' :: Maybe RoutingPolicy
routingPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:dnsRecords:DnsConfig' :: [DnsRecord]
dnsRecords = forall a. Monoid a => a
Prelude.mempty
    }

-- | /Use NamespaceId in
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_Service.html Service>
-- instead./
--
-- The ID of the namespace to use for DNS configuration.
dnsConfig_namespaceId :: Lens.Lens' DnsConfig (Prelude.Maybe Prelude.Text)
dnsConfig_namespaceId :: Lens' DnsConfig (Maybe Text)
dnsConfig_namespaceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsConfig' {Maybe Text
namespaceId :: Maybe Text
$sel:namespaceId:DnsConfig' :: DnsConfig -> Maybe Text
namespaceId} -> Maybe Text
namespaceId) (\s :: DnsConfig
s@DnsConfig' {} Maybe Text
a -> DnsConfig
s {$sel:namespaceId:DnsConfig' :: Maybe Text
namespaceId = Maybe Text
a} :: DnsConfig)

-- | The routing policy that you want to apply to all Route 53 DNS records
-- that Cloud Map creates when you register an instance and specify this
-- service.
--
-- If you want to use this service to register instances that create alias
-- records, specify @WEIGHTED@ for the routing policy.
--
-- You can specify the following values:
--
-- [MULTIVALUE]
--     If you define a health check for the service and the health check is
--     healthy, Route 53 returns the applicable value for up to eight
--     instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with IP addresses for
--     up to eight healthy instances. If fewer than eight instances are
--     healthy, Route 53 responds to every DNS query with the IP addresses
--     for all of the healthy instances.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the values for up
--     to eight instances.
--
--     For more information about the multivalue routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-multivalue Multivalue Answer Routing>
--     in the /Route 53 Developer Guide/.
--
-- [WEIGHTED]
--     Route 53 returns the applicable value from one randomly selected
--     instance from among the instances that you registered using the same
--     service. Currently, all records have the same weight, so you can\'t
--     route more or less traffic to any instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with the IP address
--     for one randomly selected instance from among the healthy instances.
--     If no instances are healthy, Route 53 responds to DNS queries as if
--     all of the instances were healthy.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the applicable
--     value for one randomly selected instance.
--
--     For more information about the weighted routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted Weighted Routing>
--     in the /Route 53 Developer Guide/.
dnsConfig_routingPolicy :: Lens.Lens' DnsConfig (Prelude.Maybe RoutingPolicy)
dnsConfig_routingPolicy :: Lens' DnsConfig (Maybe RoutingPolicy)
dnsConfig_routingPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsConfig' {Maybe RoutingPolicy
routingPolicy :: Maybe RoutingPolicy
$sel:routingPolicy:DnsConfig' :: DnsConfig -> Maybe RoutingPolicy
routingPolicy} -> Maybe RoutingPolicy
routingPolicy) (\s :: DnsConfig
s@DnsConfig' {} Maybe RoutingPolicy
a -> DnsConfig
s {$sel:routingPolicy:DnsConfig' :: Maybe RoutingPolicy
routingPolicy = Maybe RoutingPolicy
a} :: DnsConfig)

-- | An array that contains one @DnsRecord@ object for each Route 53 DNS
-- record that you want Cloud Map to create when you register an instance.
dnsConfig_dnsRecords :: Lens.Lens' DnsConfig [DnsRecord]
dnsConfig_dnsRecords :: Lens' DnsConfig [DnsRecord]
dnsConfig_dnsRecords = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsConfig' {[DnsRecord]
dnsRecords :: [DnsRecord]
$sel:dnsRecords:DnsConfig' :: DnsConfig -> [DnsRecord]
dnsRecords} -> [DnsRecord]
dnsRecords) (\s :: DnsConfig
s@DnsConfig' {} [DnsRecord]
a -> DnsConfig
s {$sel:dnsRecords:DnsConfig' :: [DnsRecord]
dnsRecords = [DnsRecord]
a} :: DnsConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON DnsConfig where
  parseJSON :: Value -> Parser DnsConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DnsConfig"
      ( \Object
x ->
          Maybe Text -> Maybe RoutingPolicy -> [DnsRecord] -> DnsConfig
DnsConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"NamespaceId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RoutingPolicy")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DnsRecords" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DnsConfig where
  hashWithSalt :: Int -> DnsConfig -> Int
hashWithSalt Int
_salt DnsConfig' {[DnsRecord]
Maybe Text
Maybe RoutingPolicy
dnsRecords :: [DnsRecord]
routingPolicy :: Maybe RoutingPolicy
namespaceId :: Maybe Text
$sel:dnsRecords:DnsConfig' :: DnsConfig -> [DnsRecord]
$sel:routingPolicy:DnsConfig' :: DnsConfig -> Maybe RoutingPolicy
$sel:namespaceId:DnsConfig' :: DnsConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
namespaceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RoutingPolicy
routingPolicy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [DnsRecord]
dnsRecords

instance Prelude.NFData DnsConfig where
  rnf :: DnsConfig -> ()
rnf DnsConfig' {[DnsRecord]
Maybe Text
Maybe RoutingPolicy
dnsRecords :: [DnsRecord]
routingPolicy :: Maybe RoutingPolicy
namespaceId :: Maybe Text
$sel:dnsRecords:DnsConfig' :: DnsConfig -> [DnsRecord]
$sel:routingPolicy:DnsConfig' :: DnsConfig -> Maybe RoutingPolicy
$sel:namespaceId:DnsConfig' :: DnsConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
namespaceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RoutingPolicy
routingPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [DnsRecord]
dnsRecords

instance Data.ToJSON DnsConfig where
  toJSON :: DnsConfig -> Value
toJSON DnsConfig' {[DnsRecord]
Maybe Text
Maybe RoutingPolicy
dnsRecords :: [DnsRecord]
routingPolicy :: Maybe RoutingPolicy
namespaceId :: Maybe Text
$sel:dnsRecords:DnsConfig' :: DnsConfig -> [DnsRecord]
$sel:routingPolicy:DnsConfig' :: DnsConfig -> Maybe RoutingPolicy
$sel:namespaceId:DnsConfig' :: DnsConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"NamespaceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
namespaceId,
            (Key
"RoutingPolicy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RoutingPolicy
routingPolicy,
            forall a. a -> Maybe a
Prelude.Just (Key
"DnsRecords" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [DnsRecord]
dnsRecords)
          ]
      )