{-# 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.CodeBuild.ListBuilds
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a list of build IDs, with each build ID representing a single
-- build.
--
-- This operation returns paginated results.
module Amazonka.CodeBuild.ListBuilds
  ( -- * Creating a Request
    ListBuilds (..),
    newListBuilds,

    -- * Request Lenses
    listBuilds_nextToken,
    listBuilds_sortOrder,

    -- * Destructuring the Response
    ListBuildsResponse (..),
    newListBuildsResponse,

    -- * Response Lenses
    listBuildsResponse_ids,
    listBuildsResponse_nextToken,
    listBuildsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListBuilds' smart constructor.
data ListBuilds = ListBuilds'
  { -- | During a previous call, if there are more than 100 items in the list,
    -- only the first 100 items are returned, along with a unique string called
    -- a /nextToken/. To get the next batch of items in the list, call this
    -- operation again, adding the next token to the call. To get all of the
    -- items in the list, keep calling this operation with each subsequent next
    -- token that is returned, until no more next tokens are returned.
    ListBuilds -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The order to list build IDs. Valid values include:
    --
    -- -   @ASCENDING@: List the build IDs in ascending order by build ID.
    --
    -- -   @DESCENDING@: List the build IDs in descending order by build ID.
    ListBuilds -> Maybe SortOrderType
sortOrder :: Prelude.Maybe SortOrderType
  }
  deriving (ListBuilds -> ListBuilds -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBuilds -> ListBuilds -> Bool
$c/= :: ListBuilds -> ListBuilds -> Bool
== :: ListBuilds -> ListBuilds -> Bool
$c== :: ListBuilds -> ListBuilds -> Bool
Prelude.Eq, ReadPrec [ListBuilds]
ReadPrec ListBuilds
Int -> ReadS ListBuilds
ReadS [ListBuilds]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBuilds]
$creadListPrec :: ReadPrec [ListBuilds]
readPrec :: ReadPrec ListBuilds
$creadPrec :: ReadPrec ListBuilds
readList :: ReadS [ListBuilds]
$creadList :: ReadS [ListBuilds]
readsPrec :: Int -> ReadS ListBuilds
$creadsPrec :: Int -> ReadS ListBuilds
Prelude.Read, Int -> ListBuilds -> ShowS
[ListBuilds] -> ShowS
ListBuilds -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBuilds] -> ShowS
$cshowList :: [ListBuilds] -> ShowS
show :: ListBuilds -> String
$cshow :: ListBuilds -> String
showsPrec :: Int -> ListBuilds -> ShowS
$cshowsPrec :: Int -> ListBuilds -> ShowS
Prelude.Show, forall x. Rep ListBuilds x -> ListBuilds
forall x. ListBuilds -> Rep ListBuilds x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBuilds x -> ListBuilds
$cfrom :: forall x. ListBuilds -> Rep ListBuilds x
Prelude.Generic)

-- |
-- Create a value of 'ListBuilds' 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:
--
-- 'nextToken', 'listBuilds_nextToken' - During a previous call, if there are more than 100 items in the list,
-- only the first 100 items are returned, along with a unique string called
-- a /nextToken/. To get the next batch of items in the list, call this
-- operation again, adding the next token to the call. To get all of the
-- items in the list, keep calling this operation with each subsequent next
-- token that is returned, until no more next tokens are returned.
--
-- 'sortOrder', 'listBuilds_sortOrder' - The order to list build IDs. Valid values include:
--
-- -   @ASCENDING@: List the build IDs in ascending order by build ID.
--
-- -   @DESCENDING@: List the build IDs in descending order by build ID.
newListBuilds ::
  ListBuilds
newListBuilds :: ListBuilds
newListBuilds =
  ListBuilds'
    { $sel:nextToken:ListBuilds' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:sortOrder:ListBuilds' :: Maybe SortOrderType
sortOrder = forall a. Maybe a
Prelude.Nothing
    }

-- | During a previous call, if there are more than 100 items in the list,
-- only the first 100 items are returned, along with a unique string called
-- a /nextToken/. To get the next batch of items in the list, call this
-- operation again, adding the next token to the call. To get all of the
-- items in the list, keep calling this operation with each subsequent next
-- token that is returned, until no more next tokens are returned.
listBuilds_nextToken :: Lens.Lens' ListBuilds (Prelude.Maybe Prelude.Text)
listBuilds_nextToken :: Lens' ListBuilds (Maybe Text)
listBuilds_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBuilds' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListBuilds' :: ListBuilds -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListBuilds
s@ListBuilds' {} Maybe Text
a -> ListBuilds
s {$sel:nextToken:ListBuilds' :: Maybe Text
nextToken = Maybe Text
a} :: ListBuilds)

