{-# 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.PollForThirdPartyJobs
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Determines whether there are any third party jobs for a job worker to
-- act on. Used for partner actions only.
--
-- When this API is called, AWS CodePipeline returns temporary credentials
-- for the S3 bucket used to store artifacts for the pipeline, if the
-- action requires access to that S3 bucket for input or output artifacts.
module Amazonka.CodePipeline.PollForThirdPartyJobs
  ( -- * Creating a Request
    PollForThirdPartyJobs (..),
    newPollForThirdPartyJobs,

    -- * Request Lenses
    pollForThirdPartyJobs_maxBatchSize,
    pollForThirdPartyJobs_actionTypeId,

    -- * Destructuring the Response
    PollForThirdPartyJobsResponse (..),
    newPollForThirdPartyJobsResponse,

    -- * Response Lenses
    pollForThirdPartyJobsResponse_jobs,
    pollForThirdPartyJobsResponse_httpStatus,
  )
where

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

-- | Represents the input of a @PollForThirdPartyJobs@ action.
--
-- /See:/ 'newPollForThirdPartyJobs' smart constructor.
data PollForThirdPartyJobs = PollForThirdPartyJobs'
  { -- | The maximum number of jobs to return in a poll for jobs call.
    PollForThirdPartyJobs -> Maybe Natural
maxBatchSize :: Prelude.Maybe Prelude.Natural,
    -- | Represents information about an action type.
    PollForThirdPartyJobs -> ActionTypeId
actionTypeId :: ActionTypeId
  }
  deriving (PollForThirdPartyJobs -> PollForThirdPartyJobs -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PollForThirdPartyJobs -> PollForThirdPartyJobs -> Bool
$c/= :: PollForThirdPartyJobs -> PollForThirdPartyJobs -> Bool
== :: PollForThirdPartyJobs -> PollForThirdPartyJobs -> Bool
$c== :: PollForThirdPartyJobs -> PollForThirdPartyJobs -> Bool
Prelude.Eq, ReadPrec [PollForThirdPartyJobs]
ReadPrec PollForThirdPartyJobs
Int -> ReadS PollForThirdPartyJobs
ReadS [PollForThirdPartyJobs]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PollForThirdPartyJobs]
$creadListPrec :: ReadPrec [PollForThirdPartyJobs]
readPrec :: ReadPrec PollForThirdPartyJobs
$creadPrec :: ReadPrec PollForThirdPartyJobs
readList :: ReadS [PollForThirdPartyJobs]
$creadList :: ReadS [PollForThirdPartyJobs]
readsPrec :: Int -> ReadS PollForThirdPartyJobs
$creadsPrec :: Int -> ReadS PollForThirdPartyJobs
Prelude.Read, Int -> PollForThirdPartyJobs -> ShowS
[PollForThirdPartyJobs] -> ShowS
PollForThirdPartyJobs -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PollForThirdPartyJobs] -> ShowS
$cshowList :: [PollForThirdPartyJobs] -> ShowS
show :: PollForThirdPartyJobs -> String
$cshow :: PollForThirdPartyJobs -> String
showsPrec :: Int -> PollForThirdPartyJobs -> ShowS
$cshowsPrec :: Int -> PollForThirdPartyJobs -> ShowS
Prelude.Show, forall x. Rep PollForThirdPartyJobs x -> PollForThirdPartyJobs
forall x. PollForThirdPartyJobs -> Rep PollForThirdPartyJobs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PollForThirdPartyJobs x -> PollForThirdPartyJobs
$cfrom :: forall x. PollForThirdPartyJobs -> Rep PollForThirdPartyJobs x
Prelude.Generic)

-- |
-- Create a value of 'PollForThirdPartyJobs' 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:
--
-- 'maxBatchSize', 'pollForThirdPartyJobs_maxBatchSize' - The maximum number of jobs to return in a poll for jobs call.
--
-- 'actionTypeId', 'pollForThirdPartyJobs_actionTypeId' - Represents information about an action type.
newPollForThirdPartyJobs ::
  -- | 'actionTypeId'
  ActionTypeId ->
  PollForThirdPartyJobs
newPollForThirdPartyJobs :: ActionTypeId -> PollForThirdPartyJobs
newPollForThirdPartyJobs ActionTypeId
pActionTypeId_ =
  PollForThirdPartyJobs'
    { $sel:maxBatchSize:PollForThirdPartyJobs' :: Maybe Natural
maxBatchSize =
        forall a. Maybe a
Prelude.Nothing,
      $sel:actionTypeId:PollForThirdPartyJobs' :: ActionTypeId
actionTypeId = ActionTypeId
pActionTypeId_
    }

-- | The maximum number of jobs to return in a poll for jobs call.
pollForThirdPartyJobs_maxBatchSize :: Lens.Lens' PollForThirdPartyJobs (Prelude.Maybe Prelude.Natural)
pollForThirdPartyJobs_maxBatchSize :: Lens' PollForThirdPartyJobs (Maybe Natural)
pollForThirdPartyJobs_maxBatchSize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PollForThirdPartyJobs' {Maybe Natural
maxBatchSize :: Maybe Natural
$sel:maxBatchSize:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> Maybe Natural
maxBatchSize} -> Maybe Natural
maxBatchSize) (\s :: PollForThirdPartyJobs
s@PollForThirdPartyJobs' {} Maybe Natural
a -> PollForThirdPartyJobs
s {$sel:maxBatchSize:PollForThirdPartyJobs' :: Maybe Natural
maxBatchSize = Maybe Natural
a} :: PollForThirdPartyJobs)

-- | Represents information about an action type.
pollForThirdPartyJobs_actionTypeId :: Lens.Lens' PollForThirdPartyJobs ActionTypeId
pollForThirdPartyJobs_actionTypeId :: Lens' PollForThirdPartyJobs ActionTypeId
pollForThirdPartyJobs_actionTypeId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PollForThirdPartyJobs' {ActionTypeId
actionTypeId :: ActionTypeId
$sel:actionTypeId:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> ActionTypeId
actionTypeId} -> ActionTypeId
actionTypeId) (\s :: PollForThirdPartyJobs
s@PollForThirdPartyJobs' {} ActionTypeId
a -> PollForThirdPartyJobs
s {$sel:actionTypeId:PollForThirdPartyJobs' :: ActionTypeId
actionTypeId = ActionTypeId
a} :: PollForThirdPartyJobs)

instance Core.AWSRequest PollForThirdPartyJobs where
  type
    AWSResponse PollForThirdPartyJobs =
      PollForThirdPartyJobsResponse
  request :: (Service -> Service)
-> PollForThirdPartyJobs -> Request PollForThirdPartyJobs
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 PollForThirdPartyJobs
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PollForThirdPartyJobs)))
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 [ThirdPartyJob] -> Int -> PollForThirdPartyJobsResponse
PollForThirdPartyJobsResponse'
            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
"jobs" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 PollForThirdPartyJobs where
  hashWithSalt :: Int -> PollForThirdPartyJobs -> Int
hashWithSalt Int
_salt PollForThirdPartyJobs' {Maybe Natural
ActionTypeId
actionTypeId :: ActionTypeId
maxBatchSize :: Maybe Natural
$sel:actionTypeId:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> ActionTypeId
$sel:maxBatchSize:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxBatchSize
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ActionTypeId
actionTypeId

instance Prelude.NFData PollForThirdPartyJobs where
  rnf :: PollForThirdPartyJobs -> ()
rnf PollForThirdPartyJobs' {Maybe Natural
ActionTypeId
actionTypeId :: ActionTypeId
maxBatchSize :: Maybe Natural
$sel:actionTypeId:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> ActionTypeId
$sel:maxBatchSize:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxBatchSize
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ActionTypeId
actionTypeId

instance Data.ToHeaders PollForThirdPartyJobs where
  toHeaders :: PollForThirdPartyJobs -> 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
"CodePipeline_20150709.PollForThirdPartyJobs" ::
                          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 PollForThirdPartyJobs where
  toJSON :: PollForThirdPartyJobs -> Value
toJSON PollForThirdPartyJobs' {Maybe Natural
ActionTypeId
actionTypeId :: ActionTypeId
maxBatchSize :: Maybe Natural
$sel:actionTypeId:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> ActionTypeId
$sel:maxBatchSize:PollForThirdPartyJobs' :: PollForThirdPartyJobs -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"maxBatchSize" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxBatchSize,
            forall a. a -> Maybe a
Prelude.Just (Key
"actionTypeId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ActionTypeId
actionTypeId)
          ]
      )

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

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

