{-# 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.GetCalculationExecutionCode
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves a pre-signed URL to a copy of the code that was executed for
-- the calculation.
module Amazonka.Athena.GetCalculationExecutionCode
  ( -- * Creating a Request
    GetCalculationExecutionCode (..),
    newGetCalculationExecutionCode,

    -- * Request Lenses
    getCalculationExecutionCode_calculationExecutionId,

    -- * Destructuring the Response
    GetCalculationExecutionCodeResponse (..),
    newGetCalculationExecutionCodeResponse,

    -- * Response Lenses
    getCalculationExecutionCodeResponse_codeBlock,
    getCalculationExecutionCodeResponse_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:/ 'newGetCalculationExecutionCode' smart constructor.
data GetCalculationExecutionCode = GetCalculationExecutionCode'
  { -- | The calculation execution UUID.
    GetCalculationExecutionCode -> Text
calculationExecutionId :: Prelude.Text
  }
  deriving (GetCalculationExecutionCode -> GetCalculationExecutionCode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCalculationExecutionCode -> GetCalculationExecutionCode -> Bool
$c/= :: GetCalculationExecutionCode -> GetCalculationExecutionCode -> Bool
== :: GetCalculationExecutionCode -> GetCalculationExecutionCode -> Bool
$c== :: GetCalculationExecutionCode -> GetCalculationExecutionCode -> Bool
Prelude.Eq, ReadPrec [GetCalculationExecutionCode]
ReadPrec GetCalculationExecutionCode
Int -> ReadS GetCalculationExecutionCode
ReadS [GetCalculationExecutionCode]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCalculationExecutionCode]
$creadListPrec :: ReadPrec [GetCalculationExecutionCode]
readPrec :: ReadPrec GetCalculationExecutionCode
$creadPrec :: ReadPrec GetCalculationExecutionCode
readList :: ReadS [GetCalculationExecutionCode]
$creadList :: ReadS [GetCalculationExecutionCode]
readsPrec :: Int -> ReadS GetCalculationExecutionCode
$creadsPrec :: Int -> ReadS GetCalculationExecutionCode
Prelude.Read, Int -> GetCalculationExecutionCode -> ShowS
[GetCalculationExecutionCode] -> ShowS
GetCalculationExecutionCode -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCalculationExecutionCode] -> ShowS
$cshowList :: [GetCalculationExecutionCode] -> ShowS
show :: GetCalculationExecutionCode -> String
$cshow :: GetCalculationExecutionCode -> String
showsPrec :: Int -> GetCalculationExecutionCode -> ShowS
$cshowsPrec :: Int -> GetCalculationExecutionCode -> ShowS
Prelude.Show, forall x.
Rep GetCalculationExecutionCode x -> GetCalculationExecutionCode
forall x.
GetCalculationExecutionCode -> Rep GetCalculationExecutionCode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetCalculationExecutionCode x -> GetCalculationExecutionCode
$cfrom :: forall x.
GetCalculationExecutionCode -> Rep GetCalculationExecutionCode x
Prelude.Generic)

-- |
-- Create a value of 'GetCalculationExecutionCode' 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:
--
-- 'calculationExecutionId', 'getCalculationExecutionCode_calculationExecutionId' - The calculation execution UUID.
newGetCalculationExecutionCode ::
  -- | 'calculationExecutionId'
  Prelude.Text ->
  GetCalculationExecutionCode
newGetCalculationExecutionCode :: Text -> GetCalculationExecutionCode
newGetCalculationExecutionCode
  Text
pCalculationExecutionId_ =
    GetCalculationExecutionCode'
      { $sel:calculationExecutionId:GetCalculationExecutionCode' :: Text
calculationExecutionId =
          Text
pCalculationExecutionId_
      }

-- | The calculation execution UUID.
getCalculationExecutionCode_calculationExecutionId :: Lens.Lens' GetCalculationExecutionCode Prelude.Text
getCalculationExecutionCode_calculationExecutionId :: Lens' GetCalculationExecutionCode Text
getCalculationExecutionCode_calculationExecutionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCalculationExecutionCode' {Text
calculationExecutionId :: Text
$sel:calculationExecutionId:GetCalculationExecutionCode' :: GetCalculationExecutionCode -> Text
calculationExecutionId} -> Text
calculationExecutionId) (\s :: GetCalculationExecutionCode
s@GetCalculationExecutionCode' {} Text
a -> GetCalculationExecutionCode
s {$sel:calculationExecutionId:GetCalculationExecutionCode' :: Text
calculationExecutionId = Text
a} :: GetCalculationExecutionCode)

instance Core.AWSRequest GetCalculationExecutionCode where
  type
    AWSResponse GetCalculationExecutionCode =
      GetCalculationExecutionCodeResponse
  request :: (Service -> Service)
-> GetCalculationExecutionCode
-> Request GetCalculationExecutionCode
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 GetCalculationExecutionCode
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCalculationExecutionCode)))
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 -> GetCalculationExecutionCodeResponse
GetCalculationExecutionCodeResponse'
            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
