{-# 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.Comprehend.StopEntitiesDetectionJob
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stops an entities detection job in progress.
--
-- If the job state is @IN_PROGRESS@ the job is marked for termination and
-- put into the @STOP_REQUESTED@ state. If the job completes before it can
-- be stopped, it is put into the @COMPLETED@ state; otherwise the job is
-- stopped and put into the @STOPPED@ state.
--
-- If the job is in the @COMPLETED@ or @FAILED@ state when you call the
-- @StopDominantLanguageDetectionJob@ operation, the operation returns a
-- 400 Internal Request Exception.
--
-- When a job is stopped, any documents already processed are written to
-- the output location.
module Amazonka.Comprehend.StopEntitiesDetectionJob
  ( -- * Creating a Request
    StopEntitiesDetectionJob (..),
    newStopEntitiesDetectionJob,

    -- * Request Lenses
    stopEntitiesDetectionJob_jobId,

    -- * Destructuring the Response
    StopEntitiesDetectionJobResponse (..),
    newStopEntitiesDetectionJobResponse,

    -- * Response Lenses
    stopEntitiesDetectionJobResponse_jobId,
    stopEntitiesDetectionJobResponse_jobStatus,
    stopEntitiesDetectionJobResponse_httpStatus,
  )
where

import Amazonka.Comprehend.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:/ 'newStopEntitiesDetectionJob' smart constructor.
data StopEntitiesDetectionJob = StopEntitiesDetectionJob'
  { -- | The identifier of the entities detection job to stop.
    StopEntitiesDetectionJob -> Text
jobId :: Prelude.Text
  }
  deriving (StopEntitiesDetectionJob -> StopEntitiesDetectionJob -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopEntitiesDetectionJob -> StopEntitiesDetectionJob -> Bool
$c/= :: StopEntitiesDetectionJob -> StopEntitiesDetectionJob -> Bool
== :: StopEntitiesDetectionJob -> StopEntitiesDetectionJob -> Bool
$c== :: StopEntitiesDetectionJob -> StopEntitiesDetectionJob -> Bool
Prelude.Eq, ReadPrec [StopEntitiesDetectionJob]
ReadPrec StopEntitiesDetectionJob
Int -> ReadS StopEntitiesDetectionJob
ReadS [StopEntitiesDetectionJob]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopEntitiesDetectionJob]
$creadListPrec :: ReadPrec [StopEntitiesDetectionJob]
readPrec :: ReadPrec StopEntitiesDetectionJob
$creadPrec :: ReadPrec StopEntitiesDetectionJob
readList :: ReadS [StopEntitiesDetectionJob]
$creadList :: ReadS [StopEntitiesDetectionJob]
readsPrec :: Int -> ReadS StopEntitiesDetectionJob
$creadsPrec :: Int -> ReadS StopEntitiesDetectionJob
Prelude.Read, Int -> StopEntitiesDetectionJob -> ShowS
[StopEntitiesDetectionJob] -> ShowS
StopEntitiesDetectionJob -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopEntitiesDetectionJob] -> ShowS
$cshowList :: [StopEntitiesDetectionJob] -> ShowS
show :: StopEntitiesDetectionJob -> String
$cshow :: StopEntitiesDetectionJob -> String
showsPrec :: Int -> StopEntitiesDetectionJob -> ShowS
$cshowsPrec :: Int -> StopEntitiesDetectionJob -> ShowS
Prelude.Show, forall x.
Rep StopEntitiesDetectionJob x -> StopEntitiesDetectionJob
forall x.
StopEntitiesDetectionJob -> Rep StopEntitiesDetectionJob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StopEntitiesDetectionJob x -> StopEntitiesDetectionJob
$cfrom :: forall x.
StopEntitiesDetectionJob -> Rep StopEntitiesDetectionJob x
Prelude.Generic)

-- |
-- Create a value of 'StopEntitiesDetectionJob' 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:
--
-- 'jobId', 'stopEntitiesDetectionJob_jobId' - The identifier of the entities detection job to stop.
newStopEntitiesDetectionJob ::
  -- | 'jobId'
  Prelude.Text ->
  StopEntitiesDetectionJob
newStopEntitiesDetectionJob :: Text -> StopEntitiesDetectionJob
newStopEntitiesDetectionJob Text
pJobId_ =
  StopEntitiesDetectionJob' {$sel:jobId:StopEntitiesDetectionJob' :: Text
jobId = Text
pJobId_}

-- | The identifier of the entities detection job to stop.
stopEntitiesDetectionJob_jobId :: Lens.Lens' StopEntitiesDetectionJob Prelude.Text
stopEntitiesDetectionJob_jobId :: Lens' StopEntitiesDetectionJob Text
stopEntitiesDetectionJob_jobId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopEntitiesDetectionJob' {Text
jobId :: Text
$sel:jobId:StopEntitiesDetectionJob' :: StopEntitiesDetectionJob -> Text
jobId} -> Text
jobId) (\s :: StopEntitiesDetectionJob
s@StopEntitiesDetectionJob' {} Text
a -> StopEntitiesDetectionJob
s {$sel:jobId:StopEntitiesDetectionJob' :: Text
jobId = Text
a} :: StopEntitiesDetectionJob)

instance Core.AWSRequest StopEntitiesDetectionJob where
  type
    AWSResponse StopEntitiesDetectionJob =
      StopEntitiesDetectionJobResponse
  request :: (Service -> Service)
-> StopEntitiesDetectionJob -> Request StopEntitiesDetectionJob
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 StopEntitiesDetectionJob
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StopEntitiesDetectionJob)))
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
-> Maybe JobStatus -> Int -> StopEntitiesDetectionJobResponse
StopEntitiesDetectionJobResponse'
            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
"JobId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"JobStatus")
            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 StopEntitiesDetectionJob where
  hashWithSalt :: Int -> StopEntitiesDetectionJob -> Int
hashWithSalt Int
_salt StopEntitiesDetectionJob' {Text
jobId :: Text
$sel:jobId:StopEntitiesDetectionJob' :: StopEntitiesDetectionJob -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
jobId

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

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

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

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

-- | /See:/ 'newStopEntitiesDetectionJobResponse' smart constructor.
data StopEntitiesDetectionJobResponse = StopEntitiesDetectionJobResponse'
  { -- | The identifier of the entities detection job to stop.
    StopEntitiesDetectionJobResponse -> Maybe Text
jobId :: Prelude.Maybe Prelude.Text,
    -- | Either @STOP_REQUESTED@ if the job is currently running, or @STOPPED@ if
    -- the job was previously stopped with the @StopEntitiesDetectionJob@
    -- operation.
    StopEntitiesDetectionJobResponse -> Maybe JobStatus
jobStatus :: Prelude.Maybe JobStatus,
    -- | The response's http status code.
    StopEntitiesDetectionJobResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopEntitiesDetectionJobResponse
-> StopEntitiesDetectionJobResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopEntitiesDetectionJobResponse
-> StopEntitiesDetectionJobResponse -> Bool
$c/= :: StopEntitiesDetectionJobResponse
-> StopEntitiesDetectionJobResponse -> Bool
== :: StopEntitiesDetectionJobResponse
-> StopEntitiesDetectionJobResponse -> Bool
$c== :: StopEntitiesDetectionJobResponse
-> StopEntitiesDetectionJobResponse -> Bool
Prelude.Eq, ReadPrec [StopEntitiesDetectionJobResponse]
ReadPrec StopEntitiesDetectionJobResponse
Int -> ReadS StopEntitiesDetectionJobResponse
ReadS [StopEntitiesDetectionJobResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopEntitiesDetectionJobResponse]
$creadListPrec :: ReadPrec [StopEntitiesDetectionJobResponse]
readPrec :: ReadPrec StopEntitiesDetectionJobResponse
$creadPrec :: ReadPrec StopEntitiesDetectionJobResponse
readList :: ReadS [StopEntitiesDetectionJobResponse]
$creadList :: ReadS [StopEntitiesDetectionJobResponse]
readsPrec :: Int -> ReadS StopEntitiesDetectionJobResponse
$creadsPrec :: Int -> ReadS StopEntitiesDetectionJobResponse
Prelude.Read, Int -> StopEntitiesDetectionJobResponse -> ShowS
[StopEntitiesDetectionJobResponse] -> ShowS
StopEntitiesDetectionJobResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopEntitiesDetectionJobResponse] -> ShowS
$cshowList :: [StopEntitiesDetectionJobResponse] -> ShowS
show :: StopEntitiesDetectionJobResponse -> String
$cshow :: StopEntitiesDetectionJobResponse -> String
showsPrec :: Int -> StopEntitiesDetectionJobResponse -> ShowS
$cshowsPrec :: Int -> StopEntitiesDetectionJobResponse -> ShowS
Prelude.Show, forall x.
Rep StopEntitiesDetectionJobResponse x
-> StopEntitiesDetectionJobResponse
forall x.
StopEntitiesDetectionJobResponse
-> Rep StopEntitiesDetectionJobResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StopEntitiesDetectionJobResponse x
-> StopEntitiesDetectionJobResponse
$cfrom :: forall x.
StopEntitiesDetectionJobResponse
-> Rep StopEntitiesDetectionJobResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopEntitiesDetectionJobResponse' 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:
--
-- 'jobId', 'stopEntitiesDetectionJobResponse_jobId' - The identifier of the entities detection job to stop.
--
-- 'jobStatus', 'stopEntitiesDetectionJobResponse_jobStatus' - Either @STOP_REQUESTED@ if the job is currently running, or @STOPPED@ if
-- the job was previously stopped with the @StopEntitiesDetectionJob@
-- operation.
--
-- 'httpStatus', 'stopEntitiesDetectionJobResponse_httpStatus' - The response's http status code.
newStopEntitiesDetectionJobResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopEntitiesDetectionJobResponse
newStopEntitiesDetectionJobResponse :: Int -> StopEntitiesDetectionJobResponse
newStopEntitiesDetectionJobResponse Int
pHttpStatus_ =
  StopEntitiesDetectionJobResponse'
    { $sel:jobId:StopEntitiesDetectionJobResponse' :: Maybe Text
jobId =
        forall a. Maybe a
Prelude.Nothing,
      $sel:jobStatus:StopEntitiesDetectionJobResponse' :: Maybe JobStatus
jobStatus = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopEntitiesDetectionJobResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier of the entities detection job to stop.
stopEntitiesDetectionJobResponse_jobId :: Lens.Lens' StopEntitiesDetectionJobResponse (Prelude.Maybe Prelude.Text)
stopEntitiesDetectionJobResponse_jobId :: Lens' StopEntitiesDetectionJobResponse (Maybe Text)
stopEntitiesDetectionJobResponse_jobId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopEntitiesDetectionJobResponse' {Maybe Text
jobId :: Maybe Text
$sel:jobId:StopEntitiesDetectionJobResponse' :: StopEntitiesDetectionJobResponse -> Maybe Text
jobId} -> Maybe Text
jobId) (\s :: StopEntitiesDetectionJobResponse
s@StopEntitiesDetectionJobResponse' {} Maybe Text
a -> StopEntitiesDetectionJobResponse
s {$sel:jobId:StopEntitiesDetectionJobResponse' :: Maybe Text
jobId = Maybe Text
a} :: StopEntitiesDetectionJobResponse)

-- | Either @STOP_REQUESTED@ if the job is currently running, or @STOPPED@ if
-- the job was previously stopped with the @StopEntitiesDetectionJob@
-- operation.
stopEntitiesDetectionJobResponse_jobStatus :: Lens.Lens' StopEntitiesDetectionJobResponse (Prelude.Maybe JobStatus)
stopEntitiesDetectionJobResponse_jobStatus :: Lens' StopEntitiesDetectionJobResponse (Maybe JobStatus)
stopEntitiesDetectionJobResponse_jobStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopEntitiesDetectionJobResponse' {Maybe JobStatus
jobStatus :: Maybe JobStatus
$sel:jobStatus:StopEntitiesDetectionJobResponse' :: StopEntitiesDetectionJobResponse -> Maybe JobStatus
jobStatus} -> Maybe JobStatus
jobStatus) (\s :: StopEntitiesDetectionJobResponse
s@StopEntitiesDetectionJobResponse' {} Maybe JobStatus
a -> StopEntitiesDetectionJobResponse
s {$sel:jobStatus:StopEntitiesDetectionJobResponse' :: Maybe JobStatus
jobStatus = Maybe JobStatus
a} :: StopEntitiesDetectionJobResponse)

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

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