{-# 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.IoTSiteWise.ListProjects
-- 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 paginated list of projects for an IoT SiteWise Monitor
-- portal.
--
-- This operation returns paginated results.
module Amazonka.IoTSiteWise.ListProjects
  ( -- * Creating a Request
    ListProjects (..),
    newListProjects,

    -- * Request Lenses
    listProjects_maxResults,
    listProjects_nextToken,
    listProjects_portalId,

    -- * Destructuring the Response
    ListProjectsResponse (..),
    newListProjectsResponse,

    -- * Response Lenses
    listProjectsResponse_nextToken,
    listProjectsResponse_httpStatus,
    listProjectsResponse_projectSummaries,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTSiteWise.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListProjects' smart constructor.
data ListProjects = ListProjects'
  { -- | The maximum number of results to return for each paginated request.
    --
    -- Default: 50
    ListProjects -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token to be used for the next set of paginated results.
    ListProjects -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The ID of the portal.
    ListProjects -> Text
portalId :: Prelude.Text
  }
  deriving (ListProjects -> ListProjects -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListProjects -> ListProjects -> Bool
$c/= :: ListProjects -> ListProjects -> Bool
== :: ListProjects -> ListProjects -> Bool
$c== :: ListProjects -> ListProjects -> Bool
Prelude.Eq, ReadPrec [ListProjects]
ReadPrec ListProjects
Int -> ReadS ListProjects
ReadS [ListProjects]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListProjects]
$creadListPrec :: ReadPrec [ListProjects]
readPrec :: ReadPrec ListProjects
$creadPrec :: ReadPrec ListProjects
readList :: ReadS [ListProjects]
$creadList :: ReadS [ListProjects]
readsPrec :: Int -> ReadS ListProjects
$creadsPrec :: Int -> ReadS ListProjects
Prelude.Read, Int -> ListProjects -> ShowS
[ListProjects] -> ShowS
ListProjects -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListProjects] -> ShowS
$cshowList :: [ListProjects] -> ShowS
show :: ListProjects -> String
$cshow :: ListProjects -> String
showsPrec :: Int -> ListProjects -> ShowS
$cshowsPrec :: Int -> ListProjects -> ShowS
Prelude.Show, forall x. Rep ListProjects x -> ListProjects
forall x. ListProjects -> Rep ListProjects x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListProjects x -> ListProjects
$cfrom :: forall x. ListProjects -> Rep ListProjects x
Prelude.Generic)

-- |
-- Create a value of 'ListProjects' 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', 'listProjects_maxResults' - The maximum number of results to return for each paginated request.
--
-- Default: 50
--
-- 'nextToken', 'listProjects_nextToken' - The token to be used for the next set of paginated results.
--
-- 'portalId', 'listProjects_portalId' - The ID of the portal.
newListProjects ::
  -- | 'portalId'
  Prelude.Text ->
  ListProjects
newListProjects :: Text -> ListProjects
newListProjects Text
pPortalId_ =
  ListProjects'
    { $sel:maxResults:ListProjects' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListProjects' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:portalId:ListProjects' :: Text
portalId = Text
pPortalId_
    }

-- | The maximum number of results to return for each paginated request.
--
-- Default: 50
listProjects_maxResults :: Lens.Lens' ListProjects (Prelude.Maybe Prelude.Natural)
listProjects_maxResults :: Lens' ListProjects (Maybe Natural)
listProjects_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProjects' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListProjects' :: ListProjects -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListProjects
s@ListProjects' {} Maybe Natural
a -> ListProjects
s {$sel:maxResults:ListProjects' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListProjects)

-- | The token to be used for the next set of paginated results.
listProjects_nextToken :: Lens.Lens' ListProjects (Prelude.Maybe Prelude.Text)
listProjects_nextToken :: Lens' ListProjects (Maybe Text)
listProjects_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProjects' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListProjects' :: ListProjects -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListProjects
s@ListProjects' {} Maybe Text
a -> ListProjects
s {$sel:nextToken:ListProjects' :: Maybe Text
nextToken = Maybe Text
a} :: ListProjects)

-- | The ID of the portal.
listProjects_portalId :: Lens.Lens' ListProjects Prelude.Text
listProjects_portalId :: Lens' ListProjects Text
listProjects_portalId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProjects' {Text
portalId :: Text
$sel:portalId:ListProjects' :: ListProjects -> Text
portalId} -> Text
portalId) (\s :: ListProjects
s@ListProjects' {} Text
a -> ListProjects
s {$sel:portalId:ListProjects' :: Text
portalId = Text
a} :: ListProjects)

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

instance Prelude.Hashable ListProjects where
  hashWithSalt :: Int -> ListProjects -> Int
hashWithSalt Int
_salt ListProjects' {Maybe Natural
Maybe Text
Text
portalId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:portalId:ListProjects' :: ListProjects -> Text
$sel:nextToken:ListProjects' :: ListProjects -> Maybe Text
$sel:maxResults:ListProjects' :: ListProjects -> 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
portalId

instance Prelude.NFData ListProjects where
  rnf :: ListProjects -> ()
rnf ListProjects' {Maybe Natural
Maybe Text
Text
portalId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:portalId:ListProjects' :: ListProjects -> Text
$sel:nextToken:ListProjects' :: ListProjects -> Maybe Text
$sel:maxResults:ListProjects' :: ListProjects -> 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
portalId

instance Data.ToHeaders ListProjects where
  toHeaders :: ListProjects -> 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 ListProjects where
  toPath :: ListProjects -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/projects"

instance Data.ToQuery ListProjects where
  toQuery :: ListProjects -> QueryString
toQuery ListProjects' {Maybe Natural
Maybe Text
Text
portalId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:portalId:ListProjects' :: ListProjects -> Text
$sel:nextToken:ListProjects' :: ListProjects -> Maybe Text
$sel:maxResults:ListProjects' :: ListProjects -> 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,
        ByteString
"portalId" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
portalId
      ]

-- | /See:/ 'newListProjectsResponse' smart constructor.
data ListProjectsResponse = ListProjectsResponse'
  { -- | The token for the next set of results, or null if there are no
    -- additional results.
    ListProjectsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListProjectsResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list that summarizes each project in the portal.
    ListProjectsResponse -> [ProjectSummary]
projectSummaries :: [ProjectSummary]
  }
  deriving (ListProjectsResponse -> ListProjectsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListProjectsResponse -> ListProjectsResponse -> Bool
$c/= :: ListProjectsResponse -> ListProjectsResponse -> Bool
== :: ListProjectsResponse -> ListProjectsResponse -> Bool
$c== :: ListProjectsResponse -> ListProjectsResponse -> Bool
Prelude.Eq, ReadPrec [ListProjectsResponse]
ReadPrec ListProjectsResponse
Int -> ReadS ListProjectsResponse
ReadS [ListProjectsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListProjectsResponse]
$creadListPrec :: ReadPrec [ListProjectsResponse]
readPrec :: ReadPrec ListProjectsResponse
$creadPrec :: ReadPrec ListProjectsResponse
readList :: ReadS [ListProjectsResponse]
$creadList :: ReadS [ListProjectsResponse]
readsPrec :: Int -> ReadS ListProjectsResponse
$creadsPrec :: Int -> ReadS ListProjectsResponse
Prelude.Read, Int -> ListProjectsResponse -> ShowS
[ListProjectsResponse] -> ShowS
ListProjectsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListProjectsResponse] -> ShowS
$cshowList :: [ListProjectsResponse] -> ShowS
show :: ListProjectsResponse -> String
$cshow :: ListProjectsResponse -> String
showsPrec :: Int -> ListProjectsResponse -> ShowS
$cshowsPrec :: Int -> ListProjectsResponse -> ShowS
Prelude.Show, forall x. Rep ListProjectsResponse x -> ListProjectsResponse
forall x. ListProjectsResponse -> Rep ListProjectsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListProjectsResponse x -> ListProjectsResponse
$cfrom :: forall x. ListProjectsResponse -> Rep ListProjectsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListProjectsResponse' 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', 'listProjectsResponse_nextToken' - The token for the next set of results, or null if there are no
-- additional results.
--
-- 'httpStatus', 'listProjectsResponse_httpStatus' - The response's http status code.
--
-- 'projectSummaries', 'listProjectsResponse_projectSummaries' - A list that summarizes each project in the portal.
newListProjectsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListProjectsResponse
newListProjectsResponse :: Int -> ListProjectsResponse
newListProjectsResponse Int
pHttpStatus_ =
  ListProjectsResponse'
    { $sel:nextToken:ListProjectsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListProjectsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:projectSummaries:ListProjectsResponse' :: [ProjectSummary]
projectSummaries = forall a. Monoid a => a
Prelude.mempty
    }

-- | The token for the next set of results, or null if there are no
-- additional results.
listProjectsResponse_nextToken :: Lens.Lens' ListProjectsResponse (Prelude.Maybe Prelude.Text)
listProjectsResponse_nextToken :: Lens' ListProjectsResponse (Maybe Text)
listProjectsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProjectsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListProjectsResponse' :: ListProjectsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListProjectsResponse
s@ListProjectsResponse' {} Maybe Text
a -> ListProjectsResponse
s {$sel:nextToken:ListProjectsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListProjectsResponse)

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

-- | A list that summarizes each project in the portal.
listProjectsResponse_projectSummaries :: Lens.Lens' ListProjectsResponse [ProjectSummary]
listProjectsResponse_projectSummaries :: Lens' ListProjectsResponse [ProjectSummary]
listProjectsResponse_projectSummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListProjectsResponse' {[ProjectSummary]
projectSummaries :: [ProjectSummary]
$sel:projectSummaries:ListProjectsResponse' :: ListProjectsResponse -> [ProjectSummary]
projectSummaries} -> [ProjectSummary]
projectSummaries) (\s :: ListProjectsResponse
s@ListProjectsResponse' {} [ProjectSummary]
a -> ListProjectsResponse
s {$sel:projectSummaries:ListProjectsResponse' :: [ProjectSummary]
projectSummaries = [ProjectSummary]
a} :: ListProjectsResponse) 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 ListProjectsResponse where
  rnf :: ListProjectsResponse -> ()
rnf ListProjectsResponse' {Int
[ProjectSummary]
Maybe Text
projectSummaries :: [ProjectSummary]
httpStatus :: Int
nextToken :: Maybe Text
$sel:projectSummaries:ListProjectsResponse' :: ListProjectsResponse -> [ProjectSummary]
$sel:httpStatus:ListProjectsResponse' :: ListProjectsResponse -> Int
$sel:nextToken:ListProjectsResponse' :: ListProjectsResponse -> 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 [ProjectSummary]
projectSummaries