{-# 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.Redshift.Types.Endpoint
-- 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.Redshift.Types.Endpoint where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Redshift.Internal
import Amazonka.Redshift.Types.VpcEndpoint

-- | Describes a connection endpoint.
--
-- /See:/ 'newEndpoint' smart constructor.
data Endpoint = Endpoint'
  { -- | The DNS address of the Cluster.
    Endpoint -> Maybe Text
address :: Prelude.Maybe Prelude.Text,
    -- | Describes a connection endpoint.
    Endpoint -> Maybe [VpcEndpoint]
vpcEndpoints :: Prelude.Maybe [VpcEndpoint],
    -- | The port that the database engine is listening on.
    Endpoint -> Maybe Int
port :: Prelude.Maybe Prelude.Int
  }
  deriving (Endpoint -> Endpoint -> Bool
(Endpoint -> Endpoint -> Bool)
-> (Endpoint -> Endpoint -> Bool) -> Eq Endpoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Endpoint -> Endpoint -> Bool
$c/= :: Endpoint -> Endpoint -> Bool
== :: Endpoint -> Endpoint -> Bool
$c== :: Endpoint -> Endpoint -> Bool
Prelude.Eq, ReadPrec [Endpoint]
ReadPrec Endpoint
Int -> ReadS Endpoint
ReadS [Endpoint]
(Int -> ReadS Endpoint)
-> ReadS [Endpoint]
-> ReadPrec Endpoint
-> ReadPrec [Endpoint]
-> Read Endpoint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Endpoint]
$creadListPrec :: ReadPrec [Endpoint]
readPrec :: ReadPrec Endpoint
$creadPrec :: ReadPrec Endpoint
readList :: ReadS [Endpoint]
$creadList :: ReadS [Endpoint]
readsPrec :: Int -> ReadS Endpoint
$creadsPrec :: Int -> ReadS Endpoint
Prelude.Read, Int -> Endpoint -> ShowS
[Endpoint] -> ShowS
Endpoint -> String
(Int -> Endpoint -> ShowS)
-> (Endpoint -> String) -> ([Endpoint] -> ShowS) -> Show Endpoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Endpoint] -> ShowS
$cshowList :: [Endpoint] -> ShowS
show :: Endpoint -> String
$cshow :: Endpoint -> String
showsPrec :: Int -> Endpoint -> ShowS
$cshowsPrec :: Int -> Endpoint -> ShowS
Prelude.Show, (forall x. Endpoint -> Rep Endpoint x)
-> (forall x. Rep Endpoint x -> Endpoint) -> Generic Endpoint
forall x. Rep Endpoint x -> Endpoint
forall x. Endpoint -> Rep Endpoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Endpoint x -> Endpoint
$cfrom :: forall x. Endpoint -> Rep Endpoint x
Prelude.Generic)

-- |
-- Create a value of 'Endpoint' 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:
--
-- 'address', 'endpoint_address' - The DNS address of the Cluster.
--
-- 'vpcEndpoints', 'endpoint_vpcEndpoints' - Describes a connection endpoint.
--
-- 'port', 'endpoint_port' - The port that the database engine is listening on.
newEndpoint ::
  Endpoint
newEndpoint :: Endpoint
newEndpoint =
  Endpoint' :: Maybe Text -> Maybe [VpcEndpoint] -> Maybe Int -> Endpoint
Endpoint'
    { $sel:address:Endpoint' :: Maybe Text
address = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:vpcEndpoints:Endpoint' :: Maybe [VpcEndpoint]
vpcEndpoints = Maybe [VpcEndpoint]
forall a. Maybe a
Prelude.Nothing,
      $sel:port:Endpoint' :: Maybe Int
port = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The DNS address of the Cluster.
endpoint_address :: Lens.Lens' Endpoint (Prelude.Maybe Prelude.Text)
endpoint_address :: (Maybe Text -> f (Maybe Text)) -> Endpoint -> f Endpoint
endpoint_address = (Endpoint -> Maybe Text)
-> (Endpoint -> Maybe Text -> Endpoint)
-> Lens Endpoint Endpoint (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Endpoint' {Maybe Text
address :: Maybe Text
$sel:address:Endpoint' :: Endpoint -> Maybe Text
address} -> Maybe Text
address) (\s :: Endpoint
s@Endpoint' {} Maybe Text
a -> Endpoint
s {$sel:address:Endpoint' :: Maybe Text
address = Maybe Text
a} :: Endpoint)

