{-# 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.Athena.CreatePreparedStatement
-- 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 prepared statement for use with SQL queries in Athena.
module Amazonka.Athena.CreatePreparedStatement
  ( -- * Creating a Request
    CreatePreparedStatement (..),
    newCreatePreparedStatement,

    -- * Request Lenses
    createPreparedStatement_description,
    createPreparedStatement_statementName,
    createPreparedStatement_workGroup,
    createPreparedStatement_queryStatement,

    -- * Destructuring the Response
    CreatePreparedStatementResponse (..),
    newCreatePreparedStatementResponse,

    -- * Response Lenses
    createPreparedStatementResponse_httpStatus,
  )
where

import Amazonka.Athena.Types
import qualified Amazonka.Core as Core
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:/ 'newCreatePreparedStatement' smart constructor.
data CreatePreparedStatement = CreatePreparedStatement'
  { -- | The description of the prepared statement.
    CreatePreparedStatement -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name of the prepared statement.
    CreatePreparedStatement -> Text
statementName :: Prelude.Text,
    -- | The name of the workgroup to which the prepared statement belongs.
    CreatePreparedStatement -> Text
workGroup :: Prelude.Text,
    -- | The query string for the prepared statement.
    CreatePreparedStatement -> Text
queryStatement :: Prelude.Text
  }
  deriving (CreatePreparedStatement -> CreatePreparedStatement -> Bool
(CreatePreparedStatement -> CreatePreparedStatement -> Bool)
-> (CreatePreparedStatement -> CreatePreparedStatement -> Bool)
-> Eq CreatePreparedStatement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePreparedStatement -> CreatePreparedStatement -> Bool
$c/= :: CreatePreparedStatement -> CreatePreparedStatement -> Bool
== :: CreatePreparedStatement -> CreatePreparedStatement -> Bool
$c== :: CreatePreparedStatement -> CreatePreparedStatement -> Bool
Prelude.Eq, ReadPrec [CreatePreparedStatement]
ReadPrec CreatePreparedStatement
Int -> ReadS CreatePreparedStatement
ReadS [CreatePreparedStatement]
(Int -> ReadS CreatePreparedStatement)
-> ReadS [CreatePreparedStatement]
-> ReadPrec CreatePreparedStatement
-> ReadPrec [CreatePreparedStatement]
-> Read CreatePreparedStatement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePreparedStatement]
$creadListPrec :: ReadPrec [CreatePreparedStatement]
readPrec :: ReadPrec CreatePreparedStatement
$creadPrec :: ReadPrec CreatePreparedStatement
readList :: ReadS [CreatePreparedStatement]
$creadList :: ReadS [CreatePreparedStatement]
readsPrec :: Int -> ReadS CreatePreparedStatement
$creadsPrec :: Int -> ReadS CreatePreparedStatement
Prelude.Read, Int -> CreatePreparedStatement -> ShowS
[CreatePreparedStatement] -> ShowS
CreatePreparedStatement -> String
(Int -> CreatePreparedStatement -> ShowS)
-> (CreatePreparedStatement -> String)
-> ([CreatePreparedStatement] -> ShowS)
-> Show CreatePreparedStatement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePreparedStatement] -> ShowS
$cshowList :: [CreatePreparedStatement] -> ShowS
show :: CreatePreparedStatement -> String
$cshow :: CreatePreparedStatement -> String
showsPrec :: Int -> CreatePreparedStatement -> ShowS
$cshowsPrec :: Int -> CreatePreparedStatement -> ShowS
Prelude.Show, (forall x.
 CreatePreparedStatement -> Rep CreatePreparedStatement x)
-> (forall x.
    Rep CreatePreparedStatement x -> CreatePreparedStatement)
-> Generic CreatePreparedStatement
forall x. Rep CreatePreparedStatement x -> CreatePreparedStatement
forall x. CreatePreparedStatement -> Rep CreatePreparedStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreatePreparedStatement x -> CreatePreparedStatement
$cfrom :: forall x. CreatePreparedStatement -> Rep CreatePreparedStatement x
Prelude.Generic)

-- |
-- Create a value of 'CreatePreparedStatement' 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:
--
-- 'description', 'createPreparedStatement_description' - The description of the prepared statement.
--
-- 'statementName', 'createPreparedStatement_statementName' - The name of the prepared statement.
--
-- 'workGroup', 'createPreparedStatement_workGroup' - The name of the workgroup to which the prepared statement belongs.
--
-- 'queryStatement', 'createPreparedStatement_queryStatement' - The query string for the prepared statement.
newCreatePreparedStatement ::
  -- | 'statementName'
  Prelude.Text ->
  -- | 'workGroup'
  Prelude.Text ->
  -- | 'queryStatement'
  Prelude.Text ->
  CreatePreparedStatement
newCreatePreparedStatement :: Text -> Text -> Text -> CreatePreparedStatement
newCreatePreparedStatement
  Text
pStatementName_
  Text
pWorkGroup_
  Text
pQueryStatement_ =
    CreatePreparedStatement' :: Maybe Text -> Text -> Text -> Text -> CreatePreparedStatement
CreatePreparedStatement'
      { $sel:description:CreatePreparedStatement' :: Maybe Text
description =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:statementName:CreatePreparedStatement' :: Text
statementName = Text
pStatementName_,
        $sel:workGroup:CreatePreparedStatement' :: Text
workGroup = Text
pWorkGroup_,
        $sel:queryStatement:CreatePreparedStatement' :: Text
queryStatement = Text
pQueryStatement_
      }

-- | The description of the prepared statement.
createPreparedStatement_description :: Lens.Lens' CreatePreparedStatement (Prelude.Maybe Prelude.Text)
createPreparedStatement_description :: (Maybe Text -> f (Maybe Text))
-> CreatePreparedStatement -> f CreatePreparedStatement
createPreparedStatement_description = (CreatePreparedStatement -> Maybe Text)
-> (CreatePreparedStatement
    -> Maybe Text -> CreatePreparedStatement)
-> Lens
     CreatePreparedStatement
     CreatePreparedStatement
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePreparedStatement' {Maybe Text
description :: Maybe Text
$sel:description:CreatePreparedStatement' :: CreatePreparedStatement -> Maybe Text
description} -> Maybe Text
description) (\s :: CreatePreparedStatement
s@CreatePreparedStatement' {} Maybe Text
a -> CreatePreparedStatement
s {$sel:description:CreatePreparedStatement' :: Maybe Text
description = Maybe Text
a} :: CreatePreparedStatement)

-- | The name of the prepared statement.
createPreparedStatement_statementName :: Lens.Lens' CreatePreparedStatement Prelude.Text
createPreparedStatement_statementName :: (Text -> f Text)
-> CreatePreparedStatement -> f CreatePreparedStatement
createPreparedStatement_statementName = (CreatePreparedStatement -> Text)
-> (CreatePreparedStatement -> Text -> CreatePreparedStatement)
-> Lens CreatePreparedStatement CreatePreparedStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePreparedStatement' {Text
statementName :: Text
$sel:statementName:CreatePreparedStatement' :: CreatePreparedStatement -> Text
statementName} -> Text
statementName) (\s :: CreatePreparedStatement
s@CreatePreparedStatement' {} Text
a -> CreatePreparedStatement
s {$sel:statementName:CreatePreparedStatement' :: Text
statementName = Text
a} :: CreatePreparedStatement)

-- | The name of the workgroup to which the prepared statement belongs.
createPreparedStatement_workGroup :: Lens.Lens' CreatePreparedStatement Prelude.Text
createPreparedStatement_workGroup :: (Text -> f Text)
-> CreatePreparedStatement -> f CreatePreparedStatement
createPreparedStatement_workGroup = (CreatePreparedStatement -> Text)
-> (CreatePreparedStatement -> Text -> CreatePreparedStatement)
-> Lens CreatePreparedStatement CreatePreparedStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePreparedStatement' {Text
workGroup :: Text
$sel:workGroup:CreatePreparedStatement' :: CreatePreparedStatement -> Text
workGroup} -> Text
workGroup) (\s :: CreatePreparedStatement
s@CreatePreparedStatement' {} Text
a -> CreatePreparedStatement
s {$sel:workGroup:CreatePreparedStatement' :: Text
workGroup = Text
a} :: CreatePreparedStatement)

-- | The query string for the prepared statement.
createPreparedStatement_queryStatement :: Lens.Lens' CreatePreparedStatement Prelude.Text
createPreparedStatement_queryStatement :: (Text -> f Text)
-> CreatePreparedStatement -> f CreatePreparedStatement
createPreparedStatement_queryStatement = (CreatePreparedStatement -> Text)
-> (CreatePreparedStatement -> Text -> CreatePreparedStatement)
-> Lens CreatePreparedStatement CreatePreparedStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePreparedStatement' {Text
queryStatement :: Text
$sel:queryStatement:CreatePreparedStatement' :: CreatePreparedStatement -> Text
queryStatement} -> Text
queryStatement) (\s :: CreatePreparedStatement
s@CreatePreparedStatement' {} Text
a -> CreatePreparedStatement
s {$sel:queryStatement:CreatePreparedStatement' :: Text
queryStatement = Text
a} :: CreatePreparedStatement)

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

instance Prelude.NFData CreatePreparedStatement

instance Core.ToHeaders CreatePreparedStatement where
  toHeaders :: CreatePreparedStatement -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreatePreparedStatement -> 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
"AmazonAthena.CreatePreparedStatement" ::
                          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 CreatePreparedStatement where
  toJSON :: CreatePreparedStatement -> Value
toJSON CreatePreparedStatement' {Maybe Text
Text
queryStatement :: Text
workGroup :: Text
statementName :: Text
description :: Maybe Text
$sel:queryStatement:CreatePreparedStatement' :: CreatePreparedStatement -> Text
$sel:workGroup:CreatePreparedStatement' :: CreatePreparedStatement -> Text
$sel:statementName:CreatePreparedStatement' :: CreatePreparedStatement -> Text
$sel:description:CreatePreparedStatement' :: CreatePreparedStatement -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Description" 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
description,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StatementName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
statementName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"WorkGroup" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
workGroup),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"QueryStatement" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
queryStatement)
          ]
      )

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

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

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

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

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

instance
  Prelude.NFData
    CreatePreparedStatementResponse