{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Glue.CreateConnection
-- 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)
--
-- Creates a connection definition in the Data Catalog.
module Amazonka.Glue.CreateConnection
  ( -- * Creating a Request
    CreateConnection (..),
    newCreateConnection,

    -- * Request Lenses
    createConnection_catalogId,
    createConnection_tags,
    createConnection_connectionInput,

    -- * Destructuring the Response
    CreateConnectionResponse (..),
    newCreateConnectionResponse,

    -- * Response Lenses
    createConnectionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateConnection' smart constructor.
data CreateConnection = CreateConnection'
  { -- | The ID of the Data Catalog in which to create the connection. If none is
    -- provided, the Amazon Web Services account ID is used by default.
    CreateConnection -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The tags you assign to the connection.
    CreateConnection -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A @ConnectionInput@ object defining the connection to create.
    CreateConnection -> ConnectionInput
connectionInput :: ConnectionInput
  }
  deriving (CreateConnection -> CreateConnection -> Bool
(CreateConnection -> CreateConnection -> Bool)
-> (CreateConnection -> CreateConnection -> Bool)
-> Eq CreateConnection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConnection -> CreateConnection -> Bool
$c/= :: CreateConnection -> CreateConnection -> Bool
== :: CreateConnection -> CreateConnection -> Bool
$c== :: CreateConnection -> CreateConnection -> Bool
Prelude.Eq, ReadPrec [CreateConnection]
ReadPrec CreateConnection
Int -> ReadS CreateConnection
ReadS [CreateConnection]
(Int -> ReadS CreateConnection)
-> ReadS [CreateConnection]
-> ReadPrec CreateConnection
-> ReadPrec [CreateConnection]
-> Read CreateConnection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConnection]
$creadListPrec :: ReadPrec [CreateConnection]
readPrec :: ReadPrec CreateConnection
$creadPrec :: ReadPrec CreateConnection
readList :: ReadS [CreateConnection]
$creadList :: ReadS [CreateConnection]
readsPrec :: Int -> ReadS CreateConnection
$creadsPrec :: Int -> ReadS CreateConnection
Prelude.Read, Int -> CreateConnection -> ShowS
[CreateConnection] -> ShowS
CreateConnection -> String
(Int -> CreateConnection -> ShowS)
-> (CreateConnection -> String)
-> ([CreateConnection] -> ShowS)
-> Show CreateConnection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConnection] -> ShowS
$cshowList :: [CreateConnection] -> ShowS
show :: CreateConnection -> String
$cshow :: CreateConnection -> String
showsPrec :: Int -> CreateConnection -> ShowS
$cshowsPrec :: Int -> CreateConnection -> ShowS
Prelude.Show, (forall x. CreateConnection -> Rep CreateConnection x)
-> (forall x. Rep CreateConnection x -> CreateConnection)
-> Generic CreateConnection
forall x. Rep CreateConnection x -> CreateConnection
forall x. CreateConnection -> Rep CreateConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateConnection x -> CreateConnection
$cfrom :: forall x. CreateConnection -> Rep CreateConnection x
Prelude.Generic)

-- |
-- Create a value of 'CreateConnection' 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:
--
-- 'catalogId', 'createConnection_catalogId' - The ID of the Data Catalog in which to create the connection. If none is
-- provided, the Amazon Web Services account ID is used by default.
--
-- 'tags', 'createConnection_tags' - The tags you assign to the connection.
--
-- 'connectionInput', 'createConnection_connectionInput' - A @ConnectionInput@ object defining the connection to create.
newCreateConnection ::
  -- | 'connectionInput'
  ConnectionInput ->
  CreateConnection
newCreateConnection :: ConnectionInput -> CreateConnection
newCreateConnection ConnectionInput
pConnectionInput_ =
  CreateConnection' :: Maybe Text
-> Maybe (HashMap Text Text) -> ConnectionInput -> CreateConnection
CreateConnection'
    { $sel:catalogId:CreateConnection' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateConnection' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:connectionInput:CreateConnection' :: ConnectionInput
connectionInput = ConnectionInput
pConnectionInput_
    }

-- | The ID of the Data Catalog in which to create the connection. If none is
-- provided, the Amazon Web Services account ID is used by default.
createConnection_catalogId :: Lens.Lens' CreateConnection (Prelude.Maybe Prelude.Text)
createConnection_catalogId :: (Maybe Text -> f (Maybe Text))
-> CreateConnection -> f CreateConnection
createConnection_catalogId = (CreateConnection -> Maybe Text)
-> (CreateConnection -> Maybe Text -> CreateConnection)
-> Lens CreateConnection CreateConnection (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:CreateConnection' :: CreateConnection -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: CreateConnection
s@CreateConnection' {} Maybe Text
a -> CreateConnection
s {$sel:catalogId:CreateConnection' :: Maybe Text
catalogId = Maybe Text
a} :: CreateConnection)

-- | The tags you assign to the connection.
createConnection_tags :: Lens.Lens' CreateConnection (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createConnection_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateConnection -> f CreateConnection
createConnection_tags = (CreateConnection -> Maybe (HashMap Text Text))
-> (CreateConnection
    -> Maybe (HashMap Text Text) -> CreateConnection)
-> Lens
     CreateConnection
     CreateConnection
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateConnection' :: CreateConnection -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateConnection
s@CreateConnection' {} Maybe (HashMap Text Text)
a -> CreateConnection
s {$sel:tags:CreateConnection' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateConnection) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreateConnection -> f CreateConnection)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateConnection
-> f CreateConnection
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A @ConnectionInput@ object defining the connection to create.
createConnection_connectionInput :: Lens.Lens' CreateConnection ConnectionInput
createConnection_connectionInput :: (ConnectionInput -> f ConnectionInput)
-> CreateConnection -> f CreateConnection
createConnection_connectionInput = (CreateConnection -> ConnectionInput)
-> (CreateConnection -> ConnectionInput -> CreateConnection)
-> Lens
     CreateConnection CreateConnection ConnectionInput ConnectionInput
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {ConnectionInput
connectionInput :: ConnectionInput
$sel:connectionInput:CreateConnection' :: CreateConnection -> ConnectionInput
connectionInput} -> ConnectionInput
connectionInput) (\s :: CreateConnection
s@CreateConnection' {} ConnectionInput
a -> CreateConnection
s {$sel:connectionInput:CreateConnection' :: ConnectionInput
connectionInput = ConnectionInput
a} :: CreateConnection)

instance Core.AWSRequest CreateConnection where
  type
    AWSResponse CreateConnection =
      CreateConnectionResponse
  request :: CreateConnection -> Request CreateConnection
request = Service -> CreateConnection -> Request CreateConnection
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateConnection
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateConnection)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateConnection))
-> Logger
-> Service
-> Proxy CreateConnection
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateConnection)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreateConnectionResponse
CreateConnectionResponse'
            (Int -> CreateConnectionResponse)
-> Either String Int -> Either String CreateConnectionResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateConnection

instance Prelude.NFData CreateConnection

instance Core.ToHeaders CreateConnection where
  toHeaders :: CreateConnection -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateConnection -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AWSGlue.CreateConnection" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateConnection where
  toJSON :: CreateConnection -> Value
toJSON CreateConnection' {Maybe Text
Maybe (HashMap Text Text)
ConnectionInput
connectionInput :: ConnectionInput
tags :: Maybe (HashMap Text Text)
catalogId :: Maybe Text
$sel:connectionInput:CreateConnection' :: CreateConnection -> ConnectionInput
$sel:tags:CreateConnection' :: CreateConnection -> Maybe (HashMap Text Text)
$sel:catalogId:CreateConnection' :: CreateConnection -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CatalogId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            (Text
"Tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ConnectionInput" Text -> ConnectionInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ConnectionInput
connectionInput)
          ]
      )

instance Core.ToPath CreateConnection where
  toPath :: CreateConnection -> ByteString
