{-# 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.AmplifyUiBuilder.ListComponents
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves a list of components for a specified Amplify app and backend
-- environment.
--
-- This operation returns paginated results.
module Amazonka.AmplifyUiBuilder.ListComponents
  ( -- * Creating a Request
    ListComponents (..),
    newListComponents,

    -- * Request Lenses
    listComponents_maxResults,
    listComponents_nextToken,
    listComponents_appId,
    listComponents_environmentName,

    -- * Destructuring the Response
    ListComponentsResponse (..),
    newListComponentsResponse,

    -- * Response Lenses
    listComponentsResponse_nextToken,
    listComponentsResponse_httpStatus,
    listComponentsResponse_entities,
  )
where

import Amazonka.AmplifyUiBuilder.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:/ 'newListComponents' smart constructor.
data ListComponents = ListComponents'
  { -- | The maximum number of components to retrieve.
    ListComponents -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token to request the next page of results.
    ListComponents -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The unique ID for the Amplify app.
    ListComponents -> Text
appId :: Prelude.Text,
    -- | The name of the backend environment that is a part of the Amplify app.
    ListComponents -> Text
environmentName :: Prelude.Text
  }
  deriving (ListComponents -> ListComponents -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListComponents -> ListComponents -> Bool
$c/= :: ListComponents -> ListComponents -> Bool
== :: ListComponents -> ListComponents -> Bool
$c== :: ListComponents -> ListComponents -> Bool
Prelude.Eq, ReadPrec [ListComponents]
ReadPrec ListComponents
Int -> ReadS ListComponents
ReadS [ListComponents]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListComponents]
$creadListPrec :: ReadPrec [ListComponents]
readPrec :: ReadPrec ListComponents
$creadPrec :: ReadPrec ListComponents
readList :: ReadS [ListComponents]
$creadList :: ReadS [ListComponents]
readsPrec :: Int -> ReadS ListComponents
$creadsPrec :: Int -> ReadS ListComponents
Prelude.Read, Int -> ListComponents -> ShowS
[ListComponents] -> ShowS
ListComponents -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListComponents] -> ShowS
$cshowList :: [ListComponents] -> ShowS
show :: ListComponents -> String
$cshow :: ListComponents -> String
showsPrec :: Int -> ListComponents -> ShowS
$cshowsPrec :: Int -> ListComponents -> ShowS
Prelude.Show, forall x. Rep ListComponents x -> ListComponents
forall x. ListComponents -> Rep ListComponents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListComponents x -> ListComponents
$cfrom :: forall x. ListComponents -> Rep ListComponents x
Prelude.Generic)

-- |
-- Create a value of 'ListComponents' 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', 'listComponents_maxResults' - The maximum number of components to retrieve.
--
-- 'nextToken', 'listComponents_nextToken' - The token to request the next page of results.
--
-- 'appId', 'listComponents_appId' - The unique ID for the Amplify app.
--
-- 'environmentName', 'listComponents_environmentName' - The name of the backend environment that is a part of the Amplify app.
newListComponents ::
  -- | 'appId'
  Prelude.Text ->
  -- | 'environmentName'
  Prelude.Text ->
  ListComponents
newListComponents :: Text -> Text -> ListComponents
newListComponents Text
pAppId_ Text
pEnvironmentName_ =
  ListComponents'
    { $sel:maxResults:ListComponents' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListComponents' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:appId:ListComponents' :: Text
appId = Text
pAppId_,
      $sel:environmentName:ListComponents' :: Text
environmentName = Text
pEnvironmentName_
    }

