{-# 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.LicenseManagerUserSubscriptions.ListInstances
-- 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 the EC2 instances providing user-based subscriptions.
--
-- This operation returns paginated results.
module Amazonka.LicenseManagerUserSubscriptions.ListInstances
  ( -- * Creating a Request
    ListInstances (..),
    newListInstances,

    -- * Request Lenses
    listInstances_filters,
    listInstances_maxResults,
    listInstances_nextToken,

    -- * Destructuring the Response
    ListInstancesResponse (..),
    newListInstancesResponse,

    -- * Response Lenses
    listInstancesResponse_instanceSummaries,
    listInstancesResponse_nextToken,
    listInstancesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListInstances' smart constructor.
data ListInstances = ListInstances'
  { -- | An array of structures that you can use to filter the results to those
    -- that match one or more sets of key-value pairs that you specify.
    ListInstances -> Maybe [Filter]
filters :: Prelude.Maybe [Filter],
    -- | Maximum number of results to return in a single call.
    ListInstances -> Maybe Int
maxResults :: Prelude.Maybe Prelude.Int,
    -- | Token for the next set of results.
    ListInstances -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListInstances -> ListInstances -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListInstances -> ListInstances -> Bool
$c/= :: ListInstances -> ListInstances -> Bool
== :: ListInstances -> ListInstances -> Bool
$c== :: ListInstances -> ListInstances -> Bool
Prelude.Eq, ReadPrec [ListInstances]
ReadPrec ListInstances
Int -> ReadS ListInstances
ReadS [ListInstances]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListInstances]
$creadListPrec :: ReadPrec [ListInstances]
readPrec :: ReadPrec ListInstances
$creadPrec :: ReadPrec ListInstances
readList :: ReadS [ListInstances]
$creadList :: ReadS [ListInstances]
readsPrec :: Int -> ReadS ListInstances
$creadsPrec :: Int -> ReadS ListInstances
Prelude.Read, Int -> ListInstances -> ShowS
[ListInstances] -> ShowS
ListInstances -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListInstances] -> ShowS
$cshowList :: [ListInstances] -> ShowS
show :: ListInstances -> String
$cshow :: ListInstances -> String
showsPrec :: Int -> ListInstances -> ShowS
$cshowsPrec :: Int -> ListInstances -> ShowS
Prelude.Show, forall x. Rep ListInstances x -> ListInstances
forall x. ListInstances -> Rep ListInstances x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListInstances x -> ListInstances
$cfrom :: forall x. ListInstances -> Rep ListInstances x
Prelude.Generic)

-- |
-- Create a value of 'ListInstances' 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:
--
-- 'filters', 'listInstances_filters' - An array of structures that you can use to filter the results to those
-- that match one or more sets of key-value pairs that you specify.
--
-- 'maxResults', 'listInstances_maxResults' - Maximum number of results to return in a single call.
--
-- 'nextToken', 'listInstances_nextToken' - Token for the next set of results.
newListInstances ::
  ListInstances
newListInstances :: ListInstances
newListInstances =
  ListInstances'
    { $sel:filters:ListInstances' :: Maybe [Filter]
filters = forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListInstances' :: Maybe Int
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListInstances' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | An array of structures that you can use to filter the results to those
-- that match one or more sets of key-value pairs that you specify.
listInstances_filters :: Lens.Lens' ListInstances (Prelude.Maybe [Filter])
listInstances_filters :: Lens' ListInstances (Maybe [Filter])
listInstances_filters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListInstances' {Maybe [Filter]
filters :: Maybe [Filter]
$sel:filters:ListInstances' :: ListInstances -> Maybe [Filter]
filters} -> Maybe [Filter]
filters) (\s :: ListInstances
s@ListInstances' {} Maybe [Filter]
a -> ListInstances
s {$sel:filters:ListInstances' :: Maybe [Filter]
filters = Maybe [Filter]
a} :: ListInstances) 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

