{-# 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.ListForms
-- 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 forms for a specified Amplify app and backend
-- environment.
--
-- This operation returns paginated results.
module Amazonka.AmplifyUiBuilder.ListForms
  ( -- * Creating a Request
    ListForms (..),
    newListForms,

    -- * Request Lenses
    listForms_maxResults,
    listForms_nextToken,
    listForms_appId,
    listForms_environmentName,

    -- * Destructuring the Response
    ListFormsResponse (..),
    newListFormsResponse,

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

-- |
-- Create a value of 'ListForms' 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', 'listForms_maxResults' - The maximum number of forms to retrieve.
--
-- 'nextToken', 'listForms_nextToken' - The token to request the next page of results.
--
-- 'appId', 'listForms_appId' - The unique ID for the Amplify app.
--
-- 'environmentName', 'listForms_environmentName' - The name of the backend environment that is a part of the Amplify app.
newListForms ::
  -- | 'appId'
  Prelude.Text ->
  -- | 'environmentName'
  Prelude.Text ->
  ListForms
newListForms :: Text -> Text -> ListForms
newListForms Text
pAppId_ Text
pEnvironmentName_ =
  ListForms'
    { $sel:maxResults:ListForms' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListForms' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:appId:ListForms' :: Text
appId = Text
pAppId_,
      $sel:environmentName:ListForms' :: Text
environmentName = Text
pEnvironmentName_
    }

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

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

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

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

instance Core.AWSPager ListForms where
  page :: ListForms -> AWSResponse ListForms -> Maybe ListForms
page ListForms
rq AWSResponse ListForms
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListForms
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFormsResponse (Maybe Text)
listFormsResponse_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 ListForms
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListFormsResponse [FormSummary]
listFormsResponse_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.$ ListForms
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListForms (Maybe Text)
listForms_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListForms
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFormsResponse (Maybe Text)
listFormsResponse_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 ListForms where
  type AWSResponse ListForms = ListFormsResponse
  request :: (Service -> Service) -> ListForms -> Request ListForms
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 ListForms
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListForms)))
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 -> [FormSummary] -> ListFormsResponse
ListFormsResponse'
            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 ListForms where
  hashWithSalt :: Int -> ListForms -> Int
hashWithSalt Int
_salt ListForms' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListForms' :: ListForms -> Text
$sel:appId:ListForms' :: ListForms -> Text
$sel:nextToken:ListForms' :: ListForms -> Maybe Text
$sel:maxResults:ListForms' :: ListForms -> 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 ListForms where
  rnf :: ListForms -> ()
rnf ListForms' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListForms' :: ListForms -> Text
$sel:appId:ListForms' :: ListForms -> Text
$sel:nextToken:ListForms' :: ListForms -> Maybe Text
$sel:maxResults:ListForms' :: ListForms -> 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 ListForms where
  toHeaders :: ListForms -> 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 ListForms where
  toPath :: ListForms -> ByteString
toPath ListForms' {Maybe Natural
Maybe Text
Text
environmentName :: Text
appId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentName:ListForms' :: ListForms -> Text
$sel:appId:ListForms' :: ListForms -> Text
$sel:nextToken:ListForms' :: ListForms -> Maybe Text
$sel:maxResults:ListForms' :: ListForms -> 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
"/forms"
      ]

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

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

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

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

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