{-# 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.IoT1ClickProjects.ListPlacements
-- 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 the placement(s) of a project.
--
-- This operation returns paginated results.
module Amazonka.IoT1ClickProjects.ListPlacements
  ( -- * Creating a Request
    ListPlacements (..),
    newListPlacements,

    -- * Request Lenses
    listPlacements_maxResults,
    listPlacements_nextToken,
    listPlacements_projectName,

    -- * Destructuring the Response
    ListPlacementsResponse (..),
    newListPlacementsResponse,

    -- * Response Lenses
    listPlacementsResponse_nextToken,
    listPlacementsResponse_httpStatus,
    listPlacementsResponse_placements,
  )
where

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

-- | /See:/ 'newListPlacements' smart constructor.
data ListPlacements = ListPlacements'
  { -- | The maximum number of results to return per request. If not set, a
    -- default value of 100 is used.
    ListPlacements -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token to retrieve the next set of results.
    ListPlacements -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The project containing the placements to be listed.
    ListPlacements -> Text
projectName :: Prelude.Text
  }
  deriving (ListPlacements -> ListPlacements -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPlacements -> ListPlacements -> Bool
$c/= :: ListPlacements -> ListPlacements -> Bool
== :: ListPlacements -> ListPlacements -> Bool
$c== :: ListPlacements -> ListPlacements -> Bool
Prelude.Eq, ReadPrec [ListPlacements]
ReadPrec ListPlacements
Int -> ReadS ListPlacements
ReadS [ListPlacements]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPlacements]
$creadListPrec :: ReadPrec [ListPlacements]
readPrec :: ReadPrec ListPlacements
$creadPrec :: ReadPrec ListPlacements
readList :: ReadS [ListPlacements]
$creadList :: ReadS [ListPlacements]
readsPrec :: Int -> ReadS ListPlacements
$creadsPrec :: Int -> ReadS ListPlacements
Prelude.Read, Int -> ListPlacements -> ShowS
[ListPlacements] -> ShowS
ListPlacements -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPlacements] -> ShowS
$cshowList :: [ListPlacements] -> ShowS
show :: ListPlacements -> String
$cshow :: ListPlacements -> String
showsPrec :: Int -> ListPlacements -> ShowS
$cshowsPrec :: Int -> ListPlacements -> ShowS
Prelude.Show, forall x. Rep ListPlacements x -> ListPlacements
forall x. ListPlacements -> Rep ListPlacements x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListPlacements x -> ListPlacements
$cfrom :: forall x. ListPlacements -> Rep ListPlacements x
Prelude.Generic)

-- |
-- Create a value of 'ListPlacements' 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', 'listPlacements_maxResults' - The maximum number of results to return per request. If not set, a
-- default value of 100 is used.
--
-- 'nextToken', 'listPlacements_nextToken' - The token to retrieve the next set of results.
--
-- 'projectName', 'listPlacements_projectName' - The project containing the placements to be listed.
newListPlacements ::
  -- | 'projectName'
  Prelude.Text ->
  ListPlacements
newListPlacements :: Text -> ListPlacements
newListPlacements Text
pProjectName_ =
  ListPlacements'
    { $sel:maxResults:ListPlacements' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListPlacements' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:projectName:ListPlacements' :: Text
projectName = Text
pProjectName_
    }

-- | The maximum number of results to return per request. If not set, a
-- default value of 100 is used.
listPlacements_maxResults :: Lens.Lens' ListPlacements (Prelude.Maybe Prelude.Natural)
listPlacements_maxResults :: Lens' ListPlacements (Maybe Natural)
listPlacements_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlacements' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListPlacements' :: ListPlacements -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListPlacements
s@ListPlacements' {} Maybe Natural
a -> ListPlacements
s {$sel:maxResults:ListPlacements' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListPlacements)

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

-- | The project containing the placements to be listed.
listPlacements_projectName :: Lens.Lens' ListPlacements Prelude.Text
listPlacements_projectName :: Lens' ListPlacements Text
listPlacements_projectName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlacements' {Text
projectName :: Text
$sel:projectName:ListPlacements' :: ListPlacements -> Text
projectName} -> Text
projectName) (\s :: ListPlacements
s@ListPlacements' {} Text
a -> ListPlacements
s {$sel:projectName:ListPlacements' :: Text
projectName = Text
a} :: ListPlacements)

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

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

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

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

instance Data.ToQuery ListPlacements where
  toQuery :: ListPlacements -> QueryString
toQuery ListPlacements' {Maybe Natural
Maybe Text
Text
projectName :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:projectName:ListPlacements' :: ListPlacements -> Text
$sel:nextToken:ListPlacements' :: ListPlacements -> Maybe Text
$sel:maxResults:ListPlacements' :: ListPlacements -> 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:/ 'newListPlacementsResponse' smart constructor.
data ListPlacementsResponse = ListPlacementsResponse'
  { -- | The token used to retrieve the next set of results - will be effectively
    -- empty if there are no further results.
    ListPlacementsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListPlacementsResponse -> Int
httpStatus :: Prelude.Int,
    -- | An object listing the requested placements.
    ListPlacementsResponse -> [PlacementSummary]
placements :: [PlacementSummary]
  }
  deriving (ListPlacementsResponse -> ListPlacementsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPlacementsResponse -> ListPlacementsResponse -> Bool
$c/= :: ListPlacementsResponse -> ListPlacementsResponse -> Bool
== :: ListPlacementsResponse -> ListPlacementsResponse -> Bool
$c== :: ListPlacementsResponse -> ListPlacementsResponse -> Bool
Prelude.Eq, ReadPrec [ListPlacementsResponse]
ReadPrec ListPlacementsResponse
Int -> ReadS ListPlacementsResponse
ReadS [ListPlacementsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPlacementsResponse]
$creadListPrec :: ReadPrec [ListPlacementsResponse]
readPrec :: ReadPrec ListPlacementsResponse
$creadPrec :: ReadPrec ListPlacementsResponse
readList :: ReadS [ListPlacementsResponse]
$creadList :: ReadS [ListPlacementsResponse]
readsPrec :: Int -> ReadS ListPlacementsResponse
$creadsPrec :: Int -> ReadS ListPlacementsResponse
Prelude.Read, Int -> ListPlacementsResponse -> ShowS
[ListPlacementsResponse] -> ShowS
ListPlacementsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPlacementsResponse] -> ShowS
$cshowList :: [ListPlacementsResponse] -> ShowS
show :: ListPlacementsResponse -> String
$cshow :: ListPlacementsResponse -> String
showsPrec :: Int -> ListPlacementsResponse -> ShowS
$cshowsPrec :: Int -> ListPlacementsResponse -> ShowS
Prelude.Show, forall x. Rep ListPlacementsResponse x -> ListPlacementsResponse
forall x. ListPlacementsResponse -> Rep ListPlacementsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListPlacementsResponse x -> ListPlacementsResponse
$cfrom :: forall x. ListPlacementsResponse -> Rep ListPlacementsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListPlacementsResponse' 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', 'listPlacementsResponse_nextToken' - The token used to retrieve the next set of results - will be effectively
-- empty if there are no further results.
--
-- 'httpStatus', 'listPlacementsResponse_httpStatus' - The response's http status code.
--
-- 'placements', 'listPlacementsResponse_placements' - An object listing the requested placements.
newListPlacementsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListPlacementsResponse
newListPlacementsResponse :: Int -> ListPlacementsResponse
newListPlacementsResponse Int
pHttpStatus_ =
  ListPlacementsResponse'
    { $sel:nextToken:ListPlacementsResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListPlacementsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:placements:ListPlacementsResponse' :: [PlacementSummary]
placements = forall a. Monoid a => a
Prelude.mempty
    }

-- | The token used to retrieve the next set of results - will be effectively
-- empty if there are no further results.
listPlacementsResponse_nextToken :: Lens.Lens' ListPlacementsResponse (Prelude.Maybe Prelude.Text)
listPlacementsResponse_nextToken :: Lens' ListPlacementsResponse (Maybe Text)
listPlacementsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlacementsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPlacementsResponse' :: ListPlacementsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPlacementsResponse
s@ListPlacementsResponse' {} Maybe Text
a -> ListPlacementsResponse
s {$sel:nextToken:ListPlacementsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListPlacementsResponse)

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

-- | An object listing the requested placements.
listPlacementsResponse_placements :: Lens.Lens' ListPlacementsResponse [PlacementSummary]
listPlacementsResponse_placements :: Lens' ListPlacementsResponse [PlacementSummary]
listPlacementsResponse_placements = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPlacementsResponse' {[PlacementSummary]
placements :: [PlacementSummary]
$sel:placements:ListPlacementsResponse' :: ListPlacementsResponse -> [PlacementSummary]
placements} -> [PlacementSummary]
placements) (\s :: ListPlacementsResponse
s@ListPlacementsResponse' {} [PlacementSummary]
a -> ListPlacementsResponse
s {$sel:placements:ListPlacementsResponse' :: [PlacementSummary]
placements = [PlacementSummary]
a} :: ListPlacementsResponse) 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 ListPlacementsResponse where
  rnf :: ListPlacementsResponse -> ()
rnf ListPlacementsResponse' {Int
[PlacementSummary]
Maybe Text
placements :: [PlacementSummary]
httpStatus :: Int
nextToken :: Maybe Text
$sel:placements:ListPlacementsResponse' :: ListPlacementsResponse -> [PlacementSummary]
$sel:httpStatus:ListPlacementsResponse' :: ListPlacementsResponse -> Int
$sel:nextToken:ListPlacementsResponse' :: ListPlacementsResponse -> 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 [PlacementSummary]
placements