{-# 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.Kendra.Types.ConnectionConfiguration
-- 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.Kendra.Types.ConnectionConfiguration 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

-- | Provides the configuration information that\'s required to connect to a
-- database.
--
-- /See:/ 'newConnectionConfiguration' smart constructor.
data ConnectionConfiguration = ConnectionConfiguration'
  { -- | The name of the host for the database. Can be either a string
    -- (host.subdomain.domain.tld) or an IPv4 or IPv6 address.
    ConnectionConfiguration -> Text
databaseHost :: Prelude.Text,
    -- | The port that the database uses for connections.
    ConnectionConfiguration -> Natural
databasePort :: Prelude.Natural,
    -- | The name of the database containing the document data.
    ConnectionConfiguration -> Text
databaseName :: Prelude.Text,
    -- | The name of the table that contains the document data.
    ConnectionConfiguration -> Text
tableName :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of credentials stored in Secrets Manager.
    -- The credentials should be a user\/password pair. For more information,
    -- see
    -- <https://docs.aws.amazon.com/kendra/latest/dg/data-source-database.html Using a Database Data Source>.
    -- For more information about Secrets Manager, see
    -- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html What Is Secrets Manager>
    -- in the /Secrets Manager/ user guide.
    ConnectionConfiguration -> Text
secretArn :: Prelude.Text
  }
  deriving (ConnectionConfiguration -> ConnectionConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConnectionConfiguration -> ConnectionConfiguration -> Bool
$c/= :: ConnectionConfiguration -> ConnectionConfiguration -> Bool
== :: ConnectionConfiguration -> ConnectionConfiguration -> Bool
$c== :: ConnectionConfiguration -> ConnectionConfiguration -> Bool
Prelude.Eq, ReadPrec [ConnectionConfiguration]
ReadPrec ConnectionConfiguration
Int -> ReadS ConnectionConfiguration
ReadS [ConnectionConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConnectionConfiguration]
$creadListPrec :: ReadPrec [ConnectionConfiguration]
readPrec :: ReadPrec ConnectionConfiguration
$creadPrec :: ReadPrec ConnectionConfiguration
readList :: ReadS [ConnectionConfiguration]
$creadList :: ReadS [ConnectionConfiguration]
readsPrec :: Int -> ReadS ConnectionConfiguration
$creadsPrec :: Int -> ReadS ConnectionConfiguration
Prelude.Read, Int -> ConnectionConfiguration -> ShowS
[ConnectionConfiguration] -> ShowS
ConnectionConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionConfiguration] -> ShowS
$cshowList :: [ConnectionConfiguration] -> ShowS
show :: ConnectionConfiguration -> String
$cshow :: ConnectionConfiguration -> String
showsPrec :: Int -> ConnectionConfiguration -> ShowS
$cshowsPrec :: Int -> ConnectionConfiguration -> ShowS
Prelude.Show, forall x. Rep ConnectionConfiguration x -> ConnectionConfiguration
forall x. ConnectionConfiguration -> Rep ConnectionConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConnectionConfiguration x -> ConnectionConfiguration
$cfrom :: forall x. ConnectionConfiguration -> Rep ConnectionConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ConnectionConfiguration' 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:
--
-- 'databaseHost', 'connectionConfiguration_databaseHost' - The name of the host for the database. Can be either a string
-- (host.subdomain.domain.tld) or an IPv4 or IPv6 address.
--
-- 'databasePort', 'connectionConfiguration_databasePort' - The port that the database uses for connections.
--
-- 'databaseName', 'connectionConfiguration_databaseName' - The name of the database containing the document data.
--
-- 'tableName', 'connectionConfiguration_tableName' - The name of the table that contains the document data.
--
-- 'secretArn', 'connectionConfiguration_secretArn' - The Amazon Resource Name (ARN) of credentials stored in Secrets Manager.
-- The credentials should be a user\/password pair. For more information,
-- see
-- <https://docs.aws.amazon.com/kendra/latest/dg/data-source-database.html Using a Database Data Source>.
-- For more information about Secrets Manager, see
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html What Is Secrets Manager>
-- in the /Secrets Manager/ user guide.
newConnectionConfiguration ::
  -- | 'databaseHost'
  Prelude.Text ->
  -- | 'databasePort'
  Prelude.Natural ->
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  -- | 'secretArn'
  Prelude.Text ->
  ConnectionConfiguration
newConnectionConfiguration :: Text -> Natural -> Text -> Text -> Text -> ConnectionConfiguration
newConnectionConfiguration
  Text
pDatabaseHost_
  Natural
pDatabasePort_
  Text
pDatabaseName_
  Text
pTableName_
  Text
pSecretArn_ =
    ConnectionConfiguration'
      { $sel:databaseHost:ConnectionConfiguration' :: Text
databaseHost =
          Text
pDatabaseHost_,
        $sel:databasePort:ConnectionConfiguration' :: Natural
databasePort = Natural
pDatabasePort_,
        $sel:databaseName:ConnectionConfiguration' :: Text
databaseName = Text
pDatabaseName_,
        $sel:tableName:ConnectionConfiguration' :: Text
tableName = Text
pTableName_,
        $sel:secretArn:ConnectionConfiguration' :: Text
secretArn = Text
pSecretArn_
      }

-- | The name of the host for the database. Can be either a string
-- (host.subdomain.domain.tld) or an IPv4 or IPv6 address.
connectionConfiguration_databaseHost :: Lens.Lens' ConnectionConfiguration Prelude.Text
connectionConfiguration_databaseHost :: Lens' ConnectionConfiguration Text
connectionConfiguration_databaseHost = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionConfiguration' {Text
databaseHost :: Text
$sel:databaseHost:ConnectionConfiguration' :: ConnectionConfiguration -> Text
databaseHost} -> Text
databaseHost) (\s :: ConnectionConfiguration
s@ConnectionConfiguration' {} Text
a -> ConnectionConfiguration
s {$sel:databaseHost:ConnectionConfiguration' :: Text
databaseHost = Text
a} :: ConnectionConfiguration)

