{-# 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.Lightsail.GetInstances
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns information about all Amazon Lightsail virtual private servers,
-- or /instances/.
--
-- This operation returns paginated results.
module Amazonka.Lightsail.GetInstances
  ( -- * Creating a Request
    GetInstances (..),
    newGetInstances,

    -- * Request Lenses
    getInstances_pageToken,

    -- * Destructuring the Response
    GetInstancesResponse (..),
    newGetInstancesResponse,

    -- * Response Lenses
    getInstancesResponse_instances,
    getInstancesResponse_nextPageToken,
    getInstancesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetInstances' smart constructor.
data GetInstances = GetInstances'
  { -- | The token to advance to the next page of results from your request.
    --
    -- To get a page token, perform an initial @GetInstances@ request. If your
    -- results are paginated, the response will return a next page token that
    -- you can specify as the page token in a subsequent request.
    GetInstances -> Maybe Text
pageToken :: Prelude.Maybe Prelude.Text
  }
  deriving (GetInstances -> GetInstances -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInstances -> GetInstances -> Bool
$c/= :: GetInstances -> GetInstances -> Bool
== :: GetInstances -> GetInstances -> Bool
$c== :: GetInstances -> GetInstances -> Bool
Prelude.Eq, ReadPrec [GetInstances]
ReadPrec GetInstances
Int -> ReadS GetInstances
ReadS [GetInstances]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInstances]
$creadListPrec :: ReadPrec [GetInstances]
readPrec :: ReadPrec GetInstances
$creadPrec :: ReadPrec GetInstances
readList :: ReadS [GetInstances]
$creadList :: ReadS [GetInstances]
readsPrec :: Int -> ReadS GetInstances
$creadsPrec :: Int -> ReadS GetInstances
Prelude.Read, Int -> GetInstances -> ShowS
[GetInstances] -> ShowS
GetInstances -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInstances] -> ShowS
$cshowList :: [GetInstances] -> ShowS
show :: GetInstances -> String
$cshow :: GetInstances -> String
showsPrec :: Int -> GetInstances -> ShowS
$cshowsPrec :: Int -> GetInstances -> ShowS
Prelude.Show, forall x. Rep GetInstances x -> GetInstances
forall x. GetInstances -> Rep GetInstances x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInstances x -> GetInstances
$cfrom :: forall x. GetInstances -> Rep GetInstances x
Prelude.Generic)

-- |
-- Create a value of 'GetInstances' 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:
--
-- 'pageToken', 'getInstances_pageToken' - The token to advance to the next page of results from your request.
--
-- To get a page token, perform an initial @GetInstances@ request. If your
-- results are paginated, the response will return a next page token that
-- you can specify as the page token in a subsequent request.
newGetInstances ::
  GetInstances
newGetInstances :: GetInstances
newGetInstances =
  GetInstances' {$sel:pageToken:GetInstances' :: Maybe Text
pageToken = forall a. Maybe a
Prelude.Nothing}

-- | The token to advance to the next page of results from your request.
--
-- To get a page token, perform an initial @GetInstances@ request. If your
-- results are paginated, the response will return a next page token that
-- you can specify as the page token in a subsequent request.
getInstances_pageToken :: Lens.Lens' GetInstances (Prelude.Maybe Prelude.Text)
getInstances_pageToken :: Lens' GetInstances (Maybe Text)
getInstances_pageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstances' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetInstances' :: GetInstances -> Maybe Text
pageToken} -> Maybe Text
pageToken) (\s :: GetInstances
s@GetInstances' {} Maybe Text
a -> GetInstances
s {$sel:pageToken:GetInstances' :: Maybe Text
pageToken = Maybe Text
a} :: GetInstances)

instance Core.AWSPager GetInstances where
  page :: GetInstances -> AWSResponse GetInstances -> Maybe GetInstances
page GetInstances
rq AWSResponse GetInstances
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetInstances
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetInstancesResponse (Maybe Text)
getInstancesResponse_nextPageToken
            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 GetInstances
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetInstancesResponse (Maybe [Instance])
getInstancesResponse_instances
            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.$ GetInstances
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' GetInstances (Maybe Text)
getInstances_pageToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetInstances
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetInstancesResponse (Maybe Text)
getInstancesResponse_nextPageToken
          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 GetInstances where
  type AWSResponse GetInstances = GetInstancesResponse
  request :: (Service -> Service) -> GetInstances -> Request GetInstances
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 GetInstances
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetInstances)))
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 [Instance] -> Maybe Text -> Int -> GetInstancesResponse
GetInstancesResponse'
            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
"instances" 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
"nextPageToken")
            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 GetInstances where
  hashWithSalt :: Int -> GetInstances -> Int
hashWithSalt Int
_salt GetInstances' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetInstances' :: GetInstances -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
pageToken

instance Prelude.NFData GetInstances where
  rnf :: GetInstances -> ()
rnf GetInstances' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetInstances' :: GetInstances -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
pageToken

instance Data.ToHeaders GetInstances where
  toHeaders :: GetInstances -> 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
"Lightsail_20161128.GetInstances" ::
                          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 GetInstances where
  toJSON :: GetInstances -> Value
toJSON GetInstances' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetInstances' :: GetInstances -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"pageToken" 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
pageToken]
      )

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

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

