{-# 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.GetQueryState
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns the state of a query previously submitted. Clients are expected
-- to poll @GetQueryState@ to monitor the current state of the planning
-- before retrieving the work units. A query state is only visible to the
-- principal that made the initial call to @StartQueryPlanning@.
module Amazonka.LakeFormation.GetQueryState
  ( -- * Creating a Request
    GetQueryState (..),
    newGetQueryState,

    -- * Request Lenses
    getQueryState_queryId,

    -- * Destructuring the Response
    GetQueryStateResponse (..),
    newGetQueryStateResponse,

    -- * Response Lenses
    getQueryStateResponse_error,
    getQueryStateResponse_httpStatus,
    getQueryStateResponse_state,
  )
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:/ 'newGetQueryState' smart constructor.
data GetQueryState = GetQueryState'
  { -- | The ID of the plan query operation.
    GetQueryState -> Text
queryId :: Prelude.Text
  }
  deriving (GetQueryState -> GetQueryState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetQueryState -> GetQueryState -> Bool
$c/= :: GetQueryState -> GetQueryState -> Bool
== :: GetQueryState -> GetQueryState -> Bool
$c== :: GetQueryState -> GetQueryState -> Bool
Prelude.Eq, ReadPrec [GetQueryState]
ReadPrec GetQueryState
Int -> ReadS GetQueryState
ReadS [GetQueryState]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetQueryState]
$creadListPrec :: ReadPrec [GetQueryState]
readPrec :: ReadPrec GetQueryState
$creadPrec :: ReadPrec GetQueryState
readList :: ReadS [GetQueryState]
$creadList :: ReadS [GetQueryState]
readsPrec :: Int -> ReadS GetQueryState
$creadsPrec :: Int -> ReadS GetQueryState
Prelude.Read, Int -> GetQueryState -> ShowS
[GetQueryState] -> ShowS
GetQueryState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetQueryState] -> ShowS
$cshowList :: [GetQueryState] -> ShowS
show :: GetQueryState -> String
$cshow :: GetQueryState -> String
showsPrec :: Int -> GetQueryState -> ShowS
$cshowsPrec :: Int -> GetQueryState -> ShowS
Prelude.Show, forall x. Rep GetQueryState x -> GetQueryState
forall x. GetQueryState -> Rep GetQueryState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetQueryState x -> GetQueryState
$cfrom :: forall x. GetQueryState -> Rep GetQueryState x
Prelude.Generic)

-- |
-- Create a value of 'GetQueryState' 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:
--
-- 'queryId', 'getQueryState_queryId' - The ID of the plan query operation.
newGetQueryState ::
  -- | 'queryId'
  Prelude.Text ->
  GetQueryState
newGetQueryState :: Text -> GetQueryState
newGetQueryState Text
pQueryId_ =
  GetQueryState' {$sel:queryId:GetQueryState' :: Text
queryId = Text
pQueryId_}

-- | The ID of the plan query operation.
getQueryState_queryId :: Lens.Lens' GetQueryState Prelude.Text
getQueryState_queryId :: Lens' GetQueryState Text
getQueryState_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetQueryState' {Text
queryId :: Text
$sel:queryId:GetQueryState' :: GetQueryState -> Text
queryId} -> Text
queryId) (\s :: GetQueryState
s@GetQueryState' {} Text
a -> GetQueryState
s {$sel:queryId:GetQueryState' :: Text
queryId = Text
a} :: GetQueryState)

instance Core.AWSRequest GetQueryState where
  type
    AWSResponse GetQueryState =
      GetQueryStateResponse
  request :: (Service -> Service) -> GetQueryState -> Request GetQueryState
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 GetQueryState
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetQueryState)))
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 ->
          Maybe Text -> Int -> QueryStateString -> GetQueryStateResponse
GetQueryStateResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Error")
            forall (f :: * -> *) a b. Applicative f => 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
"State")
      )

instance Prelude.Hashable GetQueryState where
  hashWithSalt :: Int -> GetQueryState -> Int
hashWithSalt Int
_salt GetQueryState' {Text
queryId :: Text
$sel:queryId:GetQueryState' :: GetQueryState -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
queryId

instance Prelude.NFData GetQueryState where
  rnf :: GetQueryState -> ()
rnf GetQueryState' {Text
queryId :: Text
$sel:queryId:GetQueryState' :: GetQueryState -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
queryId

instance Data.ToHeaders GetQueryState where
  toHeaders :: GetQueryState -> 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 GetQueryState where
  toJSON :: GetQueryState -> Value
toJSON GetQueryState' {Text
queryId :: Text
$sel:queryId:GetQueryState' :: GetQueryState -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"QueryId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
queryId)]
      )

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

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

-- | A structure for the output.
--
-- /See:/ 'newGetQueryStateResponse' smart constructor.
data GetQueryStateResponse = GetQueryStateResponse'
  { -- | An error message when the operation fails.
    GetQueryStateResponse -> Maybe Text
error :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetQueryStateResponse -> Int
httpStatus :: Prelude.Int,
    -- | The state of a query previously submitted. The possible states are:
    --
    -- -   PENDING: the query is pending.
    --
    -- -   WORKUNITS_AVAILABLE: some work units are ready for retrieval and
    --     execution.
    --
    -- -   FINISHED: the query planning finished successfully, and all work
    --     units are ready for retrieval and execution.
    --
    -- -   ERROR: an error occurred with the query, such as an invalid query ID
    --     or a backend error.
    GetQueryStateResponse -> QueryStateString
state :: QueryStateString
  }
  deriving (GetQueryStateResponse -> GetQueryStateResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetQueryStateResponse -> GetQueryStateResponse -> Bool
$c/= :: GetQueryStateResponse -> GetQueryStateResponse -> Bool
== :: GetQueryStateResponse -> GetQueryStateResponse -> Bool
$c== :: GetQueryStateResponse -> GetQueryStateResponse -> Bool
Prelude.Eq, ReadPrec [GetQueryStateResponse]
ReadPrec GetQueryStateResponse
Int -> ReadS GetQueryStateResponse
ReadS [GetQueryStateResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetQueryStateResponse]
$creadListPrec :: ReadPrec [GetQueryStateResponse]
readPrec :: ReadPrec GetQueryStateResponse
$creadPrec :: ReadPrec GetQueryStateResponse
readList :: ReadS [GetQueryStateResponse]
$creadList :: ReadS [GetQueryStateResponse]
readsPrec :: Int -> ReadS GetQueryStateResponse
$creadsPrec :: Int -> ReadS GetQueryStateResponse
Prelude.Read, Int -> GetQueryStateResponse -> ShowS
[GetQueryStateResponse] -> ShowS
GetQueryStateResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetQueryStateResponse] -> ShowS
$cshowList :: [GetQueryStateResponse] -> ShowS
show :: GetQueryStateResponse -> String
$cshow :: GetQueryStateResponse -> String
showsPrec :: Int -> GetQueryStateResponse -> ShowS
$cshowsPrec :: Int -> GetQueryStateResponse -> ShowS
Prelude.Show, forall x. Rep GetQueryStateResponse x -> GetQueryStateResponse
forall x. GetQueryStateResponse -> Rep GetQueryStateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetQueryStateResponse x -> GetQueryStateResponse
$cfrom :: forall x. GetQueryStateResponse -> Rep GetQueryStateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetQueryStateResponse' 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:
--
-- 'error', 'getQueryStateResponse_error' - An error message when the operation fails.
--
-- 'httpStatus', 'getQueryStateResponse_httpStatus' - The response's http status code.
--
-- 'state', 'getQueryStateResponse_state' - The state of a query previously submitted. The possible states are:
--
-- -   PENDING: the query is pending.
--
-- -   WORKUNITS_AVAILABLE: some work units are ready for retrieval and
--     execution.
--
-- -   FINISHED: the query planning finished successfully, and all work
--     units are ready for retrieval and execution.
--
-- -   ERROR: an error occurred with the query, such as an invalid query ID
--     or a backend error.
newGetQueryStateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'state'
  QueryStateString ->
  GetQueryStateResponse
newGetQueryStateResponse :: Int -> QueryStateString -> GetQueryStateResponse
newGetQueryStateResponse Int
pHttpStatus_ QueryStateString
pState_ =
  GetQueryStateResponse'
    { $sel:error:GetQueryStateResponse' :: Maybe Text
error = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetQueryStateResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:state:GetQueryStateResponse' :: QueryStateString
state = QueryStateString
pState_
    }

-- | An error message when the operation fails.
getQueryStateResponse_error :: Lens.Lens' GetQueryStateResponse (Prelude.Maybe Prelude.Text)
getQueryStateResponse_error :: Lens' GetQueryStateResponse (Maybe Text)
getQueryStateResponse_error = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetQueryStateResponse' {Maybe Text
error :: Maybe Text
$sel:error:GetQueryStateResponse' :: GetQueryStateResponse -> Maybe Text
error} -> Maybe Text
error) (\s :: GetQueryStateResponse
s@GetQueryStateResponse' {} Maybe Text
a -> GetQueryStateResponse
s {$sel:error:GetQueryStateResponse' :: Maybe Text
error = Maybe Text
a} :: GetQueryStateResponse)

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

-- | The state of a query previously submitted. The possible states are:
--
-- -   PENDING: the query is pending.
--
-- -   WORKUNITS_AVAILABLE: some work units are ready for retrieval and
--     execution.
--
-- -   FINISHED: the query planning finished successfully, and all work
--     units are ready for retrieval and execution.
--
-- -   ERROR: an error occurred with the query, such as an invalid query ID
--     or a backend error.
getQueryStateResponse_state :: Lens.Lens' GetQueryStateResponse QueryStateString
getQueryStateResponse_state :: Lens' GetQueryStateResponse QueryStateString
getQueryStateResponse_state = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetQueryStateResponse' {QueryStateString
state :: QueryStateString
$sel:state:GetQueryStateResponse' :: GetQueryStateResponse -> QueryStateString
state} -> QueryStateString
state) (\s :: GetQueryStateResponse
s@GetQueryStateResponse' {} QueryStateString
a -> GetQueryStateResponse
s {$sel:state:GetQueryStateResponse' :: QueryStateString
state = QueryStateString
a} :: GetQueryStateResponse)

instance Prelude.NFData GetQueryStateResponse where
  rnf :: GetQueryStateResponse -> ()
rnf GetQueryStateResponse' {Int
Maybe Text
QueryStateString
state :: QueryStateString
httpStatus :: Int
error :: Maybe Text
$sel:state:GetQueryStateResponse' :: GetQueryStateResponse -> QueryStateString
$sel:httpStatus:GetQueryStateResponse' :: GetQueryStateResponse -> Int
$sel:error:GetQueryStateResponse' :: GetQueryStateResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
error
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 QueryStateString
state