{-# 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.ApproveAssignment
-- 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 @ApproveAssignment@ operation approves the results of a completed
-- assignment.
--
-- Approving an assignment initiates two payments from the Requester\'s
-- Amazon.com account
--
-- -   The Worker who submitted the results is paid the reward specified in
--     the HIT.
--
-- -   Amazon Mechanical Turk fees are debited.
--
-- If the Requester\'s account does not have adequate funds for these
-- payments, the call to ApproveAssignment returns an exception, and the
-- approval is not processed. You can include an optional feedback message
-- with the approval, which the Worker can see in the Status section of the
-- web site.
--
-- You can also call this operation for assignments that were previous
-- rejected and approve them by explicitly overriding the previous
-- rejection. This only works on rejected assignments that were submitted
-- within the previous 30 days and only if the assignment\'s related HIT
-- has not been deleted.
module Amazonka.MechanicalTurk.ApproveAssignment
  ( -- * Creating a Request
    ApproveAssignment (..),
    newApproveAssignment,

    -- * Request Lenses
    approveAssignment_overrideRejection,
    approveAssignment_requesterFeedback,
    approveAssignment_assignmentId,

    -- * Destructuring the Response
    ApproveAssignmentResponse (..),
    newApproveAssignmentResponse,

    -- * Response Lenses
    approveAssignmentResponse_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:/ 'newApproveAssignment' smart constructor.
data ApproveAssignment = ApproveAssignment'
  { -- | A flag indicating that an assignment should be approved even if it was
    -- previously rejected. Defaults to @False@.
    ApproveAssignment -> Maybe Bool
overrideRejection :: Prelude.Maybe Prelude.Bool,
    -- | A message for the Worker, which the Worker can see in the Status section
    -- of the web site.
    ApproveAssignment -> Maybe Text
requesterFeedback :: Prelude.Maybe Prelude.Text,
    -- | The ID of the assignment. The assignment must correspond to a HIT
    -- created by the Requester.
    ApproveAssignment -> Text
assignmentId :: Prelude.Text
  }
  deriving (ApproveAssignment -> ApproveAssignment -> Bool
(ApproveAssignment -> ApproveAssignment -> Bool)
-> (ApproveAssignment -> ApproveAssignment -> Bool)
-> Eq ApproveAssignment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApproveAssignment -> ApproveAssignment -> Bool
$c/= :: ApproveAssignment -> ApproveAssignment -> Bool
== :: ApproveAssignment -> ApproveAssignment -> Bool
$c== :: ApproveAssignment -> ApproveAssignment -> Bool
Prelude.Eq, ReadPrec [ApproveAssignment]
ReadPrec ApproveAssignment
Int -> ReadS ApproveAssignment
ReadS [ApproveAssignment]
(Int -> ReadS ApproveAssignment)
-> ReadS [ApproveAssignment]
-> ReadPrec ApproveAssignment
-> ReadPrec [ApproveAssignment]
-> Read ApproveAssignment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApproveAssignment]
$creadListPrec :: ReadPrec [ApproveAssignment]
readPrec :: ReadPrec ApproveAssignment
$creadPrec :: ReadPrec ApproveAssignment
readList :: ReadS [ApproveAssignment]
$creadList :: ReadS [ApproveAssignment]
readsPrec :: Int -> ReadS ApproveAssignment
$creadsPrec :: Int -> ReadS ApproveAssignment
Prelude.Read, Int -> ApproveAssignment -> ShowS
[ApproveAssignment] -> ShowS
ApproveAssignment -> String
(Int -> ApproveAssignment -> ShowS)
-> (ApproveAssignment -> String)
-> ([ApproveAssignment] -> ShowS)
-> Show ApproveAssignment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApproveAssignment] -> ShowS
$cshowList :: [ApproveAssignment] -> ShowS
show :: ApproveAssignment -> String
$cshow :: ApproveAssignment -> String
showsPrec :: Int -> ApproveAssignment -> ShowS
$cshowsPrec :: Int -> ApproveAssignment -> ShowS
Prelude.Show, (forall x. ApproveAssignment -> Rep ApproveAssignment x)
-> (forall x. Rep ApproveAssignment x -> ApproveAssignment)
-> Generic ApproveAssignment
forall x. Rep ApproveAssignment x -> ApproveAssignment
forall x. ApproveAssignment -> Rep ApproveAssignment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApproveAssignment x -> ApproveAssignment
$cfrom :: forall x. ApproveAssignment -> Rep ApproveAssignment x
Prelude.Generic)

-- |
-- Create a value of 'ApproveAssignment' 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:
--
-- 'overrideRejection', 'approveAssignment_overrideRejection' - A flag indicating that an assignment should be approved even if it was
-- previously rejected. Defaults to @False@.
--
-- 'requesterFeedback', 'approveAssignment_requesterFeedback' - A message for the Worker, which the Worker can see in the Status section
-- of the web site.
--
-- 'assignmentId', 'approveAssignment_assignmentId' - The ID of the assignment. The assignment must correspond to a HIT
-- created by the Requester.
newApproveAssignment ::
  -- | 'assignmentId'
  Prelude.Text ->
  ApproveAssignment