-- | The port that the database uses for connections.
connectionConfiguration_databasePort :: Lens.Lens' ConnectionConfiguration Prelude.Natural
connectionConfiguration_databasePort :: Lens' ConnectionConfiguration Natural
connectionConfiguration_databasePort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionConfiguration' {Natural
databasePort :: Natural
$sel:databasePort:ConnectionConfiguration' :: ConnectionConfiguration -> Natural
databasePort} -> Natural
databasePort) (\s :: ConnectionConfiguration
s@ConnectionConfiguration' {} Natural
a -> ConnectionConfiguration
s {$sel:databasePort:ConnectionConfiguration' :: Natural
databasePort = Natural
a} :: ConnectionConfiguration)

-- | The name of the database containing the document data.
connectionConfiguration_databaseName :: Lens.Lens' ConnectionConfiguration Prelude.Text
connectionConfiguration_databaseName :: Lens' ConnectionConfiguration Text
connectionConfiguration_databaseName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionConfiguration' {Text
databaseName :: Text
$sel:databaseName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
databaseName} -> Text
databaseName) (\s :: ConnectionConfiguration
s@ConnectionConfiguration' {} Text
a -> ConnectionConfiguration
s {$sel:databaseName:ConnectionConfiguration' :: Text
databaseName = Text
a} :: ConnectionConfiguration)

-- | The name of the table that contains the document data.
connectionConfiguration_tableName :: Lens.Lens' ConnectionConfiguration Prelude.Text
connectionConfiguration_tableName :: Lens' ConnectionConfiguration Text
connectionConfiguration_tableName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionConfiguration' {Text
tableName :: Text
$sel:tableName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
tableName} -> Text
tableName) (\s :: ConnectionConfiguration
s@ConnectionConfiguration' {} Text
a -> ConnectionConfiguration
s {$sel:tableName:ConnectionConfiguration' :: Text
tableName = Text
a} :: ConnectionConfiguration)

