{-# 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.Cloud9.ListEnvironments
-- 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 Cloud9 development environment identifiers.
--
-- This operation returns paginated results.
module Amazonka.Cloud9.ListEnvironments
  ( -- * Creating a Request
    ListEnvironments (..),
    newListEnvironments,

    -- * Request Lenses
    listEnvironments_maxResults,
    listEnvironments_nextToken,

    -- * Destructuring the Response
    ListEnvironmentsResponse (..),
    newListEnvironmentsResponse,

    -- * Response Lenses
    listEnvironmentsResponse_environmentIds,
    listEnvironmentsResponse_nextToken,
    listEnvironmentsResponse_httpStatus,
  )
where

import Amazonka.Cloud9.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:/ 'newListEnvironments' smart constructor.
data ListEnvironments = ListEnvironments'
  { -- | The maximum number of environments to get identifiers for.
    ListEnvironments -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | During a previous call, if there are more than 25 items in the list,
    -- only the first 25 items are returned, along with a unique string called
    -- a /next token/. 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.
    ListEnvironments -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListEnvironments -> ListEnvironments -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListEnvironments -> ListEnvironments -> Bool
$c/= :: ListEnvironments -> ListEnvironments -> Bool
== :: ListEnvironments -> ListEnvironments -> Bool
$c== :: ListEnvironments -> ListEnvironments -> Bool
Prelude.Eq, ReadPrec [ListEnvironments]
ReadPrec ListEnvironments
Int -> ReadS ListEnvironments
ReadS [ListEnvironments]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListEnvironments]
$creadListPrec :: ReadPrec [ListEnvironments]
readPrec :: ReadPrec ListEnvironments
$creadPrec :: ReadPrec ListEnvironments
readList :: ReadS [ListEnvironments]
$creadList :: ReadS [ListEnvironments]
readsPrec :: Int -> ReadS ListEnvironments
$creadsPrec :: Int -> ReadS ListEnvironments
Prelude.Read, Int -> ListEnvironments -> ShowS
[ListEnvironments] -> ShowS
ListEnvironments -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListEnvironments] -> ShowS
$cshowList :: [ListEnvironments] -> ShowS
show :: ListEnvironments -> String
$cshow :: ListEnvironments -> String
showsPrec :: Int -> ListEnvironments -> ShowS
$cshowsPrec :: Int -> ListEnvironments -> ShowS
Prelude.Show, forall x. Rep ListEnvironments x -> ListEnvironments
forall x. ListEnvironments -> Rep ListEnvironments x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListEnvironments x -> ListEnvironments
$cfrom :: forall x. ListEnvironments -> Rep ListEnvironments x
Prelude.Generic)

-- |
-- Create a value of 'ListEnvironments' 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:
--
-- 'maxResults', 'listEnvironments_maxResults' - The maximum number of environments to get identifiers for.
--
-- 'nextToken', 'listEnvironments_nextToken' - During a previous call, if there are more than 25 items in the list,
-- only the first 25 items are returned, along with a unique string called
-- a /next token/. 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.
newListEnvironments ::
  ListEnvironments
newListEnvironments :: ListEnvironments
newListEnvironments =
  ListEnvironments'
    { $sel:maxResults:ListEnvironments' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListEnvironments' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of environments to get identifiers for.
listEnvironments_maxResults :: Lens.Lens' ListEnvironments (Prelude.Maybe Prelude.Natural)
listEnvironments_maxResults :: Lens' ListEnvironments (Maybe Natural)
listEnvironments_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEnvironments' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListEnvironments' :: ListEnvironments -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListEnvironments
s@ListEnvironments' {} Maybe Natural
a -> ListEnvironments
s {$sel:maxResults:ListEnvironments' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListEnvironments)

-- | During a previous call, if there are more than 25 items in the list,
-- only the first 25 items are returned, along with a unique string called
-- a /next token/. 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.
listEnvironments_nextToken :: Lens.Lens' ListEnvironments (Prelude.Maybe Prelude.Text)
listEnvironments_nextToken :: Lens' ListEnvironments (Maybe Text)
listEnvironments_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEnvironments' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListEnvironments' :: ListEnvironments -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListEnvironments
s@ListEnvironments' {} Maybe Text
a -> ListEnvironments
s {$sel:nextToken:ListEnvironments' :: Maybe Text
nextToken = Maybe Text
a} :: ListEnvironments)

instance Core.AWSPager ListEnvironments where
  page :: ListEnvironments
-> AWSResponse ListEnvironments -> Maybe ListEnvironments
page ListEnvironments
rq AWSResponse ListEnvironments
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListEnvironments
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListEnvironmentsResponse (Maybe Text)
listEnvironmentsResponse_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 ListEnvironments
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListEnvironmentsResponse (Maybe [Text])
listEnvironmentsResponse_environmentIds
            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
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListEnvironments
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListEnvironments (Maybe Text)
listEnvironments_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListEnvironments
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListEnvironmentsResponse (Maybe Text)
listEnvironmentsResponse_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 ListEnvironments where
  type
    AWSResponse ListEnvironments =
      ListEnvironmentsResponse
  request :: (Service -> Service)
-> ListEnvironments -> Request ListEnvironments
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 ListEnvironments
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListEnvironments)))
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 [Text] -> Maybe Text -> Int -> ListEnvironmentsResponse
ListEnvironmentsResponse'
            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
