{-# 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.LakeFormation.StartQueryPlanning
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Submits a request to process a query statement.
--
-- This operation generates work units that can be retrieved with the
-- @GetWorkUnits@ operation as soon as the query state is
-- WORKUNITS_AVAILABLE or FINISHED.
module Amazonka.LakeFormation.StartQueryPlanning
  ( -- * Creating a Request
    StartQueryPlanning (..),
    newStartQueryPlanning,

    -- * Request Lenses
    startQueryPlanning_queryPlanningContext,
    startQueryPlanning_queryString,

    -- * Destructuring the Response
    StartQueryPlanningResponse (..),
    newStartQueryPlanningResponse,

    -- * Response Lenses
    startQueryPlanningResponse_httpStatus,
    startQueryPlanningResponse_queryId,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LakeFormation.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartQueryPlanning' smart constructor.
data StartQueryPlanning = StartQueryPlanning'
  { -- | A structure containing information about the query plan.
    StartQueryPlanning -> QueryPlanningContext
queryPlanningContext :: QueryPlanningContext,
    -- | A PartiQL query statement used as an input to the planner service.
    StartQueryPlanning -> Sensitive Text
queryString :: Data.Sensitive Prelude.Text
  }
  deriving (StartQueryPlanning -> StartQueryPlanning -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartQueryPlanning -> StartQueryPlanning -> Bool
$c/= :: StartQueryPlanning -> StartQueryPlanning -> Bool
== :: StartQueryPlanning -> StartQueryPlanning -> Bool
$c== :: StartQueryPlanning -> StartQueryPlanning -> Bool
Prelude.Eq, Int -> StartQueryPlanning -> ShowS
[StartQueryPlanning] -> ShowS
StartQueryPlanning -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartQueryPlanning] -> ShowS
$cshowList :: [StartQueryPlanning] -> ShowS
show :: StartQueryPlanning -> String
$cshow :: StartQueryPlanning -> String
showsPrec :: Int -> StartQueryPlanning -> ShowS
$cshowsPrec :: Int -> StartQueryPlanning -> ShowS
Prelude.Show, forall x. Rep StartQueryPlanning x -> StartQueryPlanning
forall x. StartQueryPlanning -> Rep StartQueryPlanning x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartQueryPlanning x -> StartQueryPlanning
$cfrom :: forall x. StartQueryPlanning -> Rep StartQueryPlanning x
Prelude.Generic)

-- |
-- Create a value of 'StartQueryPlanning' 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:
--
-- 'queryPlanningContext', 'startQueryPlanning_queryPlanningContext' - A structure containing information about the query plan.
--
-- 'queryString', 'startQueryPlanning_queryString' - A PartiQL query statement used as an input to the planner service.
newStartQueryPlanning ::
  -- | 'queryPlanningContext'
  QueryPlanningContext ->
  -- | 'queryString'
  Prelude.Text ->
  StartQueryPlanning
newStartQueryPlanning :: QueryPlanningContext -> Text -> StartQueryPlanning
newStartQueryPlanning
  QueryPlanningContext
pQueryPlanningContext_
  Text
pQueryString_ =
    StartQueryPlanning'
      { $sel:queryPlanningContext:StartQueryPlanning' :: QueryPlanningContext
queryPlanningContext =
          QueryPlanningContext
pQueryPlanningContext_,
        $sel:queryString:StartQueryPlanning' :: Sensitive Text
queryString = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pQueryString_
      }

-- | A structure containing information about the query plan.
startQueryPlanning_queryPlanningContext :: Lens.Lens' StartQueryPlanning QueryPlanningContext
startQueryPlanning_queryPlanningContext :: Lens' StartQueryPlanning QueryPlanningContext
startQueryPlanning_queryPlanningContext = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartQueryPlanning' {QueryPlanningContext
queryPlanningContext :: QueryPlanningContext
$sel:queryPlanningContext:StartQueryPlanning' :: StartQueryPlanning -> QueryPlanningContext
queryPlanningContext} -> QueryPlanningContext
queryPlanningContext) (\s :: StartQueryPlanning
s@StartQueryPlanning' {} QueryPlanningContext
a -> StartQueryPlanning
s {$sel:queryPlanningContext:StartQueryPlanning' :: QueryPlanningContext
queryPlanningContext = QueryPlanningContext
a} :: StartQueryPlanning)

