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

    -- * Request Lenses
    listThemes_maxResults,
    listThemes_nextToken,
    listThemes_appId,
    listThemes_environmentName,

    -- * Destructuring the Response
    ListThemesResponse (..),
    newListThemesResponse,

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

-- |
-- Create a value of 'ListThemes' 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', 'listThemes_maxResults' - The maximum number of theme results to return in the response.
--
-- 'nextToken', 'listThemes_nextToken' - The token to request the next page of results.
--
-- 'appId', 'listThemes_appId' - The unique ID for the Amplify app.
--
-- 'environmentName', 'listThemes_environmentName' - The name of the backend environment that is a part of the Amplify app.
newListThemes ::
  -- | 'appId'
  Prelude.Text ->
  -- | 'environmentName'
  Prelude.Text ->
  ListThemes
newListThemes :: Text -> Text -> ListThemes
newListThemes Text
pAppId_ Text
pEnvironmentName_ =
  ListThemes'
    { $sel:maxResults:ListThemes' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListThemes' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:appId:ListThemes' :: Text
appId = Text
pAppId_,
      $sel:environmentName:ListThemes' :: Text
environmentName = Text
pEnvironmentName_
    }

-- | The maximum number of theme results to return in the response.
listThemes_maxResults :: Lens.Lens' ListThemes (Prelude.Maybe Prelude.Natural)
listThemes_maxResults :: Lens' ListThemes (Maybe Natural)
listThemes_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListThemes' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListThemes' :: ListThemes -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListThemes
s@ListThemes' {} Maybe Natural
a -> ListThemes
s {$sel:maxResults:ListThemes' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListThemes)

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

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

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

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

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

-- |
-- Create a value of 'ListThemesResponse' 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', 'listThemesResponse_nextToken' - The pagination token that\'s returned if more results are available.
--
-- 'httpStatus', 'listThemesResponse_httpStatus' - The response's http status code.
--
-- 'entities', 'listThemesResponse_entities' - The list of themes for the Amplify app.
newListThemesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListThemesResponse
newListThemesResponse :: Int -> ListThemesResponse
newListThemesResponse Int
pHttpStatus_ =
  ListThemesResponse'
    { $sel:nextToken:ListThemesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListThemesResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:entities:ListThemesResponse' :: [ThemeSummary]
entities = forall a. Monoid a => a
Prelude.mempty
    }

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

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

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