{-# 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.CreateUserDefinedFunction
-- 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 new function definition in the Data Catalog.
module Amazonka.Glue.CreateUserDefinedFunction
  ( -- * Creating a Request
    CreateUserDefinedFunction (..),
    newCreateUserDefinedFunction,

    -- * Request Lenses
    createUserDefinedFunction_catalogId,
    createUserDefinedFunction_databaseName,
    createUserDefinedFunction_functionInput,

    -- * Destructuring the Response
    CreateUserDefinedFunctionResponse (..),
    newCreateUserDefinedFunctionResponse,

    -- * Response Lenses
    createUserDefinedFunctionResponse_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:/ 'newCreateUserDefinedFunction' smart constructor.
data CreateUserDefinedFunction = CreateUserDefinedFunction'
  { -- | The ID of the Data Catalog in which to create the function. If none is
    -- provided, the Amazon Web Services account ID is used by default.
    CreateUserDefinedFunction -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the catalog database in which to create the function.
    CreateUserDefinedFunction -> Text
databaseName :: Prelude.Text,
    -- | A @FunctionInput@ object that defines the function to create in the Data
    -- Catalog.
    CreateUserDefinedFunction -> UserDefinedFunctionInput
functionInput :: UserDefinedFunctionInput
  }
  deriving (CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool
(CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool)
-> (CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool)
-> Eq CreateUserDefinedFunction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool
$c/= :: CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool
== :: CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool
$c== :: CreateUserDefinedFunction -> CreateUserDefinedFunction -> Bool
Prelude.Eq, ReadPrec [CreateUserDefinedFunction]
ReadPrec CreateUserDefinedFunction
Int -> ReadS CreateUserDefinedFunction
ReadS [CreateUserDefinedFunction]
(Int -> ReadS CreateUserDefinedFunction)
-> ReadS [CreateUserDefinedFunction]
-> ReadPrec CreateUserDefinedFunction
-> ReadPrec [CreateUserDefinedFunction]
-> Read CreateUserDefinedFunction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUserDefinedFunction]
$creadListPrec :: ReadPrec [CreateUserDefinedFunction]
readPrec :: ReadPrec CreateUserDefinedFunction
$creadPrec :: ReadPrec CreateUserDefinedFunction
readList :: ReadS [CreateUserDefinedFunction]
$creadList :: ReadS [CreateUserDefinedFunction]
readsPrec :: Int -> ReadS CreateUserDefinedFunction
$creadsPrec :: Int -> ReadS CreateUserDefinedFunction
Prelude.Read, Int -> CreateUserDefinedFunction -> ShowS
[CreateUserDefinedFunction] -> ShowS
CreateUserDefinedFunction -> String
(Int -> CreateUserDefinedFunction -> ShowS)
-> (CreateUserDefinedFunction -> String)
-> ([CreateUserDefinedFunction] -> ShowS)
-> Show CreateUserDefinedFunction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUserDefinedFunction] -> ShowS
$cshowList :: [CreateUserDefinedFunction] -> ShowS
show :: CreateUserDefinedFunction -> String
$cshow :: CreateUserDefinedFunction -> String
showsPrec :: Int -> CreateUserDefinedFunction -> ShowS
$cshowsPrec :: Int -> CreateUserDefinedFunction -> ShowS
Prelude.Show, (forall x.
 CreateUserDefinedFunction -> Rep CreateUserDefinedFunction x)
-> (forall x.
    Rep CreateUserDefinedFunction x -> CreateUserDefinedFunction)
-> Generic CreateUserDefinedFunction
forall x.
Rep CreateUserDefinedFunction x -> CreateUserDefinedFunction
forall x.
CreateUserDefinedFunction -> Rep CreateUserDefinedFunction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateUserDefinedFunction x -> CreateUserDefinedFunction
$cfrom :: forall x.
CreateUserDefinedFunction -> Rep CreateUserDefinedFunction x
Prelude.Generic)

-- |
-- Create a value of 'CreateUserDefinedFunction' 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', 'createUserDefinedFunction_catalogId' - The ID of the Data Catalog in which to create the function. If none is
-- provided, the Amazon Web Services account ID is used by default.
--
-- 'databaseName', 'createUserDefinedFunction_databaseName' - The name of the catalog database in which to create the function.
--
-- 'functionInput', 'createUserDefinedFunction_functionInput' - A @FunctionInput@ object that defines the function to create in the Data
-- Catalog.
newCreateUserDefinedFunction ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'functionInput'
  UserDefinedFunctionInput ->
  CreateUserDefinedFunction
newCreateUserDefinedFunction :: Text -> UserDefinedFunctionInput -> CreateUserDefinedFunction
newCreateUserDefinedFunction
  Text
pDatabaseName_
  UserDefinedFunctionInput
pFunctionInput_ =
    CreateUserDefinedFunction' :: Maybe Text