"CodeBlock")
            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 GetCalculationExecutionCode where
  hashWithSalt :: Int -> GetCalculationExecutionCode -> Int
hashWithSalt Int
_salt GetCalculationExecutionCode' {Text
calculationExecutionId :: Text
$sel:calculationExecutionId:GetCalculationExecutionCode' :: GetCalculationExecutionCode -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
calculationExecutionId

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

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

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

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

-- | /See:/ 'newGetCalculationExecutionCodeResponse' smart constructor.
data GetCalculationExecutionCodeResponse = GetCalculationExecutionCodeResponse'
  { -- | A pre-signed URL to the code that executed the calculation.
    GetCalculationExecutionCodeResponse -> Maybe Text
codeBlock :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetCalculationExecutionCodeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCalculationExecutionCodeResponse
-> GetCalculationExecutionCodeResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCalculationExecutionCodeResponse
-> GetCalculationExecutionCodeResponse -> Bool
$c/= :: GetCalculationExecutionCodeResponse
-> GetCalculationExecutionCodeResponse -> Bool
== :: GetCalculationExecutionCodeResponse
-> GetCalculationExecutionCodeResponse -> Bool
$c== :: GetCalculationExecutionCodeResponse
-> GetCalculationExecutionCodeResponse -> Bool
Prelude.Eq, ReadPrec [GetCalculationExecutionCodeResponse]
ReadPrec GetCalculationExecutionCodeResponse
Int -> ReadS GetCalculationExecutionCodeResponse
ReadS [GetCalculationExecutionCodeResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCalculationExecutionCodeResponse]
$creadListPrec :: ReadPrec [GetCalculationExecutionCodeResponse]
readPrec :: ReadPrec GetCalculationExecutionCodeResponse
$creadPrec :: ReadPrec GetCalculationExecutionCodeResponse
readList :: ReadS [GetCalculationExecutionCodeResponse]
$creadList :: ReadS [GetCalculationExecutionCodeResponse]
readsPrec :: Int -> ReadS GetCalculationExecutionCodeResponse
$creadsPrec :: Int -> ReadS GetCalculationExecutionCodeResponse
Prelude.Read, Int -> GetCalculationExecutionCodeResponse -> ShowS
[GetCalculationExecutionCodeResponse] -> ShowS
GetCalculationExecutionCodeResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCalculationExecutionCodeResponse] -> ShowS
$cshowList :: [GetCalculationExecutionCodeResponse] -> ShowS
show :: GetCalculationExecutionCodeResponse -> String
$cshow :: GetCalculationExecutionCodeResponse -> String
showsPrec :: Int -> GetCalculationExecutionCodeResponse -> ShowS
$cshowsPrec :: Int -> GetCalculationExecutionCodeResponse -> ShowS
Prelude.Show, forall x.
Rep GetCalculationExecutionCodeResponse x
-> GetCalculationExecutionCodeResponse
forall x.
GetCalculationExecutionCodeResponse
-> Rep GetCalculationExecutionCodeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetCalculationExecutionCodeResponse x
-> GetCalculationExecutionCodeResponse
$cfrom :: forall x.
GetCalculationExecutionCodeResponse
-> Rep GetCalculationExecutionCodeResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCalculationExecutionCodeResponse' 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:
--
-- 'codeBlock', 'getCalculationExecutionCodeResponse_codeBlock' - A pre-signed URL to the code that executed the calculation.
--
-- 'httpStatus', 'getCalculationExecutionCodeResponse_httpStatus' - The response's http status code.
newGetCalculationExecutionCodeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCalculationExecutionCodeResponse
newGetCalculationExecutionCodeResponse :: Int -> GetCalculationExecutionCodeResponse
newGetCalculationExecutionCodeResponse Int
pHttpStatus_ =
  GetCalculationExecutionCodeResponse'
    { $sel:codeBlock:GetCalculationExecutionCodeResponse' :: Maybe Text
codeBlock =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCalculationExecutionCodeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A pre-signed URL to the code that executed the calculation.
getCalculationExecutionCodeResponse_codeBlock :: Lens.Lens' GetCalculationExecutionCodeResponse (Prelude.Maybe Prelude.Text)
getCalculationExecutionCodeResponse_codeBlock :: Lens' GetCalculationExecutionCodeResponse (Maybe Text)
getCalculationExecutionCodeResponse_codeBlock = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCalculationExecutionCodeResponse' {Maybe Text
codeBlock :: Maybe Text
$sel:codeBlock:GetCalculationExecutionCodeResponse' :: GetCalculationExecutionCodeResponse -> Maybe Text
codeBlock} -> Maybe Text
codeBlock) (\s :: GetCalculationExecutionCodeResponse
s@GetCalculationExecutionCodeResponse' {} Maybe Text
a -> GetCalculationExecutionCodeResponse
s {$sel:codeBlock:GetCalculationExecutionCodeResponse' :: Maybe Text
codeBlock = Maybe Text
a} :: GetCalculationExecutionCodeResponse)

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

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