{-# 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.AMP.ListWorkspaces
-- 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 all AMP workspaces, including workspaces being created or deleted.
--
-- This operation returns paginated results.
module Amazonka.AMP.ListWorkspaces
  ( -- * Creating a Request
    ListWorkspaces (..),
    newListWorkspaces,

    -- * Request Lenses
    listWorkspaces_alias,
    listWorkspaces_maxResults,
    listWorkspaces_nextToken,

    -- * Destructuring the Response
    ListWorkspacesResponse (..),
    newListWorkspacesResponse,

    -- * Response Lenses
    listWorkspacesResponse_nextToken,
    listWorkspacesResponse_httpStatus,
    listWorkspacesResponse_workspaces,
  )
where

import Amazonka.AMP.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 ListWorkspaces operation.
--
-- /See:/ 'newListWorkspaces' smart constructor.
data ListWorkspaces = ListWorkspaces'
  { -- | Optional filter for workspace alias. Only the workspaces with aliases
    -- that begin with this value will be returned.
    ListWorkspaces -> Maybe Text
alias :: Prelude.Maybe Prelude.Text,
    -- | Maximum results to return in response (default=100, maximum=1000).
    ListWorkspaces -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | Pagination token to request the next page in a paginated list. This
    -- token is obtained from the output of the previous ListWorkspaces
    -- request.
    ListWorkspaces -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListWorkspaces -> ListWorkspaces -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListWorkspaces -> ListWorkspaces -> Bool
$c/= :: ListWorkspaces -> ListWorkspaces -> Bool
== :: ListWorkspaces -> ListWorkspaces -> Bool
$c== :: ListWorkspaces -> ListWorkspaces -> Bool
Prelude.Eq, ReadPrec [ListWorkspaces]
ReadPrec ListWorkspaces
Int -> ReadS ListWorkspaces
ReadS [ListWorkspaces]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListWorkspaces]
$creadListPrec :: ReadPrec [ListWorkspaces]
readPrec :: ReadPrec ListWorkspaces
$creadPrec :: ReadPrec ListWorkspaces
readList :: ReadS [ListWorkspaces]
$creadList :: ReadS [ListWorkspaces]
readsPrec :: Int -> ReadS ListWorkspaces
$creadsPrec :: Int -> ReadS ListWorkspaces
Prelude.Read, Int -> ListWorkspaces -> ShowS
[ListWorkspaces] -> ShowS
ListWorkspaces -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListWorkspaces] -> ShowS
$cshowList :: [ListWorkspaces] -> ShowS
show :: ListWorkspaces -> String
$cshow :: ListWorkspaces -> String
showsPrec :: Int -> ListWorkspaces -> ShowS
$cshowsPrec :: Int -> ListWorkspaces -> ShowS
Prelude.Show, forall x. Rep ListWorkspaces x -> ListWorkspaces
forall x. ListWorkspaces -> Rep ListWorkspaces x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListWorkspaces x -> ListWorkspaces
$cfrom :: forall x. ListWorkspaces -> Rep ListWorkspaces x
Prelude.Generic)

-- |
-- Create a value of 'ListWorkspaces' 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:
--
-- 'alias', 'listWorkspaces_alias' - Optional filter for workspace alias. Only the workspaces with aliases
-- that begin with this value will be returned.
--
-- 'maxResults', 'listWorkspaces_maxResults' - Maximum results to return in response (default=100, maximum=1000).
--
-- 'nextToken', 'listWorkspaces_nextToken' - Pagination token to request the next page in a paginated list. This
-- token is obtained from the output of the previous ListWorkspaces
-- request.
newListWorkspaces ::
  ListWorkspaces
newListWorkspaces :: ListWorkspaces
newListWorkspaces =
  ListWorkspaces'
    { $sel:alias:ListWorkspaces' :: Maybe Text
alias = forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListWorkspaces' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListWorkspaces' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | Optional filter for workspace alias. Only the workspaces with aliases
-- that begin with this value will be returned.
listWorkspaces_alias :: Lens.Lens' ListWorkspaces (Prelude.Maybe Prelude.Text)
listWorkspaces_alias :: Lens' ListWorkspaces (Maybe Text)
listWorkspaces_alias = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWorkspaces' {Maybe Text
alias :: Maybe Text
$sel:alias:ListWorkspaces' :: ListWorkspaces -> Maybe Text
alias} -> Maybe Text
alias) (\s :: ListWorkspaces
s@ListWorkspaces' {} Maybe Text
a -> ListWorkspaces
s {$sel:alias:ListWorkspaces' :: Maybe Text
alias = Maybe Text
a} :: ListWorkspaces)

-- | Maximum results to return in response (default=100, maximum=1000).
listWorkspaces_maxResults :: Lens.Lens' ListWorkspaces (Prelude.Maybe Prelude.Natural)
listWorkspaces_maxResults :: Lens' ListWorkspaces (Maybe Natural)
listWorkspaces_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWorkspaces' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListWorkspaces' :: ListWorkspaces -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListWorkspaces
s@ListWorkspaces' {} Maybe Natural
a -> ListWorkspaces
s {$sel:maxResults:ListWorkspaces' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListWorkspaces)

-- | Pagination token to request the next page in a paginated list. This
-- token is obtained from the output of the previous ListWorkspaces
-- request.
listWorkspaces_nextToken :: Lens.Lens' ListWorkspaces (Prelude.Maybe Prelude.Text)
listWorkspaces_nextToken :: Lens' ListWorkspaces (Maybe Text)
listWorkspaces_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWorkspaces' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListWorkspaces' :: ListWorkspaces -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListWorkspaces
s@ListWorkspaces' {} Maybe Text
a -> ListWorkspaces
s {$sel:nextToken:ListWorkspaces' :: Maybe Text
nextToken = Maybe Text
a} :: ListWorkspaces)

instance Core.AWSPager ListWorkspaces where
  page :: ListWorkspaces
-> AWSResponse ListWorkspaces -> Maybe ListWorkspaces
page ListWorkspaces
rq AWSResponse ListWorkspaces
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListWorkspaces
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListWorkspacesResponse (Maybe Text)
listWorkspacesResponse_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 ListWorkspaces
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListWorkspacesResponse [WorkspaceSummary]
listWorkspacesResponse_workspaces) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListWorkspaces
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListWorkspaces (Maybe Text)
listWorkspaces_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListWorkspaces
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListWorkspacesResponse (Maybe Text)
listWorkspacesResponse_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 ListWorkspaces where
  type
    AWSResponse ListWorkspaces =
      ListWorkspacesResponse
  request :: (Service -> Service) -> ListWorkspaces -> Request ListWorkspaces
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 ListWorkspaces
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListWorkspaces)))
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 -> Int -> [WorkspaceSummary] -> ListWorkspacesResponse
ListWorkspacesResponse'
            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
"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))
            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
"workspaces" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ListWorkspaces where
  hashWithSalt :: Int -> ListWorkspaces -> Int
hashWithSalt Int
_salt ListWorkspaces' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
alias :: Maybe Text
$sel:nextToken:ListWorkspaces' :: ListWorkspaces -> Maybe Text
$sel:maxResults:ListWorkspaces' :: ListWorkspaces -> Maybe Natural
$sel:alias:ListWorkspaces' :: ListWorkspaces -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
alias
      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 ListWorkspaces where
  rnf :: ListWorkspaces -> ()
rnf ListWorkspaces' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
alias :: Maybe Text
$sel:nextToken:ListWorkspaces' :: ListWorkspaces -> Maybe Text
$sel:maxResults:ListWorkspaces' :: ListWorkspaces -> Maybe Natural
$sel:alias:ListWorkspaces' :: ListWorkspaces -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
alias
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 ListWorkspaces where
  toHeaders :: ListWorkspaces -> 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 ListWorkspaces where
  toPath :: ListWorkspaces -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/workspaces"

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

-- | Represents the output of a ListWorkspaces operation.
--
-- /See:/ 'newListWorkspacesResponse' smart constructor.
data ListWorkspacesResponse = ListWorkspacesResponse'
  { -- | Pagination token to use when requesting the next page in this list.
    ListWorkspacesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListWorkspacesResponse -> Int
httpStatus :: Prelude.Int,
    -- | The list of existing workspaces, including those undergoing creation or
    -- deletion.
    ListWorkspacesResponse -> [WorkspaceSummary]
workspaces :: [WorkspaceSummary]
  }
  deriving (ListWorkspacesResponse -> ListWorkspacesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListWorkspacesResponse -> ListWorkspacesResponse -> Bool
$c/= :: ListWorkspacesResponse -> ListWorkspacesResponse -> Bool
== :: ListWorkspacesResponse -> ListWorkspacesResponse -> Bool
$c== :: ListWorkspacesResponse -> ListWorkspacesResponse -> Bool
Prelude.Eq, ReadPrec [ListWorkspacesResponse]
ReadPrec ListWorkspacesResponse
Int -> ReadS ListWorkspacesResponse
ReadS [ListWorkspacesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListWorkspacesResponse]
$creadListPrec :: ReadPrec [ListWorkspacesResponse]
readPrec :: ReadPrec ListWorkspacesResponse
$creadPrec :: ReadPrec ListWorkspacesResponse
readList :: ReadS [ListWorkspacesResponse]
$creadList :: ReadS [ListWorkspacesResponse]
readsPrec :: Int -> ReadS ListWorkspacesResponse
$creadsPrec :: Int -> ReadS ListWorkspacesResponse
Prelude.Read, Int -> ListWorkspacesResponse -> ShowS
[ListWorkspacesResponse] -> ShowS
ListWorkspacesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListWorkspacesResponse] -> ShowS
$cshowList :: [ListWorkspacesResponse] -> ShowS
show :: ListWorkspacesResponse -> String
$cshow :: ListWorkspacesResponse -> String
showsPrec :: Int -> ListWorkspacesResponse -> ShowS
$cshowsPrec :: Int -> ListWorkspacesResponse -> ShowS
Prelude.Show, forall x. Rep ListWorkspacesResponse x -> ListWorkspacesResponse
forall x. ListWorkspacesResponse -> Rep ListWorkspacesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListWorkspacesResponse x -> ListWorkspacesResponse
$cfrom :: forall x. ListWorkspacesResponse -> Rep ListWorkspacesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListWorkspacesResponse' 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', 'listWorkspacesResponse_nextToken' - Pagination token to use when requesting the next page in this list.
--
-- 'httpStatus', 'listWorkspacesResponse_httpStatus' - The response's http status code.
--
-- 'workspaces', 'listWorkspacesResponse_workspaces' - The list of existing workspaces, including those undergoing creation or
-- deletion.
newListWorkspacesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListWorkspacesResponse
newListWorkspacesResponse :: Int -> ListWorkspacesResponse
newListWorkspacesResponse Int
pHttpStatus_ =
  ListWorkspacesResponse'
    { $sel:nextToken:ListWorkspacesResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListWorkspacesResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:workspaces:ListWorkspacesResponse' :: [WorkspaceSummary]
workspaces = forall a. Monoid a => a
Prelude.mempty
    }

-- | Pagination token to use when requesting the next page in this list.
listWorkspacesResponse_nextToken :: Lens.Lens' ListWorkspacesResponse (Prelude.Maybe Prelude.Text)
listWorkspacesResponse_nextToken :: Lens' ListWorkspacesResponse (Maybe Text)
listWorkspacesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWorkspacesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListWorkspacesResponse' :: ListWorkspacesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListWorkspacesResponse
s@ListWorkspacesResponse' {} Maybe Text
a -> ListWorkspacesResponse
s {$sel:nextToken:ListWorkspacesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListWorkspacesResponse)

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

-- | The list of existing workspaces, including those undergoing creation or
-- deletion.
listWorkspacesResponse_workspaces :: Lens.Lens' ListWorkspacesResponse [WorkspaceSummary]
listWorkspacesResponse_workspaces :: Lens' ListWorkspacesResponse [WorkspaceSummary]
listWorkspacesResponse_workspaces = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListWorkspacesResponse' {[WorkspaceSummary]
workspaces :: [WorkspaceSummary]
$sel:workspaces:ListWorkspacesResponse' :: ListWorkspacesResponse -> [WorkspaceSummary]
workspaces} -> [WorkspaceSummary]
workspaces) (\s :: ListWorkspacesResponse
s@ListWorkspacesResponse' {} [WorkspaceSummary]
a -> ListWorkspacesResponse
s {$sel:workspaces:ListWorkspacesResponse' :: [WorkspaceSummary]
workspaces = [WorkspaceSummary]
a} :: ListWorkspacesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData ListWorkspacesResponse where
  rnf :: ListWorkspacesResponse -> ()
rnf ListWorkspacesResponse' {Int
[WorkspaceSummary]
Maybe Text
workspaces :: [WorkspaceSummary]
httpStatus :: Int
nextToken :: Maybe Text
$sel:workspaces:ListWorkspacesResponse' :: ListWorkspacesResponse -> [WorkspaceSummary]
$sel:httpStatus:ListWorkspacesResponse' :: ListWorkspacesResponse -> Int
$sel:nextToken:ListWorkspacesResponse' :: ListWorkspacesResponse -> 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 Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [WorkspaceSummary]
workspaces