-- | Represents the output of a @PollForThirdPartyJobs@ action.
--
-- /See:/ 'newPollForThirdPartyJobsResponse' smart constructor.
data PollForThirdPartyJobsResponse = PollForThirdPartyJobsResponse'
  { -- | Information about the jobs to take action on.
    PollForThirdPartyJobsResponse -> Maybe [ThirdPartyJob]
jobs :: Prelude.Maybe [ThirdPartyJob],
    -- | The response's http status code.
    PollForThirdPartyJobsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PollForThirdPartyJobsResponse
-> PollForThirdPartyJobsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PollForThirdPartyJobsResponse
-> PollForThirdPartyJobsResponse -> Bool
$c/= :: PollForThirdPartyJobsResponse
-> PollForThirdPartyJobsResponse -> Bool
== :: PollForThirdPartyJobsResponse
-> PollForThirdPartyJobsResponse -> Bool
$c== :: PollForThirdPartyJobsResponse
-> PollForThirdPartyJobsResponse -> Bool
Prelude.Eq, ReadPrec [PollForThirdPartyJobsResponse]
ReadPrec PollForThirdPartyJobsResponse
Int -> ReadS PollForThirdPartyJobsResponse
ReadS [PollForThirdPartyJobsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PollForThirdPartyJobsResponse]
$creadListPrec :: ReadPrec [PollForThirdPartyJobsResponse]
readPrec :: ReadPrec PollForThirdPartyJobsResponse
$creadPrec :: ReadPrec PollForThirdPartyJobsResponse
readList :: ReadS [PollForThirdPartyJobsResponse]
$creadList :: ReadS [PollForThirdPartyJobsResponse]
readsPrec :: Int -> ReadS PollForThirdPartyJobsResponse
$creadsPrec :: Int -> ReadS PollForThirdPartyJobsResponse
Prelude.Read, Int -> PollForThirdPartyJobsResponse -> ShowS
[PollForThirdPartyJobsResponse] -> ShowS
PollForThirdPartyJobsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PollForThirdPartyJobsResponse] -> ShowS
$cshowList :: [PollForThirdPartyJobsResponse] -> ShowS
show :: PollForThirdPartyJobsResponse -> String
$cshow :: PollForThirdPartyJobsResponse -> String
showsPrec :: Int -> PollForThirdPartyJobsResponse -> ShowS
$cshowsPrec :: Int -> PollForThirdPartyJobsResponse -> ShowS
Prelude.Show, forall x.
Rep PollForThirdPartyJobsResponse x
-> PollForThirdPartyJobsResponse
forall x.
PollForThirdPartyJobsResponse
-> Rep PollForThirdPartyJobsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PollForThirdPartyJobsResponse x
-> PollForThirdPartyJobsResponse
$cfrom :: forall x.
PollForThirdPartyJobsResponse
-> Rep PollForThirdPartyJobsResponse x
Prelude.Generic)

-- |
-- Create a value of 'PollForThirdPartyJobsResponse' 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:
--
-- 'jobs', 'pollForThirdPartyJobsResponse_jobs' - Information about the jobs to take action on.
--
-- 'httpStatus', 'pollForThirdPartyJobsResponse_httpStatus' - The response's http status code.
newPollForThirdPartyJobsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PollForThirdPartyJobsResponse
newPollForThirdPartyJobsResponse :: Int -> PollForThirdPartyJobsResponse
newPollForThirdPartyJobsResponse Int
pHttpStatus_ =
  PollForThirdPartyJobsResponse'
    { $sel:jobs:PollForThirdPartyJobsResponse' :: Maybe [ThirdPartyJob]
jobs =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PollForThirdPartyJobsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the jobs to take action on.
pollForThirdPartyJobsResponse_jobs :: Lens.Lens' PollForThirdPartyJobsResponse (Prelude.Maybe [ThirdPartyJob])
pollForThirdPartyJobsResponse_jobs :: Lens' PollForThirdPartyJobsResponse (Maybe [ThirdPartyJob])
pollForThirdPartyJobsResponse_jobs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PollForThirdPartyJobsResponse' {Maybe [ThirdPartyJob]
jobs :: Maybe [ThirdPartyJob]
$sel:jobs:PollForThirdPartyJobsResponse' :: PollForThirdPartyJobsResponse -> Maybe [ThirdPartyJob]
jobs} -> Maybe [ThirdPartyJob]
jobs) (\s :: PollForThirdPartyJobsResponse
s@PollForThirdPartyJobsResponse' {} Maybe [ThirdPartyJob]
a -> PollForThirdPartyJobsResponse
s {$sel:jobs:PollForThirdPartyJobsResponse' :: Maybe [ThirdPartyJob]
jobs = Maybe [ThirdPartyJob]
a} :: PollForThirdPartyJobsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData PollForThirdPartyJobsResponse where
  rnf :: PollForThirdPartyJobsResponse -> ()
rnf PollForThirdPartyJobsResponse' {Int
Maybe [ThirdPartyJob]
httpStatus :: Int
jobs :: Maybe [ThirdPartyJob]
$sel:httpStatus:PollForThirdPartyJobsResponse' :: PollForThirdPartyJobsResponse -> Int
$sel:jobs:PollForThirdPartyJobsResponse' :: PollForThirdPartyJobsResponse -> Maybe [ThirdPartyJob]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ThirdPartyJob]
jobs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus