{-# 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.Route53Resolver.Types.TargetAddress
-- 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.Route53Resolver.Types.TargetAddress where

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

-- | In a
-- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_CreateResolverRule.html CreateResolverRule>
-- request, an array of the IPs that you want to forward DNS queries to.
--
-- /See:/ 'newTargetAddress' smart constructor.
data TargetAddress = TargetAddress'
  { -- | The port at @Ip@ that you want to forward DNS queries to.
    TargetAddress -> Maybe Natural
port :: Prelude.Maybe Prelude.Natural,
    -- | One IP address that you want to forward DNS queries to. You can specify
    -- only IPv4 addresses.
    TargetAddress -> Text
ip :: Prelude.Text
  }
  deriving (TargetAddress -> TargetAddress -> Bool
(TargetAddress -> TargetAddress -> Bool)
-> (TargetAddress -> TargetAddress -> Bool) -> Eq TargetAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetAddress -> TargetAddress -> Bool
$c/= :: TargetAddress -> TargetAddress -> Bool
== :: TargetAddress -> TargetAddress -> Bool
$c== :: TargetAddress -> TargetAddress -> Bool
Prelude.Eq, ReadPrec [TargetAddress]
ReadPrec TargetAddress
Int -> ReadS TargetAddress
ReadS [TargetAddress]
(Int -> ReadS TargetAddress)
-> ReadS [TargetAddress]
-> ReadPrec TargetAddress
-> ReadPrec [TargetAddress]
-> Read TargetAddress
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetAddress]
$creadListPrec :: ReadPrec [TargetAddress]
readPrec :: ReadPrec TargetAddress
$creadPrec :: ReadPrec TargetAddress
readList :: ReadS [TargetAddress]
$creadList :: ReadS [TargetAddress]
readsPrec :: Int -> ReadS TargetAddress
$creadsPrec :: Int -> ReadS TargetAddress
Prelude.Read, Int -> TargetAddress -> ShowS
[TargetAddress] -> ShowS
TargetAddress -> String
(Int -> TargetAddress -> ShowS)
-> (TargetAddress -> String)
-> ([TargetAddress] -> ShowS)
-> Show TargetAddress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetAddress] -> ShowS
$cshowList :: [TargetAddress] -> ShowS
show :: TargetAddress -> String
$cshow :: TargetAddress -> String
showsPrec :: Int -> TargetAddress -> ShowS
$cshowsPrec :: Int -> TargetAddress -> ShowS
Prelude.Show, (forall x. TargetAddress -> Rep TargetAddress x)
-> (forall x. Rep TargetAddress x -> TargetAddress)
-> Generic TargetAddress
forall x. Rep TargetAddress x -> TargetAddress
forall x. TargetAddress -> Rep TargetAddress x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TargetAddress x -> TargetAddress
$cfrom :: forall x. TargetAddress -> Rep TargetAddress x
Prelude.Generic)

-- |
-- Create a value of 'TargetAddress' 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:
--
-- 'port', 'targetAddress_port' - The port at @Ip@ that you want to forward DNS queries to.
--
-- 'ip', 'targetAddress_ip' - One IP address that you want to forward DNS queries to. You can specify
-- only IPv4 addresses.
newTargetAddress ::
  -- | 'ip'
  Prelude.Text ->
  TargetAddress
newTargetAddress :: Text -> TargetAddress
newTargetAddress Text
pIp_ =
  TargetAddress' :: Maybe Natural -> Text -> TargetAddress
TargetAddress' {$sel:port:TargetAddress' :: Maybe Natural
port = Maybe Natural
forall a. Maybe a
Prelude.Nothing, $sel:ip:TargetAddress' :: Text
ip = Text
pIp_}

-- | The port at @Ip@ that you want to forward DNS queries to.
targetAddress_port :: Lens.Lens' TargetAddress (Prelude.Maybe Prelude.Natural)
targetAddress_port :: (Maybe Natural -> f (Maybe Natural))
-> TargetAddress -> f TargetAddress
targetAddress_port = (TargetAddress -> Maybe Natural)
-> (TargetAddress -> Maybe Natural -> TargetAddress)
-> Lens TargetAddress TargetAddress (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetAddress' {Maybe Natural
port :: Maybe Natural
$sel:port:TargetAddress' :: TargetAddress -> Maybe Natural
port} -> Maybe Natural
port) (\s :: TargetAddress
s@TargetAddress' {} Maybe Natural
a -> TargetAddress
s {$sel:port:TargetAddress' :: Maybe Natural
port = Maybe Natural
a} :: TargetAddress)

-- | One IP address that you want to forward DNS queries to. You can specify
-- only IPv4 addresses.
targetAddress_ip :: Lens.Lens' TargetAddress Prelude.Text
targetAddress_ip :: (Text -> f Text) -> TargetAddress -> f TargetAddress
targetAddress_ip = (TargetAddress -> Text)
-> (TargetAddress -> Text -> TargetAddress)
-> Lens TargetAddress TargetAddress Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetAddress' {Text
ip :: Text
$sel:ip:TargetAddress' :: TargetAddress -> Text
ip} -> Text
ip) (\s :: TargetAddress
s@TargetAddress' {} Text
a -> TargetAddress
s {$sel:ip:TargetAddress' :: Text
ip = Text
a} :: TargetAddress)

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

instance Prelude.Hashable TargetAddress

instance Prelude.NFData TargetAddress

instance Core.ToJSON TargetAddress where
  toJSON :: TargetAddress -> Value
toJSON TargetAddress' {Maybe Natural
Text
ip :: Text
port :: Maybe Natural
$sel:ip:TargetAddress' :: TargetAddress -> Text
$sel:port:TargetAddress' :: TargetAddress -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Port" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
port,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Ip" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ip)
          ]
      )