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

    -- * Request Lenses
    listCoreDefinitions_maxResults,
    listCoreDefinitions_nextToken,

    -- * Destructuring the Response
    ListCoreDefinitionsResponse (..),
    newListCoreDefinitionsResponse,

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

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

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

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

instance Core.AWSPager ListCoreDefinitions where
  page :: ListCoreDefinitions
-> AWSResponse ListCoreDefinitions -> Maybe ListCoreDefinitions
page ListCoreDefinitions
rq AWSResponse ListCoreDefinitions
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListCoreDefinitions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListCoreDefinitionsResponse (Maybe Text)
listCoreDefinitionsResponse_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 ListCoreDefinitions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListCoreDefinitionsResponse (Maybe [DefinitionInformation])
listCoreDefinitionsResponse_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.$ ListCoreDefinitions
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListCoreDefinitions (Maybe Text)
listCoreDefinitions_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListCoreDefinitions
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListCoreDefinitionsResponse (Maybe Text)
listCoreDefinitionsResponse_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 ListCoreDefinitions where
  type
    AWSResponse ListCoreDefinitions =
      ListCoreDefinitionsResponse
  request :: (Service -> Service)
-> ListCoreDefinitions -> Request ListCoreDefinitions
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 ListCoreDefinitions
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListCoreDefinitions)))
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 -> ListCoreDefinitionsResponse
ListCoreDefinitionsResponse'
            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 ListCoreDefinitions where
  hashWithSalt :: Int -> ListCoreDefinitions -> Int
hashWithSalt Int
_salt ListCoreDefinitions' {Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:nextToken:ListCoreDefinitions' :: ListCoreDefinitions -> Maybe Text
$sel:maxResults:ListCoreDefinitions' :: ListCoreDefinitions -> 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 ListCoreDefinitions where
  rnf :: ListCoreDefinitions -> ()
rnf ListCoreDefinitions' {Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:nextToken:ListCoreDefinitions' :: ListCoreDefinitions -> Maybe Text
$sel:maxResults:ListCoreDefinitions' :: ListCoreDefinitions -> 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 ListCoreDefinitions where
  toHeaders :: ListCoreDefinitions -> 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 ListCoreDefinitions where
  toPath :: ListCoreDefinitions -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/greengrass/definition/cores"

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

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

-- | Information about a definition.
listCoreDefinitionsResponse_definitions :: Lens.Lens' ListCoreDefinitionsResponse (Prelude.Maybe [DefinitionInformation])
listCoreDefinitionsResponse_definitions :: Lens' ListCoreDefinitionsResponse (Maybe [DefinitionInformation])
listCoreDefinitionsResponse_definitions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListCoreDefinitionsResponse' {Maybe [DefinitionInformation]
definitions :: Maybe [DefinitionInformation]
$sel:definitions:ListCoreDefinitionsResponse' :: ListCoreDefinitionsResponse -> Maybe [DefinitionInformation]
definitions} -> Maybe [DefinitionInformation]
definitions) (\s :: ListCoreDefinitionsResponse
s@ListCoreDefinitionsResponse' {} Maybe [DefinitionInformation]
a -> ListCoreDefinitionsResponse
s {$sel:definitions:ListCoreDefinitionsResponse' :: Maybe [DefinitionInformation]
definitions = Maybe [DefinitionInformation]
a} :: ListCoreDefinitionsResponse) 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.
listCoreDefinitionsResponse_nextToken :: Lens.Lens' ListCoreDefinitionsResponse (Prelude.Maybe Prelude.Text)
listCoreDefinitionsResponse_nextToken :: Lens' ListCoreDefinitionsResponse (Maybe Text)
listCoreDefinitionsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListCoreDefinitionsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListCoreDefinitionsResponse' :: ListCoreDefinitionsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListCoreDefinitionsResponse
s@ListCoreDefinitionsResponse' {} Maybe Text
a -> ListCoreDefinitionsResponse
s {$sel:nextToken:ListCoreDefinitionsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListCoreDefinitionsResponse)

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

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