{-# 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.MechanicalTurk.CreateWorkerBlock
-- 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)
--
-- The @CreateWorkerBlock@ operation allows you to prevent a Worker from
-- working on your HITs. For example, you can block a Worker who is
-- producing poor quality work. You can block up to 100,000 Workers.
module Amazonka.MechanicalTurk.CreateWorkerBlock
  ( -- * Creating a Request
    CreateWorkerBlock (..),
    newCreateWorkerBlock,

    -- * Request Lenses
    createWorkerBlock_workerId,
    createWorkerBlock_reason,

    -- * Destructuring the Response
    CreateWorkerBlockResponse (..),
    newCreateWorkerBlockResponse,

    -- * Response Lenses
    createWorkerBlockResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateWorkerBlock' smart constructor.
data CreateWorkerBlock = CreateWorkerBlock'
  { -- | The ID of the Worker to block.
    CreateWorkerBlock -> Text
workerId :: Prelude.Text,
    -- | A message explaining the reason for blocking the Worker. This parameter
    -- enables you to keep track of your Workers. The Worker does not see this
    -- message.
    CreateWorkerBlock -> Text
reason :: Prelude.Text
  }
  deriving (CreateWorkerBlock -> CreateWorkerBlock -> Bool
(CreateWorkerBlock -> CreateWorkerBlock -> Bool)
-> (CreateWorkerBlock -> CreateWorkerBlock -> Bool)
-> Eq CreateWorkerBlock
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateWorkerBlock -> CreateWorkerBlock -> Bool
$c/= :: CreateWorkerBlock -> CreateWorkerBlock -> Bool
== :: CreateWorkerBlock -> CreateWorkerBlock -> Bool
$c== :: CreateWorkerBlock -> CreateWorkerBlock -> Bool
Prelude.Eq, ReadPrec [CreateWorkerBlock]
ReadPrec CreateWorkerBlock
Int -> ReadS CreateWorkerBlock
ReadS [CreateWorkerBlock]
(Int -> ReadS CreateWorkerBlock)
-> ReadS [CreateWorkerBlock]
-> ReadPrec CreateWorkerBlock
-> ReadPrec [CreateWorkerBlock]
-> Read CreateWorkerBlock
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateWorkerBlock]
$creadListPrec :: ReadPrec [CreateWorkerBlock]
readPrec :: ReadPrec CreateWorkerBlock
$creadPrec :: ReadPrec CreateWorkerBlock
readList :: ReadS [CreateWorkerBlock]
$creadList :: ReadS [CreateWorkerBlock]
readsPrec :: Int -> ReadS CreateWorkerBlock
$creadsPrec :: Int -> ReadS CreateWorkerBlock
Prelude.Read, Int -> CreateWorkerBlock -> ShowS
[CreateWorkerBlock] -> ShowS
CreateWorkerBlock -> String
(Int -> CreateWorkerBlock -> ShowS)
-> (CreateWorkerBlock -> String)
-> ([CreateWorkerBlock] -> ShowS)
-> Show CreateWorkerBlock
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateWorkerBlock] -> ShowS
$cshowList :: [CreateWorkerBlock] -> ShowS
show :: CreateWorkerBlock -> String
$cshow :: CreateWorkerBlock -> String
showsPrec :: Int -> CreateWorkerBlock -> ShowS
$cshowsPrec :: Int -> CreateWorkerBlock -> ShowS
Prelude.Show, (forall x. CreateWorkerBlock -> Rep CreateWorkerBlock x)
-> (forall x. Rep CreateWorkerBlock x -> CreateWorkerBlock)
-> Generic CreateWorkerBlock
forall x. Rep CreateWorkerBlock x -> CreateWorkerBlock
forall x. CreateWorkerBlock -> Rep CreateWorkerBlock x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateWorkerBlock x -> CreateWorkerBlock
$cfrom :: forall x. CreateWorkerBlock -> Rep CreateWorkerBlock x
Prelude.Generic)

-- |
-- Create a value of 'CreateWorkerBlock' 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:
--
-- 'workerId', 'createWorkerBlock_workerId' - The ID of the Worker to block.
--
-- 'reason', 'createWorkerBlock_reason' - A message explaining the reason for blocking the Worker. This parameter
-- enables you to keep track of your Workers. The Worker does not see this
-- message.
newCreateWorkerBlock ::
  -- | 'workerId'
  Prelude.Text ->
  -- | 'reason'
  Prelude.Text ->
  CreateWorkerBlock