-- | The order to list build IDs. Valid values include:
--
-- -   @ASCENDING@: List the build IDs in ascending order by build ID.
--
-- -   @DESCENDING@: List the build IDs in descending order by build ID.
listBuilds_sortOrder :: Lens.Lens' ListBuilds (Prelude.Maybe SortOrderType)
listBuilds_sortOrder :: Lens' ListBuilds (Maybe SortOrderType)
listBuilds_sortOrder = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBuilds' {Maybe SortOrderType
sortOrder :: Maybe SortOrderType
$sel:sortOrder:ListBuilds' :: ListBuilds -> Maybe SortOrderType
sortOrder} -> Maybe SortOrderType
sortOrder) (\s :: ListBuilds
s@ListBuilds' {} Maybe SortOrderType
a -> ListBuilds
s {$sel:sortOrder:ListBuilds' :: Maybe SortOrderType
sortOrder = Maybe SortOrderType
a} :: ListBuilds)

instance Core.AWSPager ListBuilds where
  page :: ListBuilds -> AWSResponse ListBuilds -> Maybe ListBuilds
page ListBuilds
rq AWSResponse ListBuilds
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListBuilds
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBuildsResponse (Maybe Text)
listBuildsResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListBuilds
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBuildsResponse (Maybe (NonEmpty Text))
listBuildsResponse_ids
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to forall l. IsList l => l -> [Item l]
Prelude.toList
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListBuilds
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListBuilds (Maybe Text)
listBuilds_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListBuilds
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListBuildsResponse (Maybe Text)
listBuildsResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListBuilds where
  type AWSResponse ListBuilds = ListBuildsResponse
  request :: (Service -> Service) -> ListBuilds -> Request ListBuilds
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 ListBuilds
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListBuilds)))
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 (NonEmpty Text) -> Maybe Text -> Int -> ListBuildsResponse
ListBuildsResponse'
            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
"ids")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"nextToken")
            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 ListBuilds where
  hashWithSalt :: Int -> ListBuilds -> Int
hashWithSalt Int
_salt ListBuilds' {Maybe Text
Maybe SortOrderType
sortOrder :: Maybe SortOrderType
nextToken :: Maybe Text
$sel:sortOrder:ListBuilds' :: ListBuilds -> Maybe SortOrderType
$sel:nextToken:ListBuilds' :: ListBuilds -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SortOrderType
sortOrder

instance Prelude.NFData ListBuilds where
  rnf :: ListBuilds -> ()
rnf ListBuilds' {Maybe Text
Maybe SortOrderType
sortOrder :: Maybe SortOrderType
nextToken :: Maybe Text
$sel:sortOrder:ListBuilds' :: ListBuilds -> Maybe SortOrderType
$sel:nextToken:ListBuilds' :: ListBuilds -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SortOrderType
sortOrder

instance Data.ToHeaders ListBuilds where
  toHeaders :: ListBuilds -> 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
"CodeBuild_20161006.ListBuilds" ::
                          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 ListBuilds where
  toJSON :: ListBuilds -> Value
toJSON ListBuilds' {Maybe Text
Maybe SortOrderType
sortOrder :: Maybe SortOrderType
nextToken :: Maybe Text
$sel:sortOrder:ListBuilds' :: ListBuilds -> Maybe SortOrderType
$sel:nextToken:ListBuilds' :: ListBuilds -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"nextToken" 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 Text
nextToken,
            (Key
"sortOrder" 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 SortOrderType
sortOrder
          ]
      )

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

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