-- | The maximum number of components to retrieve.
listComponents_maxResults :: Lens.Lens' ListComponents (Prelude.Maybe Prelude.Natural)
listComponents_maxResults :: Lens' ListComponents (Maybe Natural)
listComponents_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListComponents' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListComponents' :: ListComponents -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListComponents
s@ListComponents' {} Maybe Natural
a -> ListComponents
s {$sel:maxResults:ListComponents' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListComponents)

-- | The token to request the next page of results.
listComponents_nextToken :: Lens.Lens' ListComponents (Prelude.Maybe Prelude.Text)
listComponents_nextToken :: Lens' ListComponents (Maybe Text)
listComponents_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListComponents' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListComponents' :: ListComponents -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListComponents
s@ListComponents' {} Maybe Text
a -> ListComponents
s {$sel:nextToken:ListComponents' :: Maybe Text
nextToken = Maybe Text
a} :: ListComponents)

-- | The unique ID for the Amplify app.
listComponents_appId :: Lens.Lens' ListComponents Prelude.Text
listComponents_appId :: Lens' ListComponents Text
listComponents_appId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListComponents' {Text
appId :: Text
$sel:appId:ListComponents' :: ListComponents -> Text
appId} -> Text
appId) (\s :: ListComponents
s@ListComponents' {} Text
a -> ListComponents
s {$sel:appId:ListComponents' :: Text
appId = Text
a} :: ListComponents)

-- | The name of the backend environment that is a part of the Amplify app.
listComponents_environmentName :: Lens.Lens' ListComponents Prelude.Text
listComponents_environmentName :: Lens' ListComponents Text
listComponents_environmentName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListComponents' {Text
environmentName :: Text
$sel:environmentName:ListComponents' :: ListComponents -> Text
environmentName} -> Text
environmentName) (\s :: ListComponents
s@ListComponents' {} Text
a -> ListComponents
s {$sel:environmentName:ListComponents' :: Text
environmentName = Text
a} :: ListComponents)

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

instance Prelude.Hashable ListComponents where
  hashWithSalt :: Int -> ListComponents -> Int
hashWithSalt Int
_salt ListComponents' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListComponents' :: ListComponents -> Text
$sel:appId:ListComponents' :: ListComponents -> Text
$sel:nextToken:ListComponents' :: ListComponents -> Maybe Text
$sel:maxResults:ListComponents' :: ListComponents -> 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
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
appId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
environmentName

instance Prelude.NFData ListComponents where
  rnf :: ListComponents -> ()
rnf ListComponents' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListComponents' :: ListComponents -> Text
$sel:appId:ListComponents' :: ListComponents -> Text
$sel:nextToken:ListComponents' :: ListComponents -> Maybe Text
$sel:maxResults:ListComponents' :: ListComponents -> 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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
appId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
environmentName

instance Data.ToHeaders ListComponents where
  toHeaders :: ListComponents -> 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 ListComponents where
  toPath :: ListComponents -> ByteString
toPath ListComponents' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListComponents' :: ListComponents -> Text
$sel:appId:ListComponents' :: ListComponents -> Text
$sel:nextToken:ListComponents' :: ListComponents -> Maybe Text
$sel:maxResults:ListComponents' :: ListComponents -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/app/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
appId,
        ByteString
"/environment/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
environmentName,
        ByteString
"/components"
      ]

instance Data.ToQuery ListComponents where
  toQuery :: ListComponents -> QueryString