toPath = ByteString -> CreateConnection -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery CreateConnection where
  toQuery :: CreateConnection -> QueryString
toQuery = QueryString -> CreateConnection -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateConnectionResponse' smart constructor.
data CreateConnectionResponse = CreateConnectionResponse'
  { -- | The response's http status code.
    CreateConnectionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateConnectionResponse -> CreateConnectionResponse -> Bool
(CreateConnectionResponse -> CreateConnectionResponse -> Bool)
-> (CreateConnectionResponse -> CreateConnectionResponse -> Bool)
-> Eq CreateConnectionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
$c/= :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
== :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
$c== :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
Prelude.Eq, ReadPrec [CreateConnectionResponse]
ReadPrec CreateConnectionResponse
Int -> ReadS CreateConnectionResponse
ReadS [CreateConnectionResponse]
(Int -> ReadS CreateConnectionResponse)
-> ReadS [CreateConnectionResponse]
-> ReadPrec CreateConnectionResponse
-> ReadPrec [CreateConnectionResponse]
-> Read CreateConnectionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConnectionResponse]
$creadListPrec :: ReadPrec [CreateConnectionResponse]
readPrec :: ReadPrec CreateConnectionResponse
$creadPrec :: ReadPrec CreateConnectionResponse
readList :: ReadS [CreateConnectionResponse]
$creadList :: ReadS [CreateConnectionResponse]
readsPrec :: Int -> ReadS CreateConnectionResponse
$creadsPrec :: Int -> ReadS CreateConnectionResponse
Prelude.Read, Int -> CreateConnectionResponse -> ShowS
[CreateConnectionResponse] -> ShowS
CreateConnectionResponse -> String
(Int -> CreateConnectionResponse -> ShowS)
-> (CreateConnectionResponse -> String)
-> ([CreateConnectionResponse] -> ShowS)
-> Show CreateConnectionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConnectionResponse] -> ShowS
$cshowList :: [CreateConnectionResponse] -> ShowS
show :: CreateConnectionResponse -> String
$cshow :: CreateConnectionResponse -> String
showsPrec :: Int -> CreateConnectionResponse -> ShowS
$cshowsPrec :: Int -> CreateConnectionResponse -> ShowS
Prelude.Show, (forall x.
 CreateConnectionResponse -> Rep CreateConnectionResponse x)
-> (forall x.
    Rep CreateConnectionResponse x -> CreateConnectionResponse)
-> Generic CreateConnectionResponse
forall x.
Rep CreateConnectionResponse x -> CreateConnectionResponse
forall x.
CreateConnectionResponse -> Rep CreateConnectionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateConnectionResponse x -> CreateConnectionResponse
$cfrom :: forall x.
CreateConnectionResponse -> Rep CreateConnectionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateConnectionResponse' 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:
--
-- 'httpStatus', 'createConnectionResponse_httpStatus' - The response's http status code.
newCreateConnectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateConnectionResponse
newCreateConnectionResponse :: Int -> CreateConnectionResponse
newCreateConnectionResponse Int
pHttpStatus_ =
  CreateConnectionResponse' :: Int -> CreateConnectionResponse
CreateConnectionResponse'
    { $sel:httpStatus:CreateConnectionResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
createConnectionResponse_httpStatus :: Lens.Lens' CreateConnectionResponse Prelude.Int
createConnectionResponse_httpStatus :: (Int -> f Int)
-> CreateConnectionResponse -> f CreateConnectionResponse
createConnectionResponse_httpStatus = (CreateConnectionResponse -> Int)
-> (CreateConnectionResponse -> Int -> CreateConnectionResponse)
-> Lens CreateConnectionResponse CreateConnectionResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnectionResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateConnectionResponse' :: CreateConnectionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateConnectionResponse
s@CreateConnectionResponse' {} Int
a -> CreateConnectionResponse
s {$sel:httpStatus:CreateConnectionResponse' :: Int
httpStatus = Int
a} :: CreateConnectionResponse)

instance Prelude.NFData CreateConnectionResponse