-- | /See:/ 'newListBuildsResponse' smart constructor.
data ListBuildsResponse = ListBuildsResponse'
  { -- | A list of build IDs, with each build ID representing a single build.
    ListBuildsResponse -> Maybe (NonEmpty Text)
ids :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | If there are more than 100 items in the list, only the first 100 items
    -- are returned, along with a unique string called a /nextToken/. To get
    -- the next batch of items in the list, call this operation again, adding
    -- the next token to the call.
    ListBuildsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListBuildsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListBuildsResponse -> ListBuildsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBuildsResponse -> ListBuildsResponse -> Bool
$c/= :: ListBuildsResponse -> ListBuildsResponse -> Bool
== :: ListBuildsResponse -> ListBuildsResponse -> Bool
$c== :: ListBuildsResponse -> ListBuildsResponse -> Bool
Prelude.Eq, ReadPrec [ListBuildsResponse]
ReadPrec ListBuildsResponse
Int -> ReadS ListBuildsResponse
ReadS [ListBuildsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBuildsResponse]
$creadListPrec :: ReadPrec [ListBuildsResponse]
readPrec :: ReadPrec ListBuildsResponse
$creadPrec :: ReadPrec ListBuildsResponse
readList :: ReadS [ListBuildsResponse]
$creadList :: ReadS [ListBuildsResponse]
readsPrec :: Int -> ReadS ListBuildsResponse
$creadsPrec :: Int -> ReadS ListBuildsResponse
Prelude.Read, Int -> ListBuildsResponse -> ShowS
[ListBuildsResponse] -> ShowS
ListBuildsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBuildsResponse] -> ShowS
$cshowList :: [ListBuildsResponse] -> ShowS
show :: ListBuildsResponse -> String
$cshow :: ListBuildsResponse -> String
showsPrec :: Int -> ListBuildsResponse -> ShowS
$cshowsPrec :: Int -> ListBuildsResponse -> ShowS
Prelude.Show, forall x. Rep ListBuildsResponse x -> ListBuildsResponse
forall x. ListBuildsResponse -> Rep ListBuildsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBuildsResponse x -> ListBuildsResponse
$cfrom :: forall x. ListBuildsResponse -> Rep ListBuildsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListBuildsResponse' 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:
--
-- 'ids', 'listBuildsResponse_ids' - A list of build IDs, with each build ID representing a single build.
--
-- 'nextToken', 'listBuildsResponse_nextToken' - If there are more than 100 items in the list, only the first 100 items
-- are returned, along with a unique string called a /nextToken/. To get
-- the next batch of items in the list, call this operation again, adding
-- the next token to the call.
--
-- 'httpStatus', 'listBuildsResponse_httpStatus' - The response's http status code.
newListBuildsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListBuildsResponse
newListBuildsResponse :: Int -> ListBuildsResponse
newListBuildsResponse Int
pHttpStatus_ =
  ListBuildsResponse'
    { $sel:ids:ListBuildsResponse' :: Maybe (NonEmpty Text)
ids = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListBuildsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListBuildsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of build IDs, with each build ID representing a single build.
listBuildsResponse_ids :: Lens.Lens' ListBuildsResponse (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
listBuildsResponse_ids :: Lens' ListBuildsResponse (Maybe (NonEmpty Text))
listBuildsResponse_ids = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBuildsResponse' {Maybe (NonEmpty Text)
ids :: Maybe (NonEmpty Text)
$sel:ids:ListBuildsResponse' :: ListBuildsResponse -> Maybe (NonEmpty Text)
ids} -> Maybe (NonEmpty Text)
ids) (\s :: ListBuildsResponse
s@ListBuildsResponse' {} Maybe (NonEmpty Text)
a -> ListBuildsResponse
s {$sel:ids:ListBuildsResponse' :: Maybe (NonEmpty Text)
ids = Maybe (NonEmpty Text)
a} :: ListBuildsResponse) 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

-- | If there are more than 100 items in the list, only the first 100 items
-- are returned, along with a unique string called a /nextToken/. To get
-- the next batch of items in the list, call this operation again, adding
-- the next token to the call.
listBuildsResponse_nextToken :: Lens.Lens' ListBuildsResponse (Prelude.Maybe Prelude.Text)
listBuildsResponse_nextToken :: Lens' ListBuildsResponse (Maybe Text)
listBuildsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBuildsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListBuildsResponse' :: ListBuildsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListBuildsResponse
s@ListBuildsResponse' {} Maybe Text
a -> ListBuildsResponse
s {$sel:nextToken:ListBuildsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListBuildsResponse)

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

instance Prelude.NFData ListBuildsResponse where
  rnf :: ListBuildsResponse -> ()
rnf ListBuildsResponse' {Int
Maybe (NonEmpty Text)
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
ids :: Maybe (NonEmpty Text)
$sel:httpStatus:ListBuildsResponse' :: ListBuildsResponse -> Int
$sel:nextToken:ListBuildsResponse' :: ListBuildsResponse -> Maybe Text
$sel:ids:ListBuildsResponse' :: ListBuildsResponse -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
ids
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus