{-# 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.IoTFleetWise.ListFleets
-- 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 information for each created fleet in an Amazon Web Services
-- account.
--
-- This API operation uses pagination. Specify the @nextToken@ parameter in
-- the request to return more results.
--
-- This operation returns paginated results.
module Amazonka.IoTFleetWise.ListFleets
  ( -- * Creating a Request
    ListFleets (..),
    newListFleets,

    -- * Request Lenses
    listFleets_maxResults,
    listFleets_nextToken,

    -- * Destructuring the Response
    ListFleetsResponse (..),
    newListFleetsResponse,

    -- * Response Lenses
    listFleetsResponse_fleetSummaries,
    listFleetsResponse_nextToken,
    listFleetsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListFleets' smart constructor.
data ListFleets = ListFleets'
  { -- | The maximum number of items to return, between 1 and 100, inclusive.
    ListFleets -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A pagination token for the next set of results.
    --
    -- If the results of a search are large, only a portion of the results are
    -- returned, and a @nextToken@ pagination token is returned in the
    -- response. To retrieve the next set of results, reissue the search
    -- request and include the returned token. When all results have been
    -- returned, the response does not contain a pagination token value.
    ListFleets -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListFleets -> ListFleets -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListFleets -> ListFleets -> Bool
$c/= :: ListFleets -> ListFleets -> Bool
== :: ListFleets -> ListFleets -> Bool
$c== :: ListFleets -> ListFleets -> Bool
Prelude.Eq, ReadPrec [ListFleets]
ReadPrec ListFleets
Int -> ReadS ListFleets
ReadS [ListFleets]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListFleets]
$creadListPrec :: ReadPrec [ListFleets]
readPrec :: ReadPrec ListFleets
$creadPrec :: ReadPrec ListFleets
readList :: ReadS [ListFleets]
$creadList :: ReadS [ListFleets]
readsPrec :: Int -> ReadS ListFleets
$creadsPrec :: Int -> ReadS ListFleets
Prelude.Read, Int -> ListFleets -> ShowS
[ListFleets] -> ShowS
ListFleets -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListFleets] -> ShowS
$cshowList :: [ListFleets] -> ShowS
show :: ListFleets -> String
$cshow :: ListFleets -> String
showsPrec :: Int -> ListFleets -> ShowS
$cshowsPrec :: Int -> ListFleets -> ShowS
Prelude.Show, forall x. Rep ListFleets x -> ListFleets
forall x. ListFleets -> Rep ListFleets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListFleets x -> ListFleets
$cfrom :: forall x. ListFleets -> Rep ListFleets x
Prelude.Generic)

-- |
-- Create a value of 'ListFleets' 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', 'listFleets_maxResults' - The maximum number of items to return, between 1 and 100, inclusive.
--
-- 'nextToken', 'listFleets_nextToken' - A pagination token for the next set of results.
--
-- If the results of a search are large, only a portion of the results are
-- returned, and a @nextToken@ pagination token is returned in the
-- response. To retrieve the next set of results, reissue the search
-- request and include the returned token. When all results have been
-- returned, the response does not contain a pagination token value.
newListFleets ::
  ListFleets
newListFleets :: ListFleets
newListFleets =
  ListFleets'
    { $sel:maxResults:ListFleets' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListFleets' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of items to return, between 1 and 100, inclusive.
listFleets_maxResults :: Lens.Lens' ListFleets (Prelude.Maybe Prelude.Natural)
listFleets_maxResults :: Lens' ListFleets (Maybe Natural)
listFleets_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFleets' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListFleets' :: ListFleets -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListFleets
s@ListFleets' {} Maybe Natural
a -> ListFleets
s {$sel:maxResults:ListFleets' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListFleets)

-- | A pagination token for the next set of results.
--
-- If the results of a search are large, only a portion of the results are
-- returned, and a @nextToken@ pagination token is returned in the
-- response. To retrieve the next set of results, reissue the search
-- request and include the returned token. When all results have been
-- returned, the response does not contain a pagination token value.
listFleets_nextToken :: Lens.Lens' ListFleets (Prelude.Maybe Prelude.Text)
listFleets_nextToken :: Lens' ListFleets (Maybe Text)
listFleets_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFleets' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListFleets' :: ListFleets -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListFleets
s@ListFleets' {} Maybe Text
a -> ListFleets
s {$sel:nextToken:ListFleets' :: Maybe Text
nextToken = Maybe Text
a} :: ListFleets)

instance Core.AWSPager ListFleets where
  page :: ListFleets -> AWSResponse ListFleets -> Maybe ListFleets
page ListFleets
rq AWSResponse ListFleets
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListFleets
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFleetsResponse (Maybe Text)
listFleetsResponse_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 ListFleets
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFleetsResponse (Maybe [FleetSummary])
listFleetsResponse_fleetSummaries
            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.$ ListFleets
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListFleets (Maybe Text)
listFleets_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListFleets
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFleetsResponse (Maybe Text)
listFleetsResponse_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 ListFleets where
  type AWSResponse ListFleets = ListFleetsResponse
  request :: (Service -> Service) -> ListFleets -> Request ListFleets
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListFleets
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListFleets)))
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 [FleetSummary] -> Maybe Text -> Int -> ListFleetsResponse
ListFleetsResponse'
            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
"fleetSummaries" 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 ListFleets where
  hashWithSalt :: Int -> ListFleets -> Int
hashWithSalt Int
_salt ListFleets' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListFleets' :: ListFleets -> Maybe Text
$sel:maxResults:ListFleets' :: ListFleets -> 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 ListFleets where
  rnf :: ListFleets -> ()
rnf ListFleets' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListFleets' :: ListFleets -> Maybe Text
$sel:maxResults:ListFleets' :: ListFleets -> 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 ListFleets where
  toHeaders :: ListFleets -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"IoTAutobahnControlPlane.ListFleets" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListFleets where
  toJSON :: ListFleets -> Value
toJSON ListFleets' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListFleets' :: ListFleets -> Maybe Text
$sel:maxResults:ListFleets' :: ListFleets -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"maxResults" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Key
"nextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken
          ]
      )

instance Data.ToPath ListFleets where
  toPath :: ListFleets -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery ListFleets where
  toQuery :: ListFleets -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newListFleetsResponse' smart constructor.
data ListFleetsResponse = ListFleetsResponse'
  { -- | A list of information for each fleet.
    ListFleetsResponse -> Maybe [FleetSummary]
fleetSummaries :: Prelude.Maybe [FleetSummary],
    -- | The token to retrieve the next set of results, or @null@ if there are no
    -- more results.
    ListFleetsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListFleetsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListFleetsResponse -> ListFleetsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListFleetsResponse -> ListFleetsResponse -> Bool
$c/= :: ListFleetsResponse -> ListFleetsResponse -> Bool
== :: ListFleetsResponse -> ListFleetsResponse -> Bool
$c== :: ListFleetsResponse -> ListFleetsResponse -> Bool
Prelude.Eq, ReadPrec [ListFleetsResponse]
ReadPrec ListFleetsResponse
Int -> ReadS ListFleetsResponse
ReadS [ListFleetsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListFleetsResponse]
$creadListPrec :: ReadPrec [ListFleetsResponse]
readPrec :: ReadPrec ListFleetsResponse
$creadPrec :: ReadPrec ListFleetsResponse
readList :: ReadS [ListFleetsResponse]
$creadList :: ReadS [ListFleetsResponse]
readsPrec :: Int -> ReadS ListFleetsResponse
$creadsPrec :: Int -> ReadS ListFleetsResponse
Prelude.Read, Int -> ListFleetsResponse -> ShowS
[ListFleetsResponse] -> ShowS
ListFleetsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListFleetsResponse] -> ShowS
$cshowList :: [ListFleetsResponse] -> ShowS
show :: ListFleetsResponse -> String
$cshow :: ListFleetsResponse -> String
showsPrec :: Int -> ListFleetsResponse -> ShowS
$cshowsPrec :: Int -> ListFleetsResponse -> ShowS
Prelude.Show, forall x. Rep ListFleetsResponse x -> ListFleetsResponse
forall x. ListFleetsResponse -> Rep ListFleetsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListFleetsResponse x -> ListFleetsResponse
$cfrom :: forall x. ListFleetsResponse -> Rep ListFleetsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListFleetsResponse' 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:
--
-- 'fleetSummaries', 'listFleetsResponse_fleetSummaries' - A list of information for each fleet.
--
-- 'nextToken', 'listFleetsResponse_nextToken' - The token to retrieve the next set of results, or @null@ if there are no
-- more results.
--
-- 'httpStatus', 'listFleetsResponse_httpStatus' - The response's http status code.
newListFleetsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListFleetsResponse
newListFleetsResponse :: Int -> ListFleetsResponse
newListFleetsResponse Int
pHttpStatus_ =
  ListFleetsResponse'
    { $sel:fleetSummaries:ListFleetsResponse' :: Maybe [FleetSummary]
fleetSummaries =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListFleetsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListFleetsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of information for each fleet.
listFleetsResponse_fleetSummaries :: Lens.Lens' ListFleetsResponse (Prelude.Maybe [FleetSummary])
listFleetsResponse_fleetSummaries :: Lens' ListFleetsResponse (Maybe [FleetSummary])
listFleetsResponse_fleetSummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFleetsResponse' {Maybe [FleetSummary]
fleetSummaries :: Maybe [FleetSummary]
$sel:fleetSummaries:ListFleetsResponse' :: ListFleetsResponse -> Maybe [FleetSummary]
fleetSummaries} -> Maybe [FleetSummary]
fleetSummaries) (\s :: ListFleetsResponse
s@ListFleetsResponse' {} Maybe [FleetSummary]
a -> ListFleetsResponse
s {$sel:fleetSummaries:ListFleetsResponse' :: Maybe [FleetSummary]
fleetSummaries = Maybe [FleetSummary]
a} :: ListFleetsResponse) 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 to retrieve the next set of results, or @null@ if there are no
-- more results.
listFleetsResponse_nextToken :: Lens.Lens' ListFleetsResponse (Prelude.Maybe Prelude.Text)
listFleetsResponse_nextToken :: Lens' ListFleetsResponse (Maybe Text)
listFleetsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFleetsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListFleetsResponse' :: ListFleetsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListFleetsResponse
s@ListFleetsResponse' {} Maybe Text
a -> ListFleetsResponse
s {$sel:nextToken:ListFleetsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListFleetsResponse)

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

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