-- | The Amazon Resource Name (ARN) of credentials stored in Secrets Manager.
-- The credentials should be a user\/password pair. For more information,
-- see
-- <https://docs.aws.amazon.com/kendra/latest/dg/data-source-database.html Using a Database Data Source>.
-- For more information about Secrets Manager, see
-- <https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html What Is Secrets Manager>
-- in the /Secrets Manager/ user guide.
connectionConfiguration_secretArn :: Lens.Lens' ConnectionConfiguration Prelude.Text
connectionConfiguration_secretArn :: Lens' ConnectionConfiguration Text
connectionConfiguration_secretArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionConfiguration' {Text
secretArn :: Text
$sel:secretArn:ConnectionConfiguration' :: ConnectionConfiguration -> Text
secretArn} -> Text
secretArn) (\s :: ConnectionConfiguration
s@ConnectionConfiguration' {} Text
a -> ConnectionConfiguration
s {$sel:secretArn:ConnectionConfiguration' :: Text
secretArn = Text
a} :: ConnectionConfiguration)

instance Data.FromJSON ConnectionConfiguration where
  parseJSON :: Value -> Parser ConnectionConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ConnectionConfiguration"
      ( \Object
x ->
          Text -> Natural -> Text -> Text -> Text -> ConnectionConfiguration
ConnectionConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"DatabaseHost")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"DatabasePort")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"DatabaseName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"TableName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"SecretArn")
      )

instance Prelude.Hashable ConnectionConfiguration where
  hashWithSalt :: Int -> ConnectionConfiguration -> Int
hashWithSalt Int
_salt ConnectionConfiguration' {Natural
Text
secretArn :: Text
tableName :: Text
databaseName :: Text
databasePort :: Natural
databaseHost :: Text
$sel:secretArn:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:tableName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:databaseName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:databasePort:ConnectionConfiguration' :: ConnectionConfiguration -> Natural
$sel:databaseHost:ConnectionConfiguration' :: ConnectionConfiguration -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseHost
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
databasePort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
tableName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
secretArn

instance Prelude.NFData ConnectionConfiguration where
  rnf :: ConnectionConfiguration -> ()
rnf ConnectionConfiguration' {Natural
Text
secretArn :: Text
tableName :: Text
databaseName :: Text
databasePort :: Natural
databaseHost :: Text
$sel:secretArn:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:tableName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:databaseName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:databasePort:ConnectionConfiguration' :: ConnectionConfiguration -> Natural
$sel:databaseHost:ConnectionConfiguration' :: ConnectionConfiguration -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
databaseHost
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
databasePort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
databaseName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
tableName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
secretArn

instance Data.ToJSON ConnectionConfiguration where
  toJSON :: ConnectionConfiguration -> Value
toJSON ConnectionConfiguration' {Natural
Text
secretArn :: Text
tableName :: Text
databaseName :: Text
databasePort :: Natural
databaseHost :: Text
$sel:secretArn:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:tableName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:databaseName:ConnectionConfiguration' :: ConnectionConfiguration -> Text
$sel:databasePort:ConnectionConfiguration' :: ConnectionConfiguration -> Natural
$sel:databaseHost:ConnectionConfiguration' :: ConnectionConfiguration -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"DatabaseHost" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
databaseHost),
            forall a. a -> Maybe a
Prelude.Just (Key
"DatabasePort" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
databasePort),
            forall a. a -> Maybe a
Prelude.Just (Key
"DatabaseName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
databaseName),
            forall a. a -> Maybe a
Prelude.Just (Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
tableName),
            forall a. a -> Maybe a
Prelude.Just (Key
"SecretArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
secretArn)
          ]
      )