"environmentIds" 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.<*> (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 ListEnvironments where
  hashWithSalt :: Int -> ListEnvironments -> Int
hashWithSalt Int
_salt ListEnvironments' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListEnvironments' :: ListEnvironments -> Maybe Text
$sel:maxResults:ListEnvironments' :: ListEnvironments -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

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

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

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

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

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

-- |
-- Create a value of 'ListEnvironmentsResponse' 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:
--
-- 'environmentIds', 'listEnvironmentsResponse_environmentIds' - The list of environment identifiers.
--
-- 'nextToken', 'listEnvironmentsResponse_nextToken' - If there are more than 25 items in the list, only the first 25 items are
-- returned, along with a unique string called a /next token/. To get the
-- next batch of items in the list, call this operation again, adding the
-- next token to the call.
--
-- 'httpStatus', 'listEnvironmentsResponse_httpStatus' - The response's http status code.
newListEnvironmentsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListEnvironmentsResponse
newListEnvironmentsResponse :: Int -> ListEnvironmentsResponse
newListEnvironmentsResponse Int
pHttpStatus_ =
  ListEnvironmentsResponse'
    { $sel:environmentIds:ListEnvironmentsResponse' :: Maybe [Text]
environmentIds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListEnvironmentsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListEnvironmentsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of environment identifiers.
listEnvironmentsResponse_environmentIds :: Lens.Lens' ListEnvironmentsResponse (Prelude.Maybe [Prelude.Text])
listEnvironmentsResponse_environmentIds :: Lens' ListEnvironmentsResponse (Maybe [Text])
listEnvironmentsResponse_environmentIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEnvironmentsResponse' {Maybe [Text]
environmentIds :: Maybe [Text]
$sel:environmentIds:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe [Text]
environmentIds} -> Maybe [Text]
environmentIds) (\s :: ListEnvironmentsResponse
s@ListEnvironmentsResponse' {} Maybe [Text]
a -> ListEnvironmentsResponse
s {$sel:environmentIds:ListEnvironmentsResponse' :: Maybe [Text]
environmentIds = Maybe [Text]
a} :: ListEnvironmentsResponse) 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 25 items in the list, only the first 25 items are
-- returned, along with a unique string called a /next token/. To get the
-- next batch of items in the list, call this operation again, adding the
-- next token to the call.
listEnvironmentsResponse_nextToken :: Lens.Lens' ListEnvironmentsResponse (Prelude.Maybe Prelude.Text)
listEnvironmentsResponse_nextToken :: Lens' ListEnvironmentsResponse (Maybe Text)
listEnvironmentsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEnvironmentsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListEnvironmentsResponse
s@ListEnvironmentsResponse' {} Maybe Text
a -> ListEnvironmentsResponse
s {$sel:nextToken:ListEnvironmentsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListEnvironmentsResponse)

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

instance Prelude.NFData ListEnvironmentsResponse where
  rnf :: ListEnvironmentsResponse -> ()
rnf ListEnvironmentsResponse' {Int
Maybe [Text]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
environmentIds :: Maybe [Text]
$sel:httpStatus:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Int
$sel:nextToken:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe Text
$sel:environmentIds:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
environmentIds
      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