-- | Maximum number of results to return in a single call.
listInstances_maxResults :: Lens.Lens' ListInstances (Prelude.Maybe Prelude.Int)
listInstances_maxResults :: Lens' ListInstances (Maybe Int)
listInstances_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListInstances' {Maybe Int
maxResults :: Maybe Int
$sel:maxResults:ListInstances' :: ListInstances -> Maybe Int
maxResults} -> Maybe Int
maxResults) (\s :: ListInstances
s@ListInstances' {} Maybe Int
a -> ListInstances
s {$sel:maxResults:ListInstances' :: Maybe Int
maxResults = Maybe Int
a} :: ListInstances)

-- | Token for the next set of results.
listInstances_nextToken :: Lens.Lens' ListInstances (Prelude.Maybe Prelude.Text)
listInstances_nextToken :: Lens' ListInstances (Maybe Text)
listInstances_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListInstances' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListInstances' :: ListInstances -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListInstances
s@ListInstances' {} Maybe Text
a -> ListInstances
s {$sel:nextToken:ListInstances' :: Maybe Text
nextToken = Maybe Text
a} :: ListInstances)

instance Core.AWSPager ListInstances where
  page :: ListInstances -> AWSResponse ListInstances -> Maybe ListInstances
page ListInstances
rq AWSResponse ListInstances
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListInstances
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListInstancesResponse (Maybe Text)
listInstancesResponse_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 ListInstances
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListInstancesResponse (Maybe [InstanceSummary])
listInstancesResponse_instanceSummaries
            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.$ ListInstances
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListInstances (Maybe Text)
listInstances_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListInstances
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListInstancesResponse (Maybe Text)
listInstancesResponse_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 ListInstances where
  type
    AWSResponse ListInstances =
      ListInstancesResponse
  request :: (Service -> Service) -> ListInstances -> Request ListInstances
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 ListInstances
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListInstances)))
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 [InstanceSummary]
-> Maybe Text -> Int -> ListInstancesResponse
ListInstancesResponse'
            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
"InstanceSummaries"
                            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 ListInstances where
  hashWithSalt :: Int -> ListInstances -> Int
hashWithSalt Int
_salt ListInstances' {Maybe Int
Maybe [Filter]
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Int
filters :: Maybe [Filter]
$sel:nextToken:ListInstances' :: ListInstances -> Maybe Text
$sel:maxResults:ListInstances' :: ListInstances -> Maybe Int
$sel:filters:ListInstances' :: ListInstances -> Maybe [Filter]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Filter]
filters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

instance Prelude.NFData ListInstances where
  rnf :: ListInstances -> ()
rnf ListInstances' {Maybe Int
Maybe [Filter]
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Int
filters :: Maybe [Filter]
$sel:nextToken:ListInstances' :: ListInstances -> Maybe Text
$sel:maxResults:ListInstances' :: ListInstances -> Maybe Int
$sel:filters:ListInstances' :: ListInstances -> Maybe [Filter]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Filter]
filters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken

instance Data.ToHeaders ListInstances where
  toHeaders :: ListInstances -> 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.ToJSON ListInstances where
  toJSON :: ListInstances -> Value
toJSON ListInstances' {Maybe Int
Maybe [Filter]
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Int
filters :: Maybe [Filter]
$sel:nextToken:ListInstances' :: ListInstances -> Maybe Text
$sel:maxResults:ListInstances' :: ListInstances -> Maybe Int
$sel:filters:ListInstances' :: ListInstances -> Maybe [Filter]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Filters" 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 [Filter]
filters,
            (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 Int
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 ListInstances where
  toPath :: ListInstances -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/instance/ListInstances"

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

-- | /See:/ 'newListInstancesResponse' smart constructor.
data ListInstancesResponse = ListInstancesResponse'
  { -- | Metadata that describes the list instances operation.
    ListInstancesResponse -> Maybe [InstanceSummary]
instanceSummaries :: Prelude.Maybe [InstanceSummary],
    -- | Token for the next set of results.
    ListInstancesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListInstancesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListInstancesResponse -> ListInstancesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListInstancesResponse -> ListInstancesResponse -> Bool
$c/= :: ListInstancesResponse -> ListInstancesResponse -> Bool
== :: ListInstancesResponse -> ListInstancesResponse -> Bool
$c== :: ListInstancesResponse -> ListInstancesResponse -> Bool
Prelude.Eq, ReadPrec [ListInstancesResponse]
ReadPrec ListInstancesResponse
Int -> ReadS ListInstancesResponse
ReadS [ListInstancesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListInstancesResponse]
$creadListPrec :: ReadPrec [ListInstancesResponse]
readPrec :: ReadPrec ListInstancesResponse
$creadPrec :: ReadPrec ListInstancesResponse
readList :: ReadS [ListInstancesResponse]
$creadList :: ReadS [ListInstancesResponse]
readsPrec :: Int -> ReadS ListInstancesResponse
$creadsPrec :: Int -> ReadS ListInstancesResponse
Prelude.Read, Int -> ListInstancesResponse -> ShowS
[ListInstancesResponse] -> ShowS
ListInstancesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListInstancesResponse] -> ShowS
$cshowList :: [ListInstancesResponse] -> ShowS
show :: ListInstancesResponse -> String
$cshow :: ListInstancesResponse -> String
showsPrec :: Int -> ListInstancesResponse -> ShowS
$cshowsPrec :: Int -> ListInstancesResponse -> ShowS
Prelude.Show, forall x. Rep ListInstancesResponse x -> ListInstancesResponse
forall x. ListInstancesResponse -> Rep ListInstancesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListInstancesResponse x -> ListInstancesResponse
$cfrom :: forall x. ListInstancesResponse -> Rep ListInstancesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListInstancesResponse' 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:
--
-- 'instanceSummaries', 'listInstancesResponse_instanceSummaries' - Metadata that describes the list instances operation.
--
-- 'nextToken', 'listInstancesResponse_nextToken' - Token for the next set of results.
--
-- 'httpStatus', 'listInstancesResponse_httpStatus' - The response's http status code.
newListInstancesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListInstancesResponse
newListInstancesResponse :: Int -> ListInstancesResponse
newListInstancesResponse Int
pHttpStatus_ =
  ListInstancesResponse'
    { $sel:instanceSummaries:ListInstancesResponse' :: Maybe [InstanceSummary]
instanceSummaries =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListInstancesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListInstancesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Metadata that describes the list instances operation.
listInstancesResponse_instanceSummaries :: Lens.Lens' ListInstancesResponse (Prelude.Maybe [InstanceSummary])
listInstancesResponse_instanceSummaries :: Lens' ListInstancesResponse (Maybe [InstanceSummary])
listInstancesResponse_instanceSummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListInstancesResponse' {Maybe [InstanceSummary]
instanceSummaries :: Maybe [InstanceSummary]
$sel:instanceSummaries:ListInstancesResponse' :: ListInstancesResponse -> Maybe [InstanceSummary]
instanceSummaries} -> Maybe [InstanceSummary]
instanceSummaries) (\s :: ListInstancesResponse
s@ListInstancesResponse' {} Maybe [InstanceSummary]
a -> ListInstancesResponse
s {$sel:instanceSummaries:ListInstancesResponse' :: Maybe [InstanceSummary]
instanceSummaries = Maybe [InstanceSummary]
a} :: ListInstancesResponse) 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

-- | Token for the next set of results.
listInstancesResponse_nextToken :: Lens.Lens' ListInstancesResponse (Prelude.Maybe Prelude.Text)
listInstancesResponse_nextToken :: Lens' ListInstancesResponse (Maybe Text)
listInstancesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListInstancesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListInstancesResponse' :: ListInstancesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListInstancesResponse
s@ListInstancesResponse' {} Maybe Text
a -> ListInstancesResponse
s {$sel:nextToken:ListInstancesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListInstancesResponse)

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

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