{-# 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.StorageGateway.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)
--
-- Lists gateways owned by an Amazon Web Services account in an Amazon Web
-- Services Region specified in the request. The returned list is ordered
-- by gateway Amazon Resource Name (ARN).
--
-- By default, the operation returns a maximum of 100 gateways. This
-- operation supports pagination that allows you to optionally reduce the
-- number of gateways returned in a response.
--
-- If you have more gateways than are returned in a response (that is, the
-- response returns only a truncated list of your gateways), the response
-- contains a marker that you can specify in your next request to fetch the
-- next page of gateways.
--
-- This operation returns paginated results.
module Amazonka.StorageGateway.ListGateways
  ( -- * Creating a Request
    ListGateways (..),
    newListGateways,

    -- * Request Lenses
    listGateways_limit,
    listGateways_marker,

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

    -- * Response Lenses
    listGatewaysResponse_gateways,
    listGatewaysResponse_marker,
    listGatewaysResponse_httpStatus,
  )
where

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

-- | A JSON object containing zero or more of the following fields:
--
-- -   ListGatewaysInput$Limit
--
-- -   ListGatewaysInput$Marker
--
-- /See:/ 'newListGateways' smart constructor.
data ListGateways = ListGateways'
  { -- | Specifies that the list of gateways returned be limited to the specified
    -- number of items.
    ListGateways -> Maybe Natural
limit :: Prelude.Maybe Prelude.Natural,
    -- | An opaque string that indicates the position at which to begin the
    -- returned list of gateways.
    ListGateways -> Maybe Text
marker :: 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:
--
-- 'limit', 'listGateways_limit' - Specifies that the list of gateways returned be limited to the specified
-- number of items.
--
-- 'marker', 'listGateways_marker' - An opaque string that indicates the position at which to begin the
-- returned list of gateways.
newListGateways ::
  ListGateways
newListGateways :: ListGateways
newListGateways =
  ListGateways'
    { $sel:limit:ListGateways' :: Maybe Natural
limit = forall a. Maybe a
Prelude.Nothing,
      $sel:marker:ListGateways' :: Maybe Text
marker = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies that the list of gateways returned be limited to the specified
-- number of items.
listGateways_limit :: Lens.Lens' ListGateways (Prelude.Maybe Prelude.Natural)
listGateways_limit :: Lens' ListGateways (Maybe Natural)
listGateways_limit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGateways' {Maybe Natural
limit :: Maybe Natural
$sel:limit:ListGateways' :: ListGateways -> Maybe Natural
limit} -> Maybe Natural
limit) (\s :: ListGateways
s@ListGateways' {} Maybe Natural
a -> ListGateways
s {$sel:limit:ListGateways' :: Maybe Natural
limit = Maybe Natural
a} :: ListGateways)

-- | An opaque string that indicates the position at which to begin the
-- returned list of gateways.
listGateways_marker :: Lens.Lens' ListGateways (Prelude.Maybe Prelude.Text)
listGateways_marker :: Lens' ListGateways (Maybe Text)
listGateways_marker = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGateways' {Maybe Text
marker :: Maybe Text
$sel:marker:ListGateways' :: ListGateways -> Maybe Text
marker} -> Maybe Text
marker) (\s :: ListGateways
s@ListGateways' {} Maybe Text
a -> ListGateways
s {$sel:marker:ListGateways' :: Maybe Text
marker = 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_marker
            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 (First a) s a -> Maybe a
Lens.^? Lens' ListGatewaysResponse (Maybe [GatewayInfo])
listGatewaysResponse_gateways
            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.$ ListGateways
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListGateways (Maybe Text)
listGateways_marker
          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_marker
          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, ToJSON a) => Service -> a -> Request a
Request.postJSON (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 [GatewayInfo] -> Maybe Text -> Int -> 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
"Gateways" 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
"Marker")
            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 ListGateways where
  hashWithSalt :: Int -> ListGateways -> Int
hashWithSalt Int
_salt ListGateways' {Maybe Natural
Maybe Text
marker :: Maybe Text
limit :: Maybe Natural
$sel:marker:ListGateways' :: ListGateways -> Maybe Text
$sel:limit:ListGateways' :: ListGateways -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
limit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
marker

instance Prelude.NFData ListGateways where
  rnf :: ListGateways -> ()
rnf ListGateways' {Maybe Natural
Maybe Text
marker :: Maybe Text
limit :: Maybe Natural
$sel:marker:ListGateways' :: ListGateways -> Maybe Text
$sel:limit:ListGateways' :: ListGateways -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
limit seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
marker

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
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"StorageGateway_20130630.ListGateways" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListGateways where
  toJSON :: ListGateways -> Value
toJSON ListGateways' {Maybe Natural
Maybe Text
marker :: Maybe Text
limit :: Maybe Natural
$sel:marker:ListGateways' :: ListGateways -> Maybe Text
$sel:limit:ListGateways' :: ListGateways -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Limit" 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
limit,
            (Key
"Marker" 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
marker
          ]
      )

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

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

-- | /See:/ 'newListGatewaysResponse' smart constructor.
data ListGatewaysResponse = ListGatewaysResponse'
  { -- | An array of GatewayInfo objects.
    ListGatewaysResponse -> Maybe [GatewayInfo]
gateways :: Prelude.Maybe [GatewayInfo],
    -- | Use the marker in your next request to fetch the next set of gateways in
    -- the list. If there are no more gateways to list, this field does not
    -- appear in the response.
    ListGatewaysResponse -> Maybe Text
marker :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListGatewaysResponse -> Int
httpStatus :: Prelude.Int
  }
  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:
--
-- 'gateways', 'listGatewaysResponse_gateways' - An array of GatewayInfo objects.
--
-- 'marker', 'listGatewaysResponse_marker' - Use the marker in your next request to fetch the next set of gateways in
-- the list. If there are no more gateways to list, this field does not
-- appear in the response.
--
-- 'httpStatus', 'listGatewaysResponse_httpStatus' - The response's http status code.
newListGatewaysResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListGatewaysResponse
newListGatewaysResponse :: Int -> ListGatewaysResponse
newListGatewaysResponse Int
pHttpStatus_ =
  ListGatewaysResponse'
    { $sel:gateways:ListGatewaysResponse' :: Maybe [GatewayInfo]
gateways = forall a. Maybe a
Prelude.Nothing,
      $sel:marker:ListGatewaysResponse' :: Maybe Text
marker = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListGatewaysResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of GatewayInfo objects.
listGatewaysResponse_gateways :: Lens.Lens' ListGatewaysResponse (Prelude.Maybe [GatewayInfo])
listGatewaysResponse_gateways :: Lens' ListGatewaysResponse (Maybe [GatewayInfo])
listGatewaysResponse_gateways = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGatewaysResponse' {Maybe [GatewayInfo]
gateways :: Maybe [GatewayInfo]
$sel:gateways:ListGatewaysResponse' :: ListGatewaysResponse -> Maybe [GatewayInfo]
gateways} -> Maybe [GatewayInfo]
gateways) (\s :: ListGatewaysResponse
s@ListGatewaysResponse' {} Maybe [GatewayInfo]
a -> ListGatewaysResponse
s {$sel:gateways:ListGatewaysResponse' :: Maybe [GatewayInfo]
gateways = Maybe [GatewayInfo]
a} :: ListGatewaysResponse) 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

-- | Use the marker in your next request to fetch the next set of gateways in
-- the list. If there are no more gateways to list, this field does not
-- appear in the response.
listGatewaysResponse_marker :: Lens.Lens' ListGatewaysResponse (Prelude.Maybe Prelude.Text)
listGatewaysResponse_marker :: Lens' ListGatewaysResponse (Maybe Text)
listGatewaysResponse_marker = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListGatewaysResponse' {Maybe Text
marker :: Maybe Text
$sel:marker:ListGatewaysResponse' :: ListGatewaysResponse -> Maybe Text
marker} -> Maybe Text
marker) (\s :: ListGatewaysResponse
s@ListGatewaysResponse' {} Maybe Text
a -> ListGatewaysResponse
s {$sel:marker:ListGatewaysResponse' :: Maybe Text
marker = 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)

instance Prelude.NFData ListGatewaysResponse where
  rnf :: ListGatewaysResponse -> ()
rnf ListGatewaysResponse' {Int
Maybe [GatewayInfo]
Maybe Text
httpStatus :: Int
marker :: Maybe Text
gateways :: Maybe [GatewayInfo]
$sel:httpStatus:ListGatewaysResponse' :: ListGatewaysResponse -> Int
$sel:marker:ListGatewaysResponse' :: ListGatewaysResponse -> Maybe Text
$sel:gateways:ListGatewaysResponse' :: ListGatewaysResponse -> Maybe [GatewayInfo]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [GatewayInfo]
gateways
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
marker
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus