{-# 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.SnowDeviceManagement.CancelTask
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Sends a cancel request for a specified task. You can cancel a task only
-- if it\'s still in a @QUEUED@ state. Tasks that are already running
-- can\'t be cancelled.
--
-- A task might still run if it\'s processed from the queue before the
-- @CancelTask@ operation changes the task\'s state.
module Amazonka.SnowDeviceManagement.CancelTask
  ( -- * Creating a Request
    CancelTask (..),
    newCancelTask,

    -- * Request Lenses
    cancelTask_taskId,

    -- * Destructuring the Response
    CancelTaskResponse (..),
    newCancelTaskResponse,

    -- * Response Lenses
    cancelTaskResponse_taskId,
    cancelTaskResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SnowDeviceManagement.Types

-- | /See:/ 'newCancelTask' smart constructor.
data CancelTask = CancelTask'
  { -- | The ID of the task that you are attempting to cancel. You can retrieve a
    -- task ID by using the @ListTasks@ operation.
    CancelTask -> Text
taskId :: Prelude.Text
  }
  deriving (CancelTask -> CancelTask -> Bool
(CancelTask -> CancelTask -> Bool)
-> (CancelTask -> CancelTask -> Bool) -> Eq CancelTask
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelTask -> CancelTask -> Bool
$c/= :: CancelTask -> CancelTask -> Bool
== :: CancelTask -> CancelTask -> Bool
$c== :: CancelTask -> CancelTask -> Bool
Prelude.Eq, ReadPrec [CancelTask]
ReadPrec CancelTask
Int -> ReadS CancelTask
ReadS [CancelTask]
(Int -> ReadS CancelTask)
-> ReadS [CancelTask]
-> ReadPrec CancelTask
-> ReadPrec [CancelTask]
-> Read CancelTask
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelTask]
$creadListPrec :: ReadPrec [CancelTask]
readPrec :: ReadPrec CancelTask
$creadPrec :: ReadPrec CancelTask
readList :: ReadS [CancelTask]
$creadList :: ReadS [CancelTask]
readsPrec :: Int -> ReadS CancelTask
$creadsPrec :: Int -> ReadS CancelTask
Prelude.Read, Int -> CancelTask -> ShowS
[CancelTask] -> ShowS
CancelTask -> String
(Int -> CancelTask -> ShowS)
-> (CancelTask -> String)
-> ([CancelTask] -> ShowS)
-> Show CancelTask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelTask] -> ShowS
$cshowList :: [CancelTask] -> ShowS
show :: CancelTask -> String
$cshow :: CancelTask -> String
showsPrec :: Int -> CancelTask -> ShowS
$cshowsPrec :: Int -> CancelTask -> ShowS
Prelude.Show, (forall x. CancelTask -> Rep CancelTask x)
-> (forall x. Rep CancelTask x -> CancelTask) -> Generic CancelTask
forall x. Rep CancelTask x -> CancelTask
forall x. CancelTask -> Rep CancelTask x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelTask x -> CancelTask
$cfrom :: forall x. CancelTask -> Rep CancelTask x
Prelude.Generic)

-- |
-- Create a value of 'CancelTask' 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:
--
-- 'taskId', 'cancelTask_taskId' - The ID of the task that you are attempting to cancel. You can retrieve a
-- task ID by using the @ListTasks@ operation.
newCancelTask ::
  -- | 'taskId'
  Prelude.Text ->
  CancelTask
newCancelTask :: Text -> CancelTask
newCancelTask Text
pTaskId_ =
  CancelTask' :: Text -> CancelTask
CancelTask' {$sel:taskId:CancelTask' :: Text
taskId = Text
pTaskId_}

-- | The ID of the task that you are attempting to cancel. You can retrieve a
-- task ID by using the @ListTasks@ operation.
cancelTask_taskId :: Lens.Lens' CancelTask Prelude.Text
cancelTask_taskId :: (Text -> f Text) -> CancelTask -> f CancelTask
cancelTask_taskId = (CancelTask -> Text)
-> (CancelTask -> Text -> CancelTask)
-> Lens CancelTask CancelTask Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelTask' {Text
taskId :: Text
$sel:taskId:CancelTask' :: CancelTask -> Text
taskId} -> Text
taskId) (\s :: CancelTask
s@CancelTask' {} Text
a -> CancelTask
s {$sel:taskId:CancelTask' :: Text
taskId = Text
a} :: CancelTask)

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

instance Prelude.Hashable CancelTask

instance Prelude.NFData CancelTask

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

instance Core.ToJSON CancelTask where
  toJSON :: CancelTask -> Value
toJSON = Value -> CancelTask -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath CancelTask where
  toPath :: CancelTask -> ByteString
toPath CancelTask' {Text
taskId :: Text
$sel:taskId:CancelTask' :: CancelTask -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/task/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
taskId, ByteString
"/cancel"]

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

-- | /See:/ 'newCancelTaskResponse' smart constructor.
data CancelTaskResponse = CancelTaskResponse'
  { -- | The ID of the task that you are attempting to cancel.
    CancelTaskResponse -> Maybe Text
taskId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CancelTaskResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelTaskResponse -> CancelTaskResponse -> Bool
(CancelTaskResponse -> CancelTaskResponse -> Bool)
-> (CancelTaskResponse -> CancelTaskResponse -> Bool)
-> Eq CancelTaskResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelTaskResponse -> CancelTaskResponse -> Bool
$c/= :: CancelTaskResponse -> CancelTaskResponse -> Bool
== :: CancelTaskResponse -> CancelTaskResponse -> Bool
$c== :: CancelTaskResponse -> CancelTaskResponse -> Bool
Prelude.Eq, ReadPrec [CancelTaskResponse]
ReadPrec CancelTaskResponse
Int -> ReadS CancelTaskResponse
ReadS [CancelTaskResponse]
(Int -> ReadS CancelTaskResponse)
-> ReadS [CancelTaskResponse]
-> ReadPrec CancelTaskResponse
-> ReadPrec [CancelTaskResponse]
-> Read CancelTaskResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelTaskResponse]
$creadListPrec :: ReadPrec [CancelTaskResponse]
readPrec :: ReadPrec CancelTaskResponse
$creadPrec :: ReadPrec CancelTaskResponse
readList :: ReadS [CancelTaskResponse]
$creadList :: ReadS [CancelTaskResponse]
readsPrec :: Int -> ReadS CancelTaskResponse
$creadsPrec :: Int -> ReadS CancelTaskResponse
Prelude.Read, Int -> CancelTaskResponse -> ShowS
[CancelTaskResponse] -> ShowS
CancelTaskResponse -> String
(Int -> CancelTaskResponse -> ShowS)
-> (CancelTaskResponse -> String)
-> ([CancelTaskResponse] -> ShowS)
-> Show CancelTaskResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelTaskResponse] -> ShowS
$cshowList :: [CancelTaskResponse] -> ShowS
show :: CancelTaskResponse -> String
$cshow :: CancelTaskResponse -> String
showsPrec :: Int -> CancelTaskResponse -> ShowS
$cshowsPrec :: Int -> CancelTaskResponse -> ShowS
Prelude.Show, (forall x. CancelTaskResponse -> Rep CancelTaskResponse x)
-> (forall x. Rep CancelTaskResponse x -> CancelTaskResponse)
-> Generic CancelTaskResponse
forall x. Rep CancelTaskResponse x -> CancelTaskResponse
forall x. CancelTaskResponse -> Rep CancelTaskResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelTaskResponse x -> CancelTaskResponse
$cfrom :: forall x. CancelTaskResponse -> Rep CancelTaskResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelTaskResponse' 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:
--
-- 'taskId', 'cancelTaskResponse_taskId' - The ID of the task that you are attempting to cancel.
--
-- 'httpStatus', 'cancelTaskResponse_httpStatus' - The response's http status code.
newCancelTaskResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelTaskResponse
newCancelTaskResponse :: Int -> CancelTaskResponse
newCancelTaskResponse Int
pHttpStatus_ =
  CancelTaskResponse' :: Maybe Text -> Int -> CancelTaskResponse
CancelTaskResponse'
    { $sel:taskId:CancelTaskResponse' :: Maybe Text
taskId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelTaskResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID of the task that you are attempting to cancel.
cancelTaskResponse_taskId :: Lens.Lens' CancelTaskResponse (Prelude.Maybe Prelude.Text)
cancelTaskResponse_taskId :: (Maybe Text -> f (Maybe Text))
-> CancelTaskResponse -> f CancelTaskResponse
cancelTaskResponse_taskId = (CancelTaskResponse -> Maybe Text)
-> (CancelTaskResponse -> Maybe Text -> CancelTaskResponse)
-> Lens
     CancelTaskResponse CancelTaskResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelTaskResponse' {Maybe Text
taskId :: Maybe Text
$sel:taskId:CancelTaskResponse' :: CancelTaskResponse -> Maybe Text
taskId} -> Maybe Text
taskId) (\s :: CancelTaskResponse
s@CancelTaskResponse' {} Maybe Text
a -> CancelTaskResponse
s {$sel:taskId:CancelTaskResponse' :: Maybe Text
taskId = Maybe Text
a} :: CancelTaskResponse)

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

instance Prelude.NFData CancelTaskResponse