toQuery ListComponents' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListComponents' :: ListComponents -> Text
$sel:appId:ListComponents' :: ListComponents -> Text
$sel:nextToken:ListComponents' :: ListComponents -> Maybe Text
$sel:maxResults:ListComponents' :: ListComponents -> 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:/ 'newListComponentsResponse' smart constructor.
data ListComponentsResponse = ListComponentsResponse'
  { -- | The pagination token that\'s included if more results are available.
    ListComponentsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListComponentsResponse -> Int
httpStatus :: Prelude.Int,
    -- | The list of components for the Amplify app.
    ListComponentsResponse -> [ComponentSummary]
entities :: [ComponentSummary]
  }
  deriving (ListComponentsResponse -> ListComponentsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListComponentsResponse -> ListComponentsResponse -> Bool
$c/= :: ListComponentsResponse -> ListComponentsResponse -> Bool
== :: ListComponentsResponse -> ListComponentsResponse -> Bool
$c== :: ListComponentsResponse -> ListComponentsResponse -> Bool
Prelude.Eq, ReadPrec [ListComponentsResponse]
ReadPrec ListComponentsResponse
Int -> ReadS ListComponentsResponse
ReadS [ListComponentsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListComponentsResponse]
$creadListPrec :: ReadPrec [ListComponentsResponse]
readPrec :: ReadPrec ListComponentsResponse
$creadPrec :: ReadPrec ListComponentsResponse
readList :: ReadS [ListComponentsResponse]
$creadList :: ReadS [ListComponentsResponse]
readsPrec :: Int -> ReadS ListComponentsResponse
$creadsPrec :: Int -> ReadS ListComponentsResponse
Prelude.Read, Int -> ListComponentsResponse -> ShowS
[ListComponentsResponse] -> ShowS
ListComponentsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListComponentsResponse] -> ShowS
$cshowList :: [ListComponentsResponse] -> ShowS
show :: ListComponentsResponse -> String
$cshow :: ListComponentsResponse -> String
showsPrec :: Int -> ListComponentsResponse -> ShowS
$cshowsPrec :: Int -> ListComponentsResponse -> ShowS
Prelude.Show, forall x. Rep ListComponentsResponse x -> ListComponentsResponse
forall x. ListComponentsResponse -> Rep ListComponentsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListComponentsResponse x -> ListComponentsResponse
$cfrom :: forall x. ListComponentsResponse -> Rep ListComponentsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListComponentsResponse' 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', 'listComponentsResponse_nextToken' - The pagination token that\'s included if more results are available.
--
-- 'httpStatus', 'listComponentsResponse_httpStatus' - The response's http status code.
--
-- 'entities', 'listComponentsResponse_entities' - The list of components for the Amplify app.
newListComponentsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListComponentsResponse
newListComponentsResponse :: Int -> ListComponentsResponse
newListComponentsResponse Int
pHttpStatus_ =
  ListComponentsResponse'
    { $sel:nextToken:ListComponentsResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListComponentsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:entities:ListComponentsResponse' :: [ComponentSummary]
entities = forall a. Monoid a => a
Prelude.mempty
    }

-- | The pagination token that\'s included if more results are available.
listComponentsResponse_nextToken :: Lens.Lens' ListComponentsResponse (Prelude.Maybe Prelude.Text)
listComponentsResponse_nextToken :: Lens' ListComponentsResponse (Maybe Text)
listComponentsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListComponentsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListComponentsResponse' :: ListComponentsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListComponentsResponse
s@ListComponentsResponse' {} Maybe Text
a -> ListComponentsResponse
s {$sel:nextToken:ListComponentsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListComponentsResponse)

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

-- | The list of components for the Amplify app.
listComponentsResponse_entities :: Lens.Lens' ListComponentsResponse [ComponentSummary]
listComponentsResponse_entities :: Lens' ListComponentsResponse [ComponentSummary]
listComponentsResponse_entities = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListComponentsResponse' {[ComponentSummary]
entities :: [ComponentSummary]
$sel:entities:ListComponentsResponse' :: ListComponentsResponse -> [ComponentSummary]
entities} -> [ComponentSummary]
entities) (\s :: ListComponentsResponse
s@ListComponentsResponse' {} [ComponentSummary]
a -> ListComponentsResponse
s {$sel:entities:ListComponentsResponse' :: [ComponentSummary]
entities = [ComponentSummary]
a} :: ListComponentsResponse) 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 ListComponentsResponse where
  rnf :: ListComponentsResponse -> ()
rnf ListComponentsResponse' {Int
[ComponentSummary]
Maybe Text
entities :: [ComponentSummary]
httpStatus :: Int
nextToken :: Maybe Text
$sel:entities:ListComponentsResponse' :: ListComponentsResponse -> [ComponentSummary]
$sel:httpStatus:ListComponentsResponse' :: ListComponentsResponse -> Int
$sel:nextToken:ListComponentsResponse' :: ListComponentsResponse -> 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 [ComponentSummary]
entities