{-# 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.GetAssignment
-- 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 @GetAssignment@ operation retrieves the details of the specified
-- Assignment.
module Amazonka.MechanicalTurk.GetAssignment
  ( -- * Creating a Request
    GetAssignment (..),
    newGetAssignment,

    -- * Request Lenses
    getAssignment_assignmentId,

    -- * Destructuring the Response
    GetAssignmentResponse (..),
    newGetAssignmentResponse,

    -- * Response Lenses
    getAssignmentResponse_hit,
    getAssignmentResponse_assignment,
    getAssignmentResponse_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:/ 'newGetAssignment' smart constructor.
data GetAssignment = GetAssignment'
  { -- | The ID of the Assignment to be retrieved.
    GetAssignment -> Text
assignmentId :: Prelude.Text
  }
  deriving (GetAssignment -> GetAssignment -> Bool
(GetAssignment -> GetAssignment -> Bool)
-> (GetAssignment -> GetAssignment -> Bool) -> Eq GetAssignment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAssignment -> GetAssignment -> Bool
$c/= :: GetAssignment -> GetAssignment -> Bool
== :: GetAssignment -> GetAssignment -> Bool
$c== :: GetAssignment -> GetAssignment -> Bool
Prelude.Eq, ReadPrec [GetAssignment]
ReadPrec GetAssignment
Int -> ReadS GetAssignment
ReadS [GetAssignment]
(Int -> ReadS GetAssignment)
-> ReadS [GetAssignment]
-> ReadPrec GetAssignment
-> ReadPrec [GetAssignment]
-> Read GetAssignment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAssignment]
$creadListPrec :: ReadPrec [GetAssignment]
readPrec :: ReadPrec GetAssignment
$creadPrec :: ReadPrec GetAssignment
readList :: ReadS [GetAssignment]
$creadList :: ReadS [GetAssignment]
readsPrec :: Int -> ReadS GetAssignment
$creadsPrec :: Int -> ReadS GetAssignment
Prelude.Read, Int -> GetAssignment -> ShowS
[GetAssignment] -> ShowS
GetAssignment -> String
(Int -> GetAssignment -> ShowS)
-> (GetAssignment -> String)
-> ([GetAssignment] -> ShowS)
-> Show GetAssignment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAssignment] -> ShowS
$cshowList :: [GetAssignment] -> ShowS
show :: GetAssignment -> String
$cshow :: GetAssignment -> String
showsPrec :: Int -> GetAssignment -> ShowS
$cshowsPrec :: Int -> GetAssignment -> ShowS
Prelude.Show, (forall x. GetAssignment -> Rep GetAssignment x)
-> (forall x. Rep GetAssignment x -> GetAssignment)
-> Generic GetAssignment
forall x. Rep GetAssignment x -> GetAssignment
forall x. GetAssignment -> Rep GetAssignment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAssignment x -> GetAssignment
$cfrom :: forall x. GetAssignment -> Rep GetAssignment x
Prelude.Generic)

-- |
-- Create a value of 'GetAssignment' 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:
--
-- 'assignmentId', 'getAssignment_assignmentId' - The ID of the Assignment to be retrieved.
newGetAssignment ::
  -- | 'assignmentId'
  Prelude.Text ->
  GetAssignment
newGetAssignment :: Text -> GetAssignment
newGetAssignment Text
pAssignmentId_ =
  GetAssignment' :: Text -> GetAssignment
GetAssignment' {$sel:assignmentId:GetAssignment' :: Text
assignmentId = Text
pAssignmentId_}

-- | The ID of the Assignment to be retrieved.
getAssignment_assignmentId :: Lens.Lens' GetAssignment Prelude.Text
getAssignment_assignmentId :: (Text -> f Text) -> GetAssignment -> f GetAssignment
getAssignment_assignmentId = (GetAssignment -> Text)
-> (GetAssignment -> Text -> GetAssignment)
-> Lens GetAssignment GetAssignment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAssignment' {Text
assignmentId :: Text
$sel:assignmentId:GetAssignment' :: GetAssignment -> Text
assignmentId} -> Text
assignmentId) (\s :: GetAssignment
s@GetAssignment' {} Text
a -> GetAssignment
s {$sel:assignmentId:GetAssignment' :: Text
assignmentId = Text
a} :: GetAssignment)

instance Core.AWSRequest GetAssignment where
  type
    AWSResponse GetAssignment =
      GetAssignmentResponse
  request :: GetAssignment -> Request GetAssignment
request = Service -> GetAssignment -> Request GetAssignment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAssignment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAssignment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetAssignment))
-> Logger
-> Service
-> Proxy GetAssignment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAssignment)))
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 HIT -> Maybe Assignment -> Int -> GetAssignmentResponse
GetAssignmentResponse'
            (Maybe HIT -> Maybe Assignment -> Int -> GetAssignmentResponse)
-> Either String (Maybe HIT)
-> Either String (Maybe Assignment -> Int -> GetAssignmentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe HIT)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"HIT")
            Either String (Maybe Assignment -> Int -> GetAssignmentResponse)
-> Either String (Maybe Assignment)
-> Either String (Int -> GetAssignmentResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Assignment)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Assignment")
            Either String (Int -> GetAssignmentResponse)
-> Either String Int -> Either String GetAssignmentResponse
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 GetAssignment

instance Prelude.NFData GetAssignment

instance Core.ToHeaders GetAssignment where
  toHeaders :: GetAssignment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetAssignment -> 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.GetAssignment" ::
                          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 GetAssignment where
  toJSON :: GetAssignment -> Value
toJSON GetAssignment' {Text
assignmentId :: Text
$sel:assignmentId:GetAssignment' :: GetAssignment -> 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
"AssignmentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
assignmentId)]
      )

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

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

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

-- |
-- Create a value of 'GetAssignmentResponse' 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:
--
-- 'hit', 'getAssignmentResponse_hit' - The HIT associated with this assignment. The response includes one HIT
-- element.
--
-- 'assignment', 'getAssignmentResponse_assignment' - The assignment. The response includes one Assignment element.
--
-- 'httpStatus', 'getAssignmentResponse_httpStatus' - The response's http status code.
newGetAssignmentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAssignmentResponse
newGetAssignmentResponse :: Int -> GetAssignmentResponse
newGetAssignmentResponse Int
pHttpStatus_ =
  GetAssignmentResponse' :: Maybe HIT -> Maybe Assignment -> Int -> GetAssignmentResponse
GetAssignmentResponse'
    { $sel:hit:GetAssignmentResponse' :: Maybe HIT
hit = Maybe HIT
forall a. Maybe a
Prelude.Nothing,
      $sel:assignment:GetAssignmentResponse' :: Maybe Assignment
assignment = Maybe Assignment
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAssignmentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The HIT associated with this assignment. The response includes one HIT
-- element.
getAssignmentResponse_hit :: Lens.Lens' GetAssignmentResponse (Prelude.Maybe HIT)
getAssignmentResponse_hit :: (Maybe HIT -> f (Maybe HIT))
-> GetAssignmentResponse -> f GetAssignmentResponse
getAssignmentResponse_hit = (GetAssignmentResponse -> Maybe HIT)
-> (GetAssignmentResponse -> Maybe HIT -> GetAssignmentResponse)
-> Lens
     GetAssignmentResponse GetAssignmentResponse (Maybe HIT) (Maybe HIT)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAssignmentResponse' {Maybe HIT
hit :: Maybe HIT
$sel:hit:GetAssignmentResponse' :: GetAssignmentResponse -> Maybe HIT
hit} -> Maybe HIT
hit) (\s :: GetAssignmentResponse
s@GetAssignmentResponse' {} Maybe HIT
a -> GetAssignmentResponse
s {$sel:hit:GetAssignmentResponse' :: Maybe HIT
hit = Maybe HIT
a} :: GetAssignmentResponse)

-- | The assignment. The response includes one Assignment element.
getAssignmentResponse_assignment :: Lens.Lens' GetAssignmentResponse (Prelude.Maybe Assignment)
getAssignmentResponse_assignment :: (Maybe Assignment -> f (Maybe Assignment))
-> GetAssignmentResponse -> f GetAssignmentResponse
getAssignmentResponse_assignment = (GetAssignmentResponse -> Maybe Assignment)
-> (GetAssignmentResponse
    -> Maybe Assignment -> GetAssignmentResponse)
-> Lens
     GetAssignmentResponse
     GetAssignmentResponse
     (Maybe Assignment)
     (Maybe Assignment)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAssignmentResponse' {Maybe Assignment
assignment :: Maybe Assignment
$sel:assignment:GetAssignmentResponse' :: GetAssignmentResponse -> Maybe Assignment
assignment} -> Maybe Assignment
assignment) (\s :: GetAssignmentResponse
s@GetAssignmentResponse' {} Maybe Assignment
a -> GetAssignmentResponse
s {$sel:assignment:GetAssignmentResponse' :: Maybe Assignment
assignment = Maybe Assignment
a} :: GetAssignmentResponse)

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

instance Prelude.NFData GetAssignmentResponse