{-# 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.Greengrass.ListResourceDefinitions
-- 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 resource definitions.
--
-- This operation returns paginated results.
module Amazonka.Greengrass.ListResourceDefinitions
  ( -- * Creating a Request
    ListResourceDefinitions (..),
    newListResourceDefinitions,

    -- * Request Lenses
    listResourceDefinitions_maxResults,
    listResourceDefinitions_nextToken,

    -- * Destructuring the Response
    ListResourceDefinitionsResponse (..),
    newListResourceDefinitionsResponse,

    -- * Response Lenses
    listResourceDefinitionsResponse_definitions,
    listResourceDefinitionsResponse_nextToken,
    listResourceDefinitionsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListResourceDefinitions' smart constructor.
data ListResourceDefinitions = ListResourceDefinitions'
  { -- | The maximum number of results to be returned per request.
    ListResourceDefinitions -> Maybe Text
maxResults :: Prelude.Maybe Prelude.Text,
    -- | The token for the next set of results, or \'\'null\'\' if there are no
    -- additional results.
    ListResourceDefinitions -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListResourceDefinitions -> ListResourceDefinitions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListResourceDefinitions -> ListResourceDefinitions -> Bool
$c/= :: ListResourceDefinitions -> ListResourceDefinitions -> Bool
== :: ListResourceDefinitions -> ListResourceDefinitions -> Bool
$c== :: ListResourceDefinitions -> ListResourceDefinitions -> Bool
Prelude.Eq, ReadPrec [ListResourceDefinitions]
ReadPrec ListResourceDefinitions
Int -> ReadS ListResourceDefinitions
ReadS [ListResourceDefinitions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListResourceDefinitions]
$creadListPrec :: ReadPrec [ListResourceDefinitions]
readPrec :: ReadPrec ListResourceDefinitions
$creadPrec :: ReadPrec ListResourceDefinitions
readList :: ReadS [ListResourceDefinitions]
$creadList :: ReadS [ListResourceDefinitions]
readsPrec :: Int -> ReadS ListResourceDefinitions
$creadsPrec :: Int -> ReadS ListResourceDefinitions
Prelude.Read, Int -> ListResourceDefinitions -> ShowS
[ListResourceDefinitions] -> ShowS
ListResourceDefinitions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListResourceDefinitions] -> ShowS
$cshowList :: [ListResourceDefinitions] -> ShowS
show :: ListResourceDefinitions -> String
$cshow :: ListResourceDefinitions -> String
showsPrec :: Int -> ListResourceDefinitions -> ShowS
$cshowsPrec :: Int -> ListResourceDefinitions -> ShowS
Prelude.Show, forall x. Rep ListResourceDefinitions x -> ListResourceDefinitions
forall x. ListResourceDefinitions -> Rep ListResourceDefinitions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListResourceDefinitions x -> ListResourceDefinitions
$cfrom :: forall x. ListResourceDefinitions -> Rep ListResourceDefinitions x
Prelude.Generic)

-- |
-- Create a value of 'ListResourceDefinitions' 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', 'listResourceDefinitions_maxResults' - The maximum number of results to be returned per request.
--
-- 'nextToken', 'listResourceDefinitions_nextToken' - The token for the next set of results, or \'\'null\'\' if there are no
-- additional results.
newListResourceDefinitions ::
  ListResourceDefinitions
newListResourceDefinitions :: ListResourceDefinitions
newListResourceDefinitions =
  ListResourceDefinitions'
    { $sel:maxResults:ListResourceDefinitions' :: Maybe Text
maxResults =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListResourceDefinitions' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of results to be returned per request.
listResourceDefinitions_maxResults :: Lens.Lens' ListResourceDefinitions (Prelude.Maybe Prelude.Text)
listResourceDefinitions_maxResults :: Lens' ListResourceDefinitions (Maybe Text)
listResourceDefinitions_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListResourceDefinitions' {Maybe Text
maxResults :: Maybe Text
$sel:maxResults:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
maxResults} -> Maybe Text
maxResults) (\s :: ListResourceDefinitions
s@ListResourceDefinitions' {} Maybe Text
a -> ListResourceDefinitions
s {$sel:maxResults:ListResourceDefinitions' :: Maybe Text
maxResults = Maybe Text
a} :: ListResourceDefinitions)

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

instance Core.AWSPager ListResourceDefinitions where
  page :: ListResourceDefinitions
-> AWSResponse ListResourceDefinitions
-> Maybe ListResourceDefinitions
page ListResourceDefinitions
rq AWSResponse ListResourceDefinitions
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListResourceDefinitions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListResourceDefinitionsResponse (Maybe Text)
listResourceDefinitionsResponse_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 ListResourceDefinitions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens'
  ListResourceDefinitionsResponse (Maybe [DefinitionInformation])
listResourceDefinitionsResponse_definitions
            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
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListResourceDefinitions
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListResourceDefinitions (Maybe Text)
listResourceDefinitions_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListResourceDefinitions
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListResourceDefinitionsResponse (Maybe Text)
listResourceDefinitionsResponse_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 ListResourceDefinitions where
  type
    AWSResponse ListResourceDefinitions =
      ListResourceDefinitionsResponse
  request :: (Service -> Service)
-> ListResourceDefinitions -> Request ListResourceDefinitions
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 ListResourceDefinitions
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListResourceDefinitions)))
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 [DefinitionInformation]
-> Maybe Text -> Int -> ListResourceDefinitionsResponse
ListResourceDefinitionsResponse'
            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
"Definitions" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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
"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))
      )

instance Prelude.Hashable ListResourceDefinitions where
  hashWithSalt :: Int -> ListResourceDefinitions -> Int
hashWithSalt Int
_salt ListResourceDefinitions' {Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:nextToken:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
$sel:maxResults:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListResourceDefinitions where
  rnf :: ListResourceDefinitions -> ()
rnf ListResourceDefinitions' {Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:nextToken:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
$sel:maxResults:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

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

instance Data.ToQuery ListResourceDefinitions where
  toQuery :: ListResourceDefinitions -> QueryString
toQuery ListResourceDefinitions' {Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:nextToken:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
$sel:maxResults:ListResourceDefinitions' :: ListResourceDefinitions -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"MaxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
maxResults,
        ByteString
"NextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | /See:/ 'newListResourceDefinitionsResponse' smart constructor.
data ListResourceDefinitionsResponse = ListResourceDefinitionsResponse'
  { -- | Information about a definition.
    ListResourceDefinitionsResponse -> Maybe [DefinitionInformation]
definitions :: Prelude.Maybe [DefinitionInformation],
    -- | The token for the next set of results, or \'\'null\'\' if there are no
    -- additional results.
    ListResourceDefinitionsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListResourceDefinitionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListResourceDefinitionsResponse
-> ListResourceDefinitionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListResourceDefinitionsResponse
-> ListResourceDefinitionsResponse -> Bool
$c/= :: ListResourceDefinitionsResponse
-> ListResourceDefinitionsResponse -> Bool
== :: ListResourceDefinitionsResponse
-> ListResourceDefinitionsResponse -> Bool
$c== :: ListResourceDefinitionsResponse
-> ListResourceDefinitionsResponse -> Bool
Prelude.Eq, ReadPrec [ListResourceDefinitionsResponse]
ReadPrec ListResourceDefinitionsResponse
Int -> ReadS ListResourceDefinitionsResponse
ReadS [ListResourceDefinitionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListResourceDefinitionsResponse]
$creadListPrec :: ReadPrec [ListResourceDefinitionsResponse]
readPrec :: ReadPrec ListResourceDefinitionsResponse
$creadPrec :: ReadPrec ListResourceDefinitionsResponse
readList :: ReadS [ListResourceDefinitionsResponse]
$creadList :: ReadS [ListResourceDefinitionsResponse]
readsPrec :: Int -> ReadS ListResourceDefinitionsResponse
$creadsPrec :: Int -> ReadS ListResourceDefinitionsResponse
Prelude.Read, Int -> ListResourceDefinitionsResponse -> ShowS
[ListResourceDefinitionsResponse] -> ShowS
ListResourceDefinitionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListResourceDefinitionsResponse] -> ShowS
$cshowList :: [ListResourceDefinitionsResponse] -> ShowS
show :: ListResourceDefinitionsResponse -> String
$cshow :: ListResourceDefinitionsResponse -> String
showsPrec :: Int -> ListResourceDefinitionsResponse -> ShowS
$cshowsPrec :: Int -> ListResourceDefinitionsResponse -> ShowS
Prelude.Show, forall x.
Rep ListResourceDefinitionsResponse x
-> ListResourceDefinitionsResponse
forall x.
ListResourceDefinitionsResponse
-> Rep ListResourceDefinitionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListResourceDefinitionsResponse x
-> ListResourceDefinitionsResponse
$cfrom :: forall x.
ListResourceDefinitionsResponse
-> Rep ListResourceDefinitionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListResourceDefinitionsResponse' 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:
--
-- 'definitions', 'listResourceDefinitionsResponse_definitions' - Information about a definition.
--
-- 'nextToken', 'listResourceDefinitionsResponse_nextToken' - The token for the next set of results, or \'\'null\'\' if there are no
-- additional results.
--
-- 'httpStatus', 'listResourceDefinitionsResponse_httpStatus' - The response's http status code.
newListResourceDefinitionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListResourceDefinitionsResponse
newListResourceDefinitionsResponse :: Int -> ListResourceDefinitionsResponse
newListResourceDefinitionsResponse Int
pHttpStatus_ =
  ListResourceDefinitionsResponse'
    { $sel:definitions:ListResourceDefinitionsResponse' :: Maybe [DefinitionInformation]
definitions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListResourceDefinitionsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListResourceDefinitionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about a definition.
listResourceDefinitionsResponse_definitions :: Lens.Lens' ListResourceDefinitionsResponse (Prelude.Maybe [DefinitionInformation])
listResourceDefinitionsResponse_definitions :: Lens'
  ListResourceDefinitionsResponse (Maybe [DefinitionInformation])
listResourceDefinitionsResponse_definitions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListResourceDefinitionsResponse' {Maybe [DefinitionInformation]
definitions :: Maybe [DefinitionInformation]
$sel:definitions:ListResourceDefinitionsResponse' :: ListResourceDefinitionsResponse -> Maybe [DefinitionInformation]
definitions} -> Maybe [DefinitionInformation]
definitions) (\s :: ListResourceDefinitionsResponse
s@ListResourceDefinitionsResponse' {} Maybe [DefinitionInformation]
a -> ListResourceDefinitionsResponse
s {$sel:definitions:ListResourceDefinitionsResponse' :: Maybe [DefinitionInformation]
definitions = Maybe [DefinitionInformation]
a} :: ListResourceDefinitionsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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

instance
  Prelude.NFData
    ListResourceDefinitionsResponse
  where
  rnf :: ListResourceDefinitionsResponse -> ()
rnf ListResourceDefinitionsResponse' {Int
Maybe [DefinitionInformation]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
definitions :: Maybe [DefinitionInformation]
$sel:httpStatus:ListResourceDefinitionsResponse' :: ListResourceDefinitionsResponse -> Int
$sel:nextToken:ListResourceDefinitionsResponse' :: ListResourceDefinitionsResponse -> Maybe Text
$sel:definitions:ListResourceDefinitionsResponse' :: ListResourceDefinitionsResponse -> Maybe [DefinitionInformation]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [DefinitionInformation]
definitions
      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 Int
httpStatus