newApproveAssignment :: Text -> ApproveAssignment
newApproveAssignment Text
pAssignmentId_ =
  ApproveAssignment' :: Maybe Bool -> Maybe Text -> Text -> ApproveAssignment
ApproveAssignment'
    { $sel:overrideRejection:ApproveAssignment' :: Maybe Bool
overrideRejection =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:requesterFeedback:ApproveAssignment' :: Maybe Text
requesterFeedback = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:assignmentId:ApproveAssignment' :: Text
assignmentId = Text
pAssignmentId_
    }

-- | A flag indicating that an assignment should be approved even if it was
-- previously rejected. Defaults to @False@.
approveAssignment_overrideRejection :: Lens.Lens' ApproveAssignment (Prelude.Maybe Prelude.Bool)
approveAssignment_overrideRejection :: (Maybe Bool -> f (Maybe Bool))
-> ApproveAssignment -> f ApproveAssignment
approveAssignment_overrideRejection = (ApproveAssignment -> Maybe Bool)
-> (ApproveAssignment -> Maybe Bool -> ApproveAssignment)
-> Lens
     ApproveAssignment ApproveAssignment (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApproveAssignment' {Maybe Bool
overrideRejection :: Maybe Bool
$sel:overrideRejection:ApproveAssignment' :: ApproveAssignment -> Maybe Bool
overrideRejection} -> Maybe Bool
overrideRejection) (\s :: ApproveAssignment
s@ApproveAssignment' {} Maybe Bool
a -> ApproveAssignment
s {$sel:overrideRejection:ApproveAssignment' :: Maybe Bool
overrideRejection = Maybe Bool
a} :: ApproveAssignment)

-- | A message for the Worker, which the Worker can see in the Status section
-- of the web site.
approveAssignment_requesterFeedback :: Lens.Lens' ApproveAssignment (Prelude.Maybe Prelude.Text)
approveAssignment_requesterFeedback :: (Maybe Text -> f (Maybe Text))
-> ApproveAssignment -> f ApproveAssignment
approveAssignment_requesterFeedback = (ApproveAssignment -> Maybe Text)
-> (ApproveAssignment -> Maybe Text -> ApproveAssignment)
-> Lens
     ApproveAssignment ApproveAssignment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApproveAssignment' {Maybe Text
requesterFeedback :: Maybe Text
$sel:requesterFeedback:ApproveAssignment' :: ApproveAssignment -> Maybe Text
requesterFeedback} -> Maybe Text
requesterFeedback) (\s :: ApproveAssignment
s@ApproveAssignment' {} Maybe Text
a -> ApproveAssignment
s {$sel:requesterFeedback:ApproveAssignment' :: Maybe Text
requesterFeedback = Maybe Text
a} :: ApproveAssignment)

-- | The ID of the assignment. The assignment must correspond to a HIT
-- created by the Requester.
approveAssignment_assignmentId :: Lens.Lens' ApproveAssignment Prelude.Text
approveAssignment_assignmentId :: (Text -> f Text) -> ApproveAssignment -> f ApproveAssignment
approveAssignment_assignmentId = (ApproveAssignment -> Text)
-> (ApproveAssignment -> Text -> ApproveAssignment)
-> Lens ApproveAssignment ApproveAssignment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApproveAssignment' {Text
assignmentId :: Text
$sel:assignmentId:ApproveAssignment' :: ApproveAssignment -> Text
assignmentId} -> Text
assignmentId) (\s :: ApproveAssignment
s@ApproveAssignment' {} Text
a -> ApproveAssignment
s {$sel:assignmentId:ApproveAssignment' :: Text
assignmentId = Text
a} :: ApproveAssignment)

instance Core.AWSRequest ApproveAssignment where
  type
    AWSResponse ApproveAssignment =
      ApproveAssignmentResponse
  request :: ApproveAssignment -> Request ApproveAssignment
request = Service -> ApproveAssignment -> Request ApproveAssignment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ApproveAssignment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ApproveAssignment)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse ApproveAssignment))
-> Logger
-> Service
-> Proxy ApproveAssignment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ApproveAssignment)))
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 -> ApproveAssignmentResponse
ApproveAssignmentResponse'
            (Int -> ApproveAssignmentResponse)
-> Either String Int -> Either String ApproveAssignmentResponse
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 ApproveAssignment

instance Prelude.NFData ApproveAssignment

instance Core.ToHeaders ApproveAssignment where
  toHeaders :: ApproveAssignment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ApproveAssignment -> 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.ApproveAssignment" ::
                          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 ApproveAssignment where
  toJSON :: ApproveAssignment -> Value
toJSON ApproveAssignment' {Maybe Bool
Maybe Text
Text
assignmentId :: Text
requesterFeedback :: Maybe Text
overrideRejection :: Maybe Bool
$sel:assignmentId:ApproveAssignment' :: ApproveAssignment -> Text
$sel:requesterFeedback:ApproveAssignment' :: ApproveAssignment -> Maybe Text
$sel:overrideRejection:ApproveAssignment' :: ApproveAssignment -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"OverrideRejection" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
overrideRejection,
            (Text
"RequesterFeedback" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
requesterFeedback,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"AssignmentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
assignmentId)
          ]
      )

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

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

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

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

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

instance Prelude.NFData ApproveAssignmentResponse