-- | Describes a connection endpoint.
endpoint_vpcEndpoints :: Lens.Lens' Endpoint (Prelude.Maybe [VpcEndpoint])
endpoint_vpcEndpoints :: (Maybe [VpcEndpoint] -> f (Maybe [VpcEndpoint]))
-> Endpoint -> f Endpoint
endpoint_vpcEndpoints = (Endpoint -> Maybe [VpcEndpoint])
-> (Endpoint -> Maybe [VpcEndpoint] -> Endpoint)
-> Lens
     Endpoint Endpoint (Maybe [VpcEndpoint]) (Maybe [VpcEndpoint])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Endpoint' {Maybe [VpcEndpoint]
vpcEndpoints :: Maybe [VpcEndpoint]
$sel:vpcEndpoints:Endpoint' :: Endpoint -> Maybe [VpcEndpoint]
vpcEndpoints} -> Maybe [VpcEndpoint]
vpcEndpoints) (\s :: Endpoint
s@Endpoint' {} Maybe [VpcEndpoint]
a -> Endpoint
s {$sel:vpcEndpoints:Endpoint' :: Maybe [VpcEndpoint]
vpcEndpoints = Maybe [VpcEndpoint]
a} :: Endpoint) ((Maybe [VpcEndpoint] -> f (Maybe [VpcEndpoint]))
 -> Endpoint -> f Endpoint)
-> ((Maybe [VpcEndpoint] -> f (Maybe [VpcEndpoint]))
    -> Maybe [VpcEndpoint] -> f (Maybe [VpcEndpoint]))
-> (Maybe [VpcEndpoint] -> f (Maybe [VpcEndpoint]))
-> Endpoint
-> f Endpoint
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [VpcEndpoint] [VpcEndpoint] [VpcEndpoint] [VpcEndpoint]
-> Iso
     (Maybe [VpcEndpoint])
     (Maybe [VpcEndpoint])
     (Maybe [VpcEndpoint])
     (Maybe [VpcEndpoint])
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 [VpcEndpoint] [VpcEndpoint] [VpcEndpoint] [VpcEndpoint]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The port that the database engine is listening on.
endpoint_port :: Lens.Lens' Endpoint (Prelude.Maybe Prelude.Int)
endpoint_port :: (Maybe Int -> f (Maybe Int)) -> Endpoint -> f Endpoint
endpoint_port = (Endpoint -> Maybe Int)
-> (Endpoint -> Maybe Int -> Endpoint)
-> Lens Endpoint Endpoint (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Endpoint' {Maybe Int
port :: Maybe Int
$sel:port:Endpoint' :: Endpoint -> Maybe Int
port} -> Maybe Int
port) (\s :: Endpoint
s@Endpoint' {} Maybe Int
a -> Endpoint
s {$sel:port:Endpoint' :: Maybe Int
port = Maybe Int
a} :: Endpoint)

instance Core.FromXML Endpoint where
  parseXML :: [Node] -> Either String Endpoint
parseXML [Node]
x =
    Maybe Text -> Maybe [VpcEndpoint] -> Maybe Int -> Endpoint
Endpoint'
      (Maybe Text -> Maybe [VpcEndpoint] -> Maybe Int -> Endpoint)
-> Either String (Maybe Text)
-> Either String (Maybe [VpcEndpoint] -> Maybe Int -> Endpoint)
forall (f :: * -> *) a b. Functor 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
"Address")
      Either String (Maybe [VpcEndpoint] -> Maybe Int -> Endpoint)
-> Either String (Maybe [VpcEndpoint])
-> Either String (Maybe Int -> Endpoint)
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
"VpcEndpoints" 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 (Maybe [VpcEndpoint]))
-> Either String (Maybe [VpcEndpoint])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [VpcEndpoint])
-> [Node] -> Either String (Maybe [VpcEndpoint])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [VpcEndpoint]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"VpcEndpoint")
                  )
      Either String (Maybe Int -> Endpoint)
-> Either String (Maybe Int) -> Either String Endpoint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Port")

instance Prelude.Hashable Endpoint

instance Prelude.NFData Endpoint