{-# 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.TerminateSession
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Terminates an active session. A @TerminateSession@ call on a session
-- that is already inactive (for example, in a @FAILED@, @TERMINATED@ or
-- @TERMINATING@ state) succeeds but has no effect. Calculations running in
-- the session when @TerminateSession@ is called are forcefully stopped,
-- but may display as @FAILED@ instead of @STOPPED@.
module Amazonka.Athena.TerminateSession
  ( -- * Creating a Request
    TerminateSession (..),
    newTerminateSession,

    -- * Request Lenses
    terminateSession_sessionId,

    -- * Destructuring the Response
    TerminateSessionResponse (..),
    newTerminateSessionResponse,

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

-- |
-- Create a value of 'TerminateSession' 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:
--
-- 'sessionId', 'terminateSession_sessionId' - The session ID.
newTerminateSession ::
  -- | 'sessionId'
  Prelude.Text ->
  TerminateSession
newTerminateSession :: Text -> TerminateSession
newTerminateSession Text
pSessionId_ =
  TerminateSession' {$sel:sessionId:TerminateSession' :: Text
sessionId = Text
pSessionId_}

-- | The session ID.
terminateSession_sessionId :: Lens.Lens' TerminateSession Prelude.Text
terminateSession_sessionId :: Lens' TerminateSession Text
terminateSession_sessionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateSession' {Text
sessionId :: Text
$sel:sessionId:TerminateSession' :: TerminateSession -> Text
sessionId} -> Text
sessionId) (\s :: TerminateSession
s@TerminateSession' {} Text
a -> TerminateSession
s {$sel:sessionId:TerminateSession' :: Text
sessionId = Text
a} :: TerminateSession)

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

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

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

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

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

-- | /See:/ 'newTerminateSessionResponse' smart constructor.
data TerminateSessionResponse = TerminateSessionResponse'
  { -- | The state of the session. A description of each state follows.
    --
    -- @CREATING@ - The session is being started, including acquiring
    -- resources.
    --
    -- @CREATED@ - The session has been started.
    --
    -- @IDLE@ - The session is able to accept a calculation.
    --
    -- @BUSY@ - The session is processing another task and is unable to accept
    -- a calculation.
    --
    -- @TERMINATING@ - The session is in the process of shutting down.
    --
    -- @TERMINATED@ - The session and its resources are no longer running.
    --
    -- @DEGRADED@ - The session has no healthy coordinators.
    --
    -- @FAILED@ - Due to a failure, the session and its resources are no longer
    -- running.
    TerminateSessionResponse -> Maybe SessionState
state :: Prelude.Maybe SessionState,
    -- | The response's http status code.
    TerminateSessionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (TerminateSessionResponse -> TerminateSessionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
$c/= :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
== :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
$c== :: TerminateSessionResponse -> TerminateSessionResponse -> Bool
Prelude.Eq, ReadPrec [TerminateSessionResponse]
ReadPrec TerminateSessionResponse
Int -> ReadS TerminateSessionResponse
ReadS [TerminateSessionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TerminateSessionResponse]
$creadListPrec :: ReadPrec [TerminateSessionResponse]
readPrec :: ReadPrec TerminateSessionResponse
$creadPrec :: ReadPrec TerminateSessionResponse
readList :: ReadS [TerminateSessionResponse]
$creadList :: ReadS [TerminateSessionResponse]
readsPrec :: Int -> ReadS TerminateSessionResponse
$creadsPrec :: Int -> ReadS TerminateSessionResponse
Prelude.Read, Int -> TerminateSessionResponse -> ShowS
[TerminateSessionResponse] -> ShowS
TerminateSessionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TerminateSessionResponse] -> ShowS
$cshowList :: [TerminateSessionResponse] -> ShowS
show :: TerminateSessionResponse -> String
$cshow :: TerminateSessionResponse -> String
showsPrec :: Int -> TerminateSessionResponse -> ShowS
$cshowsPrec :: Int -> TerminateSessionResponse -> ShowS
Prelude.Show, forall x.
Rep TerminateSessionResponse x -> TerminateSessionResponse
forall x.
TerminateSessionResponse -> Rep TerminateSessionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TerminateSessionResponse x -> TerminateSessionResponse
$cfrom :: forall x.
TerminateSessionResponse -> Rep TerminateSessionResponse x
Prelude.Generic)

-- |
-- Create a value of 'TerminateSessionResponse' 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:
--
-- 'state', 'terminateSessionResponse_state' - The state of the session. A description of each state follows.
--
-- @CREATING@ - The session is being started, including acquiring
-- resources.
--
-- @CREATED@ - The session has been started.
--
-- @IDLE@ - The session is able to accept a calculation.
--
-- @BUSY@ - The session is processing another task and is unable to accept
-- a calculation.
--
-- @TERMINATING@ - The session is in the process of shutting down.
--
-- @TERMINATED@ - The session and its resources are no longer running.
--
-- @DEGRADED@ - The session has no healthy coordinators.
--
-- @FAILED@ - Due to a failure, the session and its resources are no longer
-- running.
--
-- 'httpStatus', 'terminateSessionResponse_httpStatus' - The response's http status code.
newTerminateSessionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TerminateSessionResponse
newTerminateSessionResponse :: Int -> TerminateSessionResponse
newTerminateSessionResponse Int
pHttpStatus_ =
  TerminateSessionResponse'
    { $sel:state:TerminateSessionResponse' :: Maybe SessionState
state = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TerminateSessionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The state of the session. A description of each state follows.
--
-- @CREATING@ - The session is being started, including acquiring
-- resources.
--
-- @CREATED@ - The session has been started.
--
-- @IDLE@ - The session is able to accept a calculation.
--
-- @BUSY@ - The session is processing another task and is unable to accept
-- a calculation.
--
-- @TERMINATING@ - The session is in the process of shutting down.
--
-- @TERMINATED@ - The session and its resources are no longer running.
--
-- @DEGRADED@ - The session has no healthy coordinators.
--
-- @FAILED@ - Due to a failure, the session and its resources are no longer
-- running.
terminateSessionResponse_state :: Lens.Lens' TerminateSessionResponse (Prelude.Maybe SessionState)
terminateSessionResponse_state :: Lens' TerminateSessionResponse (Maybe SessionState)
terminateSessionResponse_state = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateSessionResponse' {Maybe SessionState
state :: Maybe SessionState
$sel:state:TerminateSessionResponse' :: TerminateSessionResponse -> Maybe SessionState
state} -> Maybe SessionState
state) (\s :: TerminateSessionResponse
s@TerminateSessionResponse' {} Maybe SessionState
a -> TerminateSessionResponse
s {$sel:state:TerminateSessionResponse' :: Maybe SessionState
state = Maybe SessionState
a} :: TerminateSessionResponse)

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

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