-- | A PartiQL query statement used as an input to the planner service.
startQueryPlanning_queryString :: Lens.Lens' StartQueryPlanning Prelude.Text
startQueryPlanning_queryString :: Lens' StartQueryPlanning Text
startQueryPlanning_queryString = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartQueryPlanning' {Sensitive Text
queryString :: Sensitive Text
$sel:queryString:StartQueryPlanning' :: StartQueryPlanning -> Sensitive Text
queryString} -> Sensitive Text
queryString) (\s :: StartQueryPlanning
s@StartQueryPlanning' {} Sensitive Text
a -> StartQueryPlanning
s {$sel:queryString:StartQueryPlanning' :: Sensitive Text
queryString = Sensitive Text
a} :: StartQueryPlanning) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest StartQueryPlanning where
  type
    AWSResponse StartQueryPlanning =
      StartQueryPlanningResponse
  request :: (Service -> Service)
-> StartQueryPlanning -> Request StartQueryPlanning
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy StartQueryPlanning
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartQueryPlanning)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> StartQueryPlanningResponse
StartQueryPlanningResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"QueryId")
      )

instance Prelude.Hashable StartQueryPlanning where
  hashWithSalt :: Int -> StartQueryPlanning -> Int
hashWithSalt Int
_salt StartQueryPlanning' {Sensitive Text
QueryPlanningContext
queryString :: Sensitive Text
queryPlanningContext :: QueryPlanningContext
$sel:queryString:StartQueryPlanning' :: StartQueryPlanning -> Sensitive Text
$sel:queryPlanningContext:StartQueryPlanning' :: StartQueryPlanning -> QueryPlanningContext
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` QueryPlanningContext
queryPlanningContext
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
queryString

instance Prelude.NFData StartQueryPlanning where
  rnf :: StartQueryPlanning -> ()
rnf StartQueryPlanning' {Sensitive Text
QueryPlanningContext
queryString :: Sensitive Text
queryPlanningContext :: QueryPlanningContext
$sel:queryString:StartQueryPlanning' :: StartQueryPlanning -> Sensitive Text
$sel:queryPlanningContext:StartQueryPlanning' :: StartQueryPlanning -> QueryPlanningContext
..} =
    forall a. NFData a => a -> ()
Prelude.rnf QueryPlanningContext
queryPlanningContext
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
queryString

instance Data.ToHeaders StartQueryPlanning where
  toHeaders :: StartQueryPlanning -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON StartQueryPlanning where
  toJSON :: StartQueryPlanning -> Value
toJSON StartQueryPlanning' {Sensitive Text
QueryPlanningContext
queryString :: Sensitive Text
queryPlanningContext :: QueryPlanningContext
$sel:queryString:StartQueryPlanning' :: StartQueryPlanning -> Sensitive Text
$sel:queryPlanningContext:StartQueryPlanning' :: StartQueryPlanning -> QueryPlanningContext
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"QueryPlanningContext"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= QueryPlanningContext
queryPlanningContext
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"QueryString" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
queryString)
          ]
      )

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

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

-- | A structure for the output.
--
-- /See:/ 'newStartQueryPlanningResponse' smart constructor.
data StartQueryPlanningResponse = StartQueryPlanningResponse'
  { -- | The response's http status code.
    StartQueryPlanningResponse -> Int
httpStatus :: Prelude.Int,
    -- | The ID of the plan query operation can be used to fetch the actual work
    -- unit descriptors that are produced as the result of the operation. The
    -- ID is also used to get the query state and as an input to the @Execute@
    -- operation.
    StartQueryPlanningResponse -> Text
queryId :: Prelude.Text
  }
  deriving (StartQueryPlanningResponse -> StartQueryPlanningResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartQueryPlanningResponse -> StartQueryPlanningResponse -> Bool
$c/= :: StartQueryPlanningResponse -> StartQueryPlanningResponse -> Bool
== :: StartQueryPlanningResponse -> StartQueryPlanningResponse -> Bool
$c== :: StartQueryPlanningResponse -> StartQueryPlanningResponse -> Bool
Prelude.Eq, ReadPrec [StartQueryPlanningResponse]
ReadPrec StartQueryPlanningResponse
Int -> ReadS StartQueryPlanningResponse
ReadS [StartQueryPlanningResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartQueryPlanningResponse]
$creadListPrec :: ReadPrec [StartQueryPlanningResponse]
readPrec :: ReadPrec StartQueryPlanningResponse
$creadPrec :: ReadPrec StartQueryPlanningResponse
readList :: ReadS [StartQueryPlanningResponse]
$creadList :: ReadS [StartQueryPlanningResponse]
readsPrec :: Int -> ReadS StartQueryPlanningResponse
$creadsPrec :: Int -> ReadS StartQueryPlanningResponse
Prelude.Read, Int -> StartQueryPlanningResponse -> ShowS
[StartQueryPlanningResponse] -> ShowS
StartQueryPlanningResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartQueryPlanningResponse] -> ShowS
$cshowList :: [StartQueryPlanningResponse] -> ShowS
show :: StartQueryPlanningResponse -> String
$cshow :: StartQueryPlanningResponse -> String
showsPrec :: Int -> StartQueryPlanningResponse -> ShowS
$cshowsPrec :: Int -> StartQueryPlanningResponse -> ShowS
Prelude.Show, forall x.
Rep StartQueryPlanningResponse x -> StartQueryPlanningResponse
forall x.
StartQueryPlanningResponse -> Rep StartQueryPlanningResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartQueryPlanningResponse x -> StartQueryPlanningResponse
$cfrom :: forall x.
StartQueryPlanningResponse -> Rep StartQueryPlanningResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartQueryPlanningResponse' 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', 'startQueryPlanningResponse_httpStatus' - The response's http status code.
--
-- 'queryId', 'startQueryPlanningResponse_queryId' - The ID of the plan query operation can be used to fetch the actual work
-- unit descriptors that are produced as the result of the operation. The
-- ID is also used to get the query state and as an input to the @Execute@
-- operation.
newStartQueryPlanningResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'queryId'
  Prelude.Text ->
  StartQueryPlanningResponse
newStartQueryPlanningResponse :: Int -> Text -> StartQueryPlanningResponse
newStartQueryPlanningResponse Int
pHttpStatus_ Text
pQueryId_ =
  StartQueryPlanningResponse'
    { $sel:httpStatus:StartQueryPlanningResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:queryId:StartQueryPlanningResponse' :: Text
queryId = Text
pQueryId_
    }

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

-- | The ID of the plan query operation can be used to fetch the actual work
-- unit descriptors that are produced as the result of the operation. The
-- ID is also used to get the query state and as an input to the @Execute@
-- operation.
startQueryPlanningResponse_queryId :: Lens.Lens' StartQueryPlanningResponse Prelude.Text
startQueryPlanningResponse_queryId :: Lens' StartQueryPlanningResponse Text
startQueryPlanningResponse_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartQueryPlanningResponse' {Text
queryId :: Text
$sel:queryId:StartQueryPlanningResponse' :: StartQueryPlanningResponse -> Text
queryId} -> Text
queryId) (\s :: StartQueryPlanningResponse
s@StartQueryPlanningResponse' {} Text
a -> StartQueryPlanningResponse
s {$sel:queryId:StartQueryPlanningResponse' :: Text
queryId = Text
a} :: StartQueryPlanningResponse)

instance Prelude.NFData StartQueryPlanningResponse where
  rnf :: StartQueryPlanningResponse -> ()
rnf StartQueryPlanningResponse' {Int
Text
queryId :: Text
httpStatus :: Int
$sel:queryId:StartQueryPlanningResponse' :: StartQueryPlanningResponse -> Text
$sel:httpStatus:StartQueryPlanningResponse' :: StartQueryPlanningResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
queryId