-> Text -> UserDefinedFunctionInput -> CreateUserDefinedFunction
CreateUserDefinedFunction'
      { $sel:catalogId:CreateUserDefinedFunction' :: Maybe Text
catalogId =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:databaseName:CreateUserDefinedFunction' :: Text
databaseName = Text
pDatabaseName_,
        $sel:functionInput:CreateUserDefinedFunction' :: UserDefinedFunctionInput
functionInput = UserDefinedFunctionInput
pFunctionInput_
      }

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

-- | The name of the catalog database in which to create the function.
createUserDefinedFunction_databaseName :: Lens.Lens' CreateUserDefinedFunction Prelude.Text
createUserDefinedFunction_databaseName :: (Text -> f Text)
-> CreateUserDefinedFunction -> f CreateUserDefinedFunction
createUserDefinedFunction_databaseName = (CreateUserDefinedFunction -> Text)
-> (CreateUserDefinedFunction -> Text -> CreateUserDefinedFunction)
-> Lens
     CreateUserDefinedFunction CreateUserDefinedFunction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUserDefinedFunction' {Text
databaseName :: Text
$sel:databaseName:CreateUserDefinedFunction' :: CreateUserDefinedFunction -> Text
databaseName} -> Text
databaseName) (\s :: CreateUserDefinedFunction
s@CreateUserDefinedFunction' {} Text
a -> CreateUserDefinedFunction
s {$sel:databaseName:CreateUserDefinedFunction' :: Text
databaseName = Text
a} :: CreateUserDefinedFunction)

-- | A @FunctionInput@ object that defines the function to create in the Data
-- Catalog.
createUserDefinedFunction_functionInput :: Lens.Lens' CreateUserDefinedFunction UserDefinedFunctionInput
createUserDefinedFunction_functionInput :: (UserDefinedFunctionInput -> f UserDefinedFunctionInput)
-> CreateUserDefinedFunction -> f CreateUserDefinedFunction
createUserDefinedFunction_functionInput = (CreateUserDefinedFunction -> UserDefinedFunctionInput)
-> (CreateUserDefinedFunction
    -> UserDefinedFunctionInput -> CreateUserDefinedFunction)
-> Lens
     CreateUserDefinedFunction
     CreateUserDefinedFunction
     UserDefinedFunctionInput
     UserDefinedFunctionInput
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUserDefinedFunction' {UserDefinedFunctionInput
functionInput :: UserDefinedFunctionInput
$sel:functionInput:CreateUserDefinedFunction' :: CreateUserDefinedFunction -> UserDefinedFunctionInput
functionInput} -> UserDefinedFunctionInput
functionInput) (\s :: CreateUserDefinedFunction
s@CreateUserDefinedFunction' {} UserDefinedFunctionInput
a -> CreateUserDefinedFunction
s {$sel:functionInput:CreateUserDefinedFunction' :: UserDefinedFunctionInput
functionInput = UserDefinedFunctionInput
a} :: CreateUserDefinedFunction)

instance Core.AWSRequest CreateUserDefinedFunction where
  type
    AWSResponse CreateUserDefinedFunction =
      CreateUserDefinedFunctionResponse
  request :: CreateUserDefinedFunction -> Request CreateUserDefinedFunction
request = Service
-> CreateUserDefinedFunction -> Request CreateUserDefinedFunction
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateUserDefinedFunction
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateUserDefinedFunction)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateUserDefinedFunction))
-> Logger
-> Service
-> Proxy CreateUserDefinedFunction
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateUserDefinedFunction)))
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 -> CreateUserDefinedFunctionResponse
CreateUserDefinedFunctionResponse'
            (Int -> CreateUserDefinedFunctionResponse)
-> Either String Int
-> Either String CreateUserDefinedFunctionResponse
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 CreateUserDefinedFunction

instance Prelude.NFData CreateUserDefinedFunction

instance Core.ToHeaders CreateUserDefinedFunction where
  toHeaders :: CreateUserDefinedFunction -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateUserDefinedFunction -> 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.CreateUserDefinedFunction" ::
                          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 CreateUserDefinedFunction where
  toJSON :: CreateUserDefinedFunction -> Value
toJSON CreateUserDefinedFunction' {Maybe Text
Text
UserDefinedFunctionInput
functionInput :: UserDefinedFunctionInput
databaseName :: Text
catalogId :: Maybe Text
$sel:functionInput:CreateUserDefinedFunction' :: CreateUserDefinedFunction -> UserDefinedFunctionInput
$sel:databaseName:CreateUserDefinedFunction' :: CreateUserDefinedFunction -> Text
$sel:catalogId:CreateUserDefinedFunction' :: CreateUserDefinedFunction -> 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,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DatabaseName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
databaseName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"FunctionInput" Text -> UserDefinedFunctionInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= UserDefinedFunctionInput
functionInput)
          ]
      )

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

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

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

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

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

instance
  Prelude.NFData
    CreateUserDefinedFunctionResponse