{-# 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.CodePipeline.AcknowledgeJob
-- 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)
--
-- Returns information about a specified job and whether that job has been
-- received by the job worker. Used for custom actions only.
module Amazonka.CodePipeline.AcknowledgeJob
  ( -- * Creating a Request
    AcknowledgeJob (..),
    newAcknowledgeJob,

    -- * Request Lenses
    acknowledgeJob_jobId,
    acknowledgeJob_nonce,

    -- * Destructuring the Response
    AcknowledgeJobResponse (..),
    newAcknowledgeJobResponse,

    -- * Response Lenses
    acknowledgeJobResponse_status,
    acknowledgeJobResponse_httpStatus,
  )
where

import Amazonka.CodePipeline.Types
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

-- | Represents the input of an AcknowledgeJob action.
--
-- /See:/ 'newAcknowledgeJob' smart constructor.
data AcknowledgeJob = AcknowledgeJob'
  { -- | The unique system-generated ID of the job for which you want to confirm
    -- receipt.
    AcknowledgeJob -> Text
jobId :: Prelude.Text,
    -- | A system-generated random number that AWS CodePipeline uses to ensure
    -- that the job is being worked on by only one job worker. Get this number
    -- from the response of the PollForJobs request that returned this job.
    AcknowledgeJob -> Text
nonce :: Prelude.Text
  }
  deriving (AcknowledgeJob -> AcknowledgeJob -> Bool
(AcknowledgeJob -> AcknowledgeJob -> Bool)
-> (AcknowledgeJob -> AcknowledgeJob -> Bool) -> Eq AcknowledgeJob
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AcknowledgeJob -> AcknowledgeJob -> Bool
$c/= :: AcknowledgeJob -> AcknowledgeJob -> Bool
== :: AcknowledgeJob -> AcknowledgeJob -> Bool
$c== :: AcknowledgeJob -> AcknowledgeJob -> Bool
Prelude.Eq, ReadPrec [AcknowledgeJob]
ReadPrec AcknowledgeJob
Int -> ReadS AcknowledgeJob
ReadS [AcknowledgeJob]
(Int -> ReadS AcknowledgeJob)
-> ReadS [AcknowledgeJob]
-> ReadPrec AcknowledgeJob
-> ReadPrec [AcknowledgeJob]
-> Read AcknowledgeJob
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AcknowledgeJob]
$creadListPrec :: ReadPrec [AcknowledgeJob]
readPrec :: ReadPrec AcknowledgeJob
$creadPrec :: ReadPrec AcknowledgeJob
readList :: ReadS [AcknowledgeJob]
$creadList :: ReadS [AcknowledgeJob]
readsPrec :: Int -> ReadS AcknowledgeJob
$creadsPrec :: Int -> ReadS AcknowledgeJob
Prelude.Read, Int -> AcknowledgeJob -> ShowS
[AcknowledgeJob] -> ShowS
AcknowledgeJob -> String
(Int -> AcknowledgeJob -> ShowS)
-> (AcknowledgeJob -> String)
-> ([AcknowledgeJob] -> ShowS)
-> Show AcknowledgeJob
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AcknowledgeJob] -> ShowS
$cshowList :: [AcknowledgeJob] -> ShowS
show :: AcknowledgeJob -> String
$cshow :: AcknowledgeJob -> String
showsPrec :: Int -> AcknowledgeJob -> ShowS
$cshowsPrec :: Int -> AcknowledgeJob -> ShowS
Prelude.Show, (forall x. AcknowledgeJob -> Rep AcknowledgeJob x)
-> (forall x. Rep AcknowledgeJob x -> AcknowledgeJob)
-> Generic AcknowledgeJob
forall x. Rep AcknowledgeJob x -> AcknowledgeJob
forall x. AcknowledgeJob -> Rep AcknowledgeJob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AcknowledgeJob x -> AcknowledgeJob
$cfrom :: forall x. AcknowledgeJob -> Rep AcknowledgeJob x
Prelude.Generic)

-- |
-- Create a value of 'AcknowledgeJob' 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', 'acknowledgeJob_jobId' - The unique system-generated ID of the job for which you want to confirm
-- receipt.
--
-- 'nonce', 'acknowledgeJob_nonce' - A system-generated random number that AWS CodePipeline uses to ensure
-- that the job is being worked on by only one job worker. Get this number
-- from the response of the PollForJobs request that returned this job.
newAcknowledgeJob ::
  -- | 'jobId'
  Prelude.Text ->
  -- | 'nonce'
  Prelude.Text ->
  AcknowledgeJob
newAcknowledgeJob :: Text -> Text -> AcknowledgeJob
newAcknowledgeJob Text
pJobId_ Text
pNonce_ =
  AcknowledgeJob' :: Text -> Text -> AcknowledgeJob
AcknowledgeJob' {$sel:jobId:AcknowledgeJob' :: Text
jobId = Text
pJobId_, $sel:nonce:AcknowledgeJob' :: Text
nonce = Text
pNonce_}

-- | The unique system-generated ID of the job for which you want to confirm
-- receipt.
acknowledgeJob_jobId :: Lens.Lens' AcknowledgeJob Prelude.Text
acknowledgeJob_jobId :: (Text -> f Text) -> AcknowledgeJob -> f AcknowledgeJob
acknowledgeJob_jobId = (AcknowledgeJob -> Text)
-> (AcknowledgeJob -> Text -> AcknowledgeJob)
-> Lens AcknowledgeJob AcknowledgeJob Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AcknowledgeJob' {Text
jobId :: Text
$sel:jobId:AcknowledgeJob' :: AcknowledgeJob -> Text
jobId} -> Text
jobId) (\s :: AcknowledgeJob
s@AcknowledgeJob' {} Text
a -> AcknowledgeJob
s {$sel:jobId:AcknowledgeJob' :: Text
jobId = Text
a} :: AcknowledgeJob)

-- | A system-generated random number that AWS CodePipeline uses to ensure
-- that the job is being worked on by only one job worker. Get this number
-- from the response of the PollForJobs request that returned this job.
acknowledgeJob_nonce :: Lens.Lens' AcknowledgeJob Prelude.Text
acknowledgeJob_nonce :: (Text -> f Text) -> AcknowledgeJob -> f AcknowledgeJob
acknowledgeJob_nonce = (AcknowledgeJob -> Text)
-> (AcknowledgeJob -> Text -> AcknowledgeJob)
-> Lens AcknowledgeJob AcknowledgeJob Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AcknowledgeJob' {Text
nonce :: Text
$sel:nonce:AcknowledgeJob' :: AcknowledgeJob -> Text
nonce} -> Text
nonce) (\s :: AcknowledgeJob
s@AcknowledgeJob' {} Text
a -> AcknowledgeJob
s {$sel:nonce:AcknowledgeJob' :: Text
nonce = Text
a} :: AcknowledgeJob)

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

instance Prelude.NFData AcknowledgeJob

instance Core.ToHeaders AcknowledgeJob where
  toHeaders :: AcknowledgeJob -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AcknowledgeJob -> 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
"CodePipeline_20150709.AcknowledgeJob" ::
                          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 AcknowledgeJob where
  toJSON :: AcknowledgeJob -> Value
toJSON AcknowledgeJob' {Text
nonce :: Text
jobId :: Text
$sel:nonce:AcknowledgeJob' :: AcknowledgeJob -> Text
$sel:jobId:AcknowledgeJob' :: AcknowledgeJob -> 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
"jobId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
jobId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"nonce" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
nonce)
          ]
      )

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

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

-- | Represents the output of an AcknowledgeJob action.
--
-- /See:/ 'newAcknowledgeJobResponse' smart constructor.
data AcknowledgeJobResponse = AcknowledgeJobResponse'
  { -- | Whether the job worker has received the specified job.
    AcknowledgeJobResponse -> Maybe JobStatus
status :: Prelude.Maybe JobStatus,
    -- | The response's http status code.
    AcknowledgeJobResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool
(AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool)
-> (AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool)
-> Eq AcknowledgeJobResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool
$c/= :: AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool
== :: AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool
$c== :: AcknowledgeJobResponse -> AcknowledgeJobResponse -> Bool
Prelude.Eq, ReadPrec [AcknowledgeJobResponse]
ReadPrec AcknowledgeJobResponse
Int -> ReadS AcknowledgeJobResponse
ReadS [AcknowledgeJobResponse]
(Int -> ReadS AcknowledgeJobResponse)
-> ReadS [AcknowledgeJobResponse]
-> ReadPrec AcknowledgeJobResponse
-> ReadPrec [AcknowledgeJobResponse]
-> Read AcknowledgeJobResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AcknowledgeJobResponse]
$creadListPrec :: ReadPrec [AcknowledgeJobResponse]
readPrec :: ReadPrec AcknowledgeJobResponse
$creadPrec :: ReadPrec AcknowledgeJobResponse
readList :: ReadS [AcknowledgeJobResponse]
$creadList :: ReadS [AcknowledgeJobResponse]
readsPrec :: Int -> ReadS AcknowledgeJobResponse
$creadsPrec :: Int -> ReadS AcknowledgeJobResponse
Prelude.Read, Int -> AcknowledgeJobResponse -> ShowS
[AcknowledgeJobResponse] -> ShowS
AcknowledgeJobResponse -> String
(Int -> AcknowledgeJobResponse -> ShowS)
-> (AcknowledgeJobResponse -> String)
-> ([AcknowledgeJobResponse] -> ShowS)
-> Show AcknowledgeJobResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AcknowledgeJobResponse] -> ShowS
$cshowList :: [AcknowledgeJobResponse] -> ShowS
show :: AcknowledgeJobResponse -> String
$cshow :: AcknowledgeJobResponse -> String
showsPrec :: Int -> AcknowledgeJobResponse -> ShowS
$cshowsPrec :: Int -> AcknowledgeJobResponse -> ShowS
Prelude.Show, (forall x. AcknowledgeJobResponse -> Rep AcknowledgeJobResponse x)
-> (forall x.
    Rep AcknowledgeJobResponse x -> AcknowledgeJobResponse)
-> Generic AcknowledgeJobResponse
forall x. Rep AcknowledgeJobResponse x -> AcknowledgeJobResponse
forall x. AcknowledgeJobResponse -> Rep AcknowledgeJobResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AcknowledgeJobResponse x -> AcknowledgeJobResponse
$cfrom :: forall x. AcknowledgeJobResponse -> Rep AcknowledgeJobResponse x
Prelude.Generic)

-- |
-- Create a value of 'AcknowledgeJobResponse' 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:
--
-- 'status', 'acknowledgeJobResponse_status' - Whether the job worker has received the specified job.
--
-- 'httpStatus', 'acknowledgeJobResponse_httpStatus' - The response's http status code.
newAcknowledgeJobResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AcknowledgeJobResponse
newAcknowledgeJobResponse :: Int -> AcknowledgeJobResponse
newAcknowledgeJobResponse Int
pHttpStatus_ =
  AcknowledgeJobResponse' :: Maybe JobStatus -> Int -> AcknowledgeJobResponse
AcknowledgeJobResponse'
    { $sel:status:AcknowledgeJobResponse' :: Maybe JobStatus
status = Maybe JobStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AcknowledgeJobResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Whether the job worker has received the specified job.
acknowledgeJobResponse_status :: Lens.Lens' AcknowledgeJobResponse (Prelude.Maybe JobStatus)
acknowledgeJobResponse_status :: (Maybe JobStatus -> f (Maybe JobStatus))
-> AcknowledgeJobResponse -> f AcknowledgeJobResponse
acknowledgeJobResponse_status = (AcknowledgeJobResponse -> Maybe JobStatus)
-> (AcknowledgeJobResponse
    -> Maybe JobStatus -> AcknowledgeJobResponse)
-> Lens
     AcknowledgeJobResponse
     AcknowledgeJobResponse
     (Maybe JobStatus)
     (Maybe JobStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AcknowledgeJobResponse' {Maybe JobStatus
status :: Maybe JobStatus
$sel:status:AcknowledgeJobResponse' :: AcknowledgeJobResponse -> Maybe JobStatus
status} -> Maybe JobStatus
status) (\s :: AcknowledgeJobResponse
s@AcknowledgeJobResponse' {} Maybe JobStatus
a -> AcknowledgeJobResponse
s {$sel:status:AcknowledgeJobResponse' :: Maybe JobStatus
status = Maybe JobStatus
a} :: AcknowledgeJobResponse)

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

instance Prelude.NFData AcknowledgeJobResponse