{-# 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.ListGateways
-- 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 gateways.
--
-- This operation returns paginated results.
module Amazonka.IoTSiteWise.ListGateways
  ( -- * Creating a Request
    ListGateways (..),
    newListGateways,

    -- * Request Lenses
    listGateways_maxResults,
    listGateways_nextToken,

    -- * Destructuring the Response
    ListGatewaysResponse (..),
    newListGatewaysResponse,

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

-- |
-- Create a value of 'ListGateways' 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', 'listGateways_maxResults' - The maximum number of results to return for each paginated request.
--
-- Default: 50
--
-- 'nextToken', 'listGateways_nextToken' - The token to be used for the next set of paginated results.
newListGateways ::
  ListGateways
newListGateways :: ListGateways
newListGateways =
  ListGateways'
    { $sel:maxResults:ListGateways' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListGateways' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

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

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

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

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

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

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

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

-- |
-- Create a value of 'ListGatewaysResponse' 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', 'listGatewaysResponse_nextToken' - The token for the next set of results, or null if there are no
-- additional results.
--
-- 'httpStatus', 'listGatewaysResponse_httpStatus' - The response's http status code.
--
-- 'gatewaySummaries', 'listGatewaysResponse_gatewaySummaries' - A list that summarizes each gateway.
newListGatewaysResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListGatewaysResponse
newListGatewaysResponse :: Int -> ListGatewaysResponse
newListGatewaysResponse Int
pHttpStatus_ =
  ListGatewaysResponse'
    { $sel:nextToken:ListGatewaysResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListGatewaysResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:gatewaySummaries:ListGatewaysResponse' :: [GatewaySummary]
gatewaySummaries = forall a. Monoid a => a
Prelude.mempty
    }

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

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

-- | A list that summarizes each gateway.
listGatewaysResponse_gatewaySummaries :: Lens.Lens' ListGatewaysResponse [GatewaySummary]
listGatewaysResponse_gatewaySummaries :: Lens' ListGatewaysResponse [GatewaySummary]
listGatewaysResponse_gatewaySummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGatewaysResponse' {[GatewaySummary]
gatewaySummaries :: [GatewaySummary]
$sel:gatewaySummaries:ListGatewaysResponse' :: ListGatewaysResponse -> [GatewaySummary]
gatewaySummaries} -> [GatewaySummary]
gatewaySummaries) (\s :: ListGatewaysResponse
s@ListGatewaysResponse' {} [GatewaySummary]
a -> ListGatewaysResponse
s {$sel:gatewaySummaries:ListGatewaysResponse' :: [GatewaySummary]
gatewaySummaries = [GatewaySummary]
a} :: ListGatewaysResponse) 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 ListGatewaysResponse where
  rnf :: ListGatewaysResponse -> ()
rnf ListGatewaysResponse' {Int
[GatewaySummary]
Maybe Text
gatewaySummaries :: [GatewaySummary]
httpStatus :: Int
nextToken :: Maybe Text
$sel:gatewaySummaries:ListGatewaysResponse' :: ListGatewaysResponse -> [GatewaySummary]
$sel:httpStatus:ListGatewaysResponse' :: ListGatewaysResponse -> Int
$sel:nextToken:ListGatewaysResponse' :: ListGatewaysResponse -> 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 [GatewaySummary]
gatewaySummaries