newCreateWorkerBlock :: Text -> Text -> CreateWorkerBlock
newCreateWorkerBlock Text
pWorkerId_ Text
pReason_ =
  CreateWorkerBlock' :: Text -> Text -> CreateWorkerBlock
CreateWorkerBlock'
    { $sel:workerId:CreateWorkerBlock' :: Text
workerId = Text
pWorkerId_,
      $sel:reason:CreateWorkerBlock' :: Text
reason = Text
pReason_
    }

-- | The ID of the Worker to block.
createWorkerBlock_workerId :: Lens.Lens' CreateWorkerBlock Prelude.Text
createWorkerBlock_workerId :: (Text -> f Text) -> CreateWorkerBlock -> f CreateWorkerBlock
createWorkerBlock_workerId = (CreateWorkerBlock -> Text)
-> (CreateWorkerBlock -> Text -> CreateWorkerBlock)
-> Lens CreateWorkerBlock CreateWorkerBlock Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateWorkerBlock' {Text
workerId :: Text
$sel:workerId:CreateWorkerBlock' :: CreateWorkerBlock -> Text
workerId} -> Text
workerId) (\s :: CreateWorkerBlock
s@CreateWorkerBlock' {} Text
a -> CreateWorkerBlock
s {$sel:workerId:CreateWorkerBlock' :: Text
workerId = Text
a} :: CreateWorkerBlock)

-- | A message explaining the reason for blocking the Worker. This parameter
-- enables you to keep track of your Workers. The Worker does not see this
-- message.
createWorkerBlock_reason :: Lens.Lens' CreateWorkerBlock Prelude.Text
createWorkerBlock_reason :: (Text -> f Text) -> CreateWorkerBlock -> f CreateWorkerBlock
createWorkerBlock_reason = (CreateWorkerBlock -> Text)
-> (CreateWorkerBlock -> Text -> CreateWorkerBlock)
-> Lens CreateWorkerBlock CreateWorkerBlock Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateWorkerBlock' {Text
reason :: Text
$sel:reason:CreateWorkerBlock' :: CreateWorkerBlock -> Text
reason} -> Text
reason) (\s :: CreateWorkerBlock
s@CreateWorkerBlock' {} Text
a -> CreateWorkerBlock
s {$sel:reason:CreateWorkerBlock' :: Text
reason = Text
a} :: CreateWorkerBlock)

instance Core.AWSRequest CreateWorkerBlock where
  type
    AWSResponse CreateWorkerBlock =
      CreateWorkerBlockResponse
  request :: CreateWorkerBlock -> Request CreateWorkerBlock
request = Service -> CreateWorkerBlock -> Request CreateWorkerBlock
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateWorkerBlock
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateWorkerBlock)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateWorkerBlock))
-> Logger
-> Service
-> Proxy CreateWorkerBlock
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateWorkerBlock)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreateWorkerBlockResponse
CreateWorkerBlockResponse'
            (Int -> CreateWorkerBlockResponse)
-> Either String Int -> Either String CreateWorkerBlockResponse
forall (f :: * -> *) a b. Functor 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 CreateWorkerBlock

instance Prelude.NFData CreateWorkerBlock

instance Core.ToHeaders CreateWorkerBlock where
  toHeaders :: CreateWorkerBlock -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateWorkerBlock -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"MTurkRequesterServiceV20170117.CreateWorkerBlock" ::
                          Prelude.ByteString
                      ),
            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 CreateWorkerBlock where
  toJSON :: CreateWorkerBlock -> Value
toJSON CreateWorkerBlock' {Text
reason :: Text
workerId :: Text
$sel:reason:CreateWorkerBlock' :: CreateWorkerBlock -> Text
$sel:workerId:CreateWorkerBlock' :: CreateWorkerBlock -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"WorkerId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
workerId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Reason" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
reason)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateWorkerBlockResponse' 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:
--
-- 'httpStatus', 'createWorkerBlockResponse_httpStatus' - The response's http status code.
newCreateWorkerBlockResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateWorkerBlockResponse
newCreateWorkerBlockResponse :: Int -> CreateWorkerBlockResponse
newCreateWorkerBlockResponse Int
pHttpStatus_ =
  CreateWorkerBlockResponse' :: Int -> CreateWorkerBlockResponse
CreateWorkerBlockResponse'
    { $sel:httpStatus:CreateWorkerBlockResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData CreateWorkerBlockResponse