{-# 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.MigrationHubReFactorSpaces.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)
--
-- Lists Amazon Web Services Migration Hub Refactor Spaces environments
-- owned by a caller account or shared with the caller account.
--
-- This operation returns paginated results.
module Amazonka.MigrationHubReFactorSpaces.ListEnvironments
  ( -- * Creating a Request
    ListEnvironments (..),
    newListEnvironments,

    -- * Request Lenses
    listEnvironments_maxResults,
    listEnvironments_nextToken,

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

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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MigrationHubReFactorSpaces.Types
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 results to return with a single call. To retrieve
    -- the remaining results, make another call with the returned @nextToken@
    -- value.
    ListEnvironments -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token for the next page of results.
    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 results to return with a single call. To retrieve
-- the remaining results, make another call with the returned @nextToken@
-- value.
--
-- 'nextToken', 'listEnvironments_nextToken' - The token for the next page of results.
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 results to return with a single call. To retrieve
-- the remaining results, make another call with the returned @nextToken@
-- value.
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)

-- | The token for the next page of results.
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 [EnvironmentSummary])
listEnvironmentsResponse_environmentSummaryList
            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 => Service -> a -> Request a
Request.get (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 [EnvironmentSummary]
-> 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
"EnvironmentSummaryList"
                            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
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

instance Data.ToQuery ListEnvironments where
  toQuery :: ListEnvironments -> QueryString
toQuery 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. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | /See:/ 'newListEnvironmentsResponse' smart constructor.
data ListEnvironmentsResponse = ListEnvironmentsResponse'
  { -- | The list of @EnvironmentSummary@ objects.
    ListEnvironmentsResponse -> Maybe [EnvironmentSummary]
environmentSummaryList :: Prelude.Maybe [EnvironmentSummary],
    -- | The token for the next page of results.
    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, 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:
--
-- 'environmentSummaryList', 'listEnvironmentsResponse_environmentSummaryList' - The list of @EnvironmentSummary@ objects.
--
-- 'nextToken', 'listEnvironmentsResponse_nextToken' - The token for the next page of results.
--
-- 'httpStatus', 'listEnvironmentsResponse_httpStatus' - The response's http status code.
newListEnvironmentsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListEnvironmentsResponse
newListEnvironmentsResponse :: Int -> ListEnvironmentsResponse
newListEnvironmentsResponse Int
pHttpStatus_ =
  ListEnvironmentsResponse'
    { $sel:environmentSummaryList:ListEnvironmentsResponse' :: Maybe [EnvironmentSummary]
environmentSummaryList =
        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 @EnvironmentSummary@ objects.
listEnvironmentsResponse_environmentSummaryList :: Lens.Lens' ListEnvironmentsResponse (Prelude.Maybe [EnvironmentSummary])
listEnvironmentsResponse_environmentSummaryList :: Lens' ListEnvironmentsResponse (Maybe [EnvironmentSummary])
listEnvironmentsResponse_environmentSummaryList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEnvironmentsResponse' {Maybe [EnvironmentSummary]
environmentSummaryList :: Maybe [EnvironmentSummary]
$sel:environmentSummaryList:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe [EnvironmentSummary]
environmentSummaryList} -> Maybe [EnvironmentSummary]
environmentSummaryList) (\s :: ListEnvironmentsResponse
s@ListEnvironmentsResponse' {} Maybe [EnvironmentSummary]
a -> ListEnvironmentsResponse
s {$sel:environmentSummaryList:ListEnvironmentsResponse' :: Maybe [EnvironmentSummary]
environmentSummaryList = Maybe [EnvironmentSummary]
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

-- | The token for the next page of results.
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 [EnvironmentSummary]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
environmentSummaryList :: Maybe [EnvironmentSummary]
$sel:httpStatus:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Int
$sel:nextToken:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe Text
$sel:environmentSummaryList:ListEnvironmentsResponse' :: ListEnvironmentsResponse -> Maybe [EnvironmentSummary]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [EnvironmentSummary]
environmentSummaryList
      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