-- | /See:/ 'newGetInstancesResponse' smart constructor.
data GetInstancesResponse = GetInstancesResponse'
  { -- | An array of key-value pairs containing information about your instances.
    GetInstancesResponse -> Maybe [Instance]
instances :: Prelude.Maybe [Instance],
    -- | The token to advance to the next page of results from your request.
    --
    -- A next page token is not returned if there are no more results to
    -- display.
    --
    -- To get the next page of results, perform another @GetInstances@ request
    -- and specify the next page token using the @pageToken@ parameter.
    GetInstancesResponse -> Maybe Text
nextPageToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetInstancesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetInstancesResponse -> GetInstancesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInstancesResponse -> GetInstancesResponse -> Bool
$c/= :: GetInstancesResponse -> GetInstancesResponse -> Bool
== :: GetInstancesResponse -> GetInstancesResponse -> Bool
$c== :: GetInstancesResponse -> GetInstancesResponse -> Bool
Prelude.Eq, ReadPrec [GetInstancesResponse]
ReadPrec GetInstancesResponse
Int -> ReadS GetInstancesResponse
ReadS [GetInstancesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInstancesResponse]
$creadListPrec :: ReadPrec [GetInstancesResponse]
readPrec :: ReadPrec GetInstancesResponse
$creadPrec :: ReadPrec GetInstancesResponse
readList :: ReadS [GetInstancesResponse]
$creadList :: ReadS [GetInstancesResponse]
readsPrec :: Int -> ReadS GetInstancesResponse
$creadsPrec :: Int -> ReadS GetInstancesResponse
Prelude.Read, Int -> GetInstancesResponse -> ShowS
[GetInstancesResponse] -> ShowS
GetInstancesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInstancesResponse] -> ShowS
$cshowList :: [GetInstancesResponse] -> ShowS
show :: GetInstancesResponse -> String
$cshow :: GetInstancesResponse -> String
showsPrec :: Int -> GetInstancesResponse -> ShowS
$cshowsPrec :: Int -> GetInstancesResponse -> ShowS
Prelude.Show, forall x. Rep GetInstancesResponse x -> GetInstancesResponse
forall x. GetInstancesResponse -> Rep GetInstancesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInstancesResponse x -> GetInstancesResponse
$cfrom :: forall x. GetInstancesResponse -> Rep GetInstancesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetInstancesResponse' 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:
--
-- 'instances', 'getInstancesResponse_instances' - An array of key-value pairs containing information about your instances.
--
-- 'nextPageToken', 'getInstancesResponse_nextPageToken' - The token to advance to the next page of results from your request.
--
-- A next page token is not returned if there are no more results to
-- display.
--
-- To get the next page of results, perform another @GetInstances@ request
-- and specify the next page token using the @pageToken@ parameter.
--
-- 'httpStatus', 'getInstancesResponse_httpStatus' - The response's http status code.
newGetInstancesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetInstancesResponse
newGetInstancesResponse :: Int -> GetInstancesResponse
newGetInstancesResponse Int
pHttpStatus_ =
  GetInstancesResponse'
    { $sel:instances:GetInstancesResponse' :: Maybe [Instance]
instances = forall a. Maybe a
Prelude.Nothing,
      $sel:nextPageToken:GetInstancesResponse' :: Maybe Text
nextPageToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetInstancesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of key-value pairs containing information about your instances.
getInstancesResponse_instances :: Lens.Lens' GetInstancesResponse (Prelude.Maybe [Instance])
getInstancesResponse_instances :: Lens' GetInstancesResponse (Maybe [Instance])
getInstancesResponse_instances = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstancesResponse' {Maybe [Instance]
instances :: Maybe [Instance]
$sel:instances:GetInstancesResponse' :: GetInstancesResponse -> Maybe [Instance]
instances} -> Maybe [Instance]
instances) (\s :: GetInstancesResponse
s@GetInstancesResponse' {} Maybe [Instance]
a -> GetInstancesResponse
s {$sel:instances:GetInstancesResponse' :: Maybe [Instance]
instances = Maybe [Instance]
a} :: GetInstancesResponse) 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 advance to the next page of results from your request.
--
-- A next page token is not returned if there are no more results to
-- display.
--
-- To get the next page of results, perform another @GetInstances@ request
-- and specify the next page token using the @pageToken@ parameter.
getInstancesResponse_nextPageToken :: Lens.Lens' GetInstancesResponse (Prelude.Maybe Prelude.Text)
getInstancesResponse_nextPageToken :: Lens' GetInstancesResponse (Maybe Text)
getInstancesResponse_nextPageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstancesResponse' {Maybe Text
nextPageToken :: Maybe Text
$sel:nextPageToken:GetInstancesResponse' :: GetInstancesResponse -> Maybe Text
nextPageToken} -> Maybe Text
nextPageToken) (\s :: GetInstancesResponse
s@GetInstancesResponse' {} Maybe Text
a -> GetInstancesResponse
s {$sel:nextPageToken:GetInstancesResponse' :: Maybe Text
nextPageToken = Maybe Text
a} :: GetInstancesResponse)

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

instance Prelude.NFData GetInstancesResponse where
  rnf :: GetInstancesResponse -> ()
rnf GetInstancesResponse' {Int
Maybe [Instance]
Maybe Text
httpStatus :: Int
nextPageToken :: Maybe Text
instances :: Maybe [Instance]
$sel:httpStatus:GetInstancesResponse' :: GetInstancesResponse -> Int
$sel:nextPageToken:GetInstancesResponse' :: GetInstancesResponse -> Maybe Text
$sel:instances:GetInstancesResponse' :: GetInstancesResponse -> Maybe [Instance]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Instance]
instances
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextPageToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus