{-# 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.GetNamedQuery
-- 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 information about a single query. Requires that you have access
-- to the workgroup in which the query was saved.
module Amazonka.Athena.GetNamedQuery
  ( -- * Creating a Request
    GetNamedQuery (..),
    newGetNamedQuery,

    -- * Request Lenses
    getNamedQuery_namedQueryId,

    -- * Destructuring the Response
    GetNamedQueryResponse (..),
    newGetNamedQueryResponse,

    -- * Response Lenses
    getNamedQueryResponse_namedQuery,
    getNamedQueryResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetNamedQuery' smart constructor.
data GetNamedQuery = GetNamedQuery'
  { -- | The unique ID of the query. Use ListNamedQueries to get query IDs.
    GetNamedQuery -> Text
namedQueryId :: Prelude.Text
  }
  deriving (GetNamedQuery -> GetNamedQuery -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetNamedQuery -> GetNamedQuery -> Bool
$c/= :: GetNamedQuery -> GetNamedQuery -> Bool
== :: GetNamedQuery -> GetNamedQuery -> Bool
$c== :: GetNamedQuery -> GetNamedQuery -> Bool
Prelude.Eq, ReadPrec [GetNamedQuery]
ReadPrec GetNamedQuery
Int -> ReadS GetNamedQuery
ReadS [GetNamedQuery]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetNamedQuery]
$creadListPrec :: ReadPrec [GetNamedQuery]
readPrec :: ReadPrec GetNamedQuery
$creadPrec :: ReadPrec GetNamedQuery
readList :: ReadS [GetNamedQuery]
$creadList :: ReadS [GetNamedQuery]
readsPrec :: Int -> ReadS GetNamedQuery
$creadsPrec :: Int -> ReadS GetNamedQuery
Prelude.Read, Int -> GetNamedQuery -> ShowS
[GetNamedQuery] -> ShowS
GetNamedQuery -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetNamedQuery] -> ShowS
$cshowList :: [GetNamedQuery] -> ShowS
show :: GetNamedQuery -> String
$cshow :: GetNamedQuery -> String
showsPrec :: Int -> GetNamedQuery -> ShowS
$cshowsPrec :: Int -> GetNamedQuery -> ShowS
Prelude.Show, forall x. Rep GetNamedQuery x -> GetNamedQuery
forall x. GetNamedQuery -> Rep GetNamedQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetNamedQuery x -> GetNamedQuery
$cfrom :: forall x. GetNamedQuery -> Rep GetNamedQuery x
Prelude.Generic)

-- |
-- Create a value of 'GetNamedQuery' 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:
--
-- 'namedQueryId', 'getNamedQuery_namedQueryId' - The unique ID of the query. Use ListNamedQueries to get query IDs.
newGetNamedQuery ::
  -- | 'namedQueryId'
  Prelude.Text ->
  GetNamedQuery
newGetNamedQuery :: Text -> GetNamedQuery
newGetNamedQuery Text
pNamedQueryId_ =
  GetNamedQuery' {$sel:namedQueryId:GetNamedQuery' :: Text
namedQueryId = Text
pNamedQueryId_}

-- | The unique ID of the query. Use ListNamedQueries to get query IDs.
getNamedQuery_namedQueryId :: Lens.Lens' GetNamedQuery Prelude.Text
getNamedQuery_namedQueryId :: Lens' GetNamedQuery Text
getNamedQuery_namedQueryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetNamedQuery' {Text
namedQueryId :: Text
$sel:namedQueryId:GetNamedQuery' :: GetNamedQuery -> Text
namedQueryId} -> Text
namedQueryId) (\s :: GetNamedQuery
s@GetNamedQuery' {} Text
a -> GetNamedQuery
s {$sel:namedQueryId:GetNamedQuery' :: Text
namedQueryId = Text
a} :: GetNamedQuery)

instance Core.AWSRequest GetNamedQuery where
  type
    AWSResponse GetNamedQuery =
      GetNamedQueryResponse
  request :: (Service -> Service) -> GetNamedQuery -> Request GetNamedQuery
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 GetNamedQuery
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetNamedQuery)))
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 NamedQuery -> Int -> GetNamedQueryResponse
GetNamedQueryResponse'
            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
"NamedQuery")
            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))
      )

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

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

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

instance Data.ToJSON GetNamedQuery where
  toJSON :: GetNamedQuery -> Value
toJSON GetNamedQuery' {Text
namedQueryId :: Text
$sel:namedQueryId:GetNamedQuery' :: GetNamedQuery -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"NamedQueryId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
namedQueryId)]
      )

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

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

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

-- |
-- Create a value of 'GetNamedQueryResponse' 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:
--
-- 'namedQuery', 'getNamedQueryResponse_namedQuery' - Information about the query.
--
-- 'httpStatus', 'getNamedQueryResponse_httpStatus' - The response's http status code.
newGetNamedQueryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetNamedQueryResponse
newGetNamedQueryResponse :: Int -> GetNamedQueryResponse
newGetNamedQueryResponse Int
pHttpStatus_ =
  GetNamedQueryResponse'
    { $sel:namedQuery:GetNamedQueryResponse' :: Maybe NamedQuery
namedQuery =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetNamedQueryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the query.
getNamedQueryResponse_namedQuery :: Lens.Lens' GetNamedQueryResponse (Prelude.Maybe NamedQuery)
getNamedQueryResponse_namedQuery :: Lens' GetNamedQueryResponse (Maybe NamedQuery)
getNamedQueryResponse_namedQuery = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetNamedQueryResponse' {Maybe NamedQuery
namedQuery :: Maybe NamedQuery
$sel:namedQuery:GetNamedQueryResponse' :: GetNamedQueryResponse -> Maybe NamedQuery
namedQuery} -> Maybe NamedQuery
namedQuery) (\s :: GetNamedQueryResponse
s@GetNamedQueryResponse' {} Maybe NamedQuery
a -> GetNamedQueryResponse
s {$sel:namedQuery:GetNamedQueryResponse' :: Maybe NamedQuery
namedQuery = Maybe NamedQuery
a} :: GetNamedQueryResponse)

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

instance Prelude.NFData GetNamedQueryResponse where
  rnf :: GetNamedQueryResponse -> ()
rnf GetNamedQueryResponse' {Int
Maybe NamedQuery
httpStatus :: Int
namedQuery :: Maybe NamedQuery
$sel:httpStatus:GetNamedQueryResponse' :: GetNamedQueryResponse -> Int
$sel:namedQuery:GetNamedQueryResponse' :: GetNamedQueryResponse -> Maybe NamedQuery
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe NamedQuery
namedQuery
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus