{-# 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.GetActiveNames
-- 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 the names of all active (not deleted) resources.
--
-- This operation returns paginated results.
module Amazonka.Lightsail.GetActiveNames
  ( -- * Creating a Request
    GetActiveNames (..),
    newGetActiveNames,

    -- * Request Lenses
    getActiveNames_pageToken,

    -- * Destructuring the Response
    GetActiveNamesResponse (..),
    newGetActiveNamesResponse,

    -- * Response Lenses
    getActiveNamesResponse_activeNames,
    getActiveNamesResponse_nextPageToken,
    getActiveNamesResponse_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:/ 'newGetActiveNames' smart constructor.
data GetActiveNames = GetActiveNames'
  { -- | The token to advance to the next page of results from your request.
    --
    -- To get a page token, perform an initial @GetActiveNames@ 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.
    GetActiveNames -> Maybe Text
pageToken :: Prelude.Maybe Prelude.Text
  }
  deriving (GetActiveNames -> GetActiveNames -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetActiveNames -> GetActiveNames -> Bool
$c/= :: GetActiveNames -> GetActiveNames -> Bool
== :: GetActiveNames -> GetActiveNames -> Bool
$c== :: GetActiveNames -> GetActiveNames -> Bool
Prelude.Eq, ReadPrec [GetActiveNames]
ReadPrec GetActiveNames
Int -> ReadS GetActiveNames
ReadS [GetActiveNames]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetActiveNames]
$creadListPrec :: ReadPrec [GetActiveNames]
readPrec :: ReadPrec GetActiveNames
$creadPrec :: ReadPrec GetActiveNames
readList :: ReadS [GetActiveNames]
$creadList :: ReadS [GetActiveNames]
readsPrec :: Int -> ReadS GetActiveNames
$creadsPrec :: Int -> ReadS GetActiveNames
Prelude.Read, Int -> GetActiveNames -> ShowS
[GetActiveNames] -> ShowS
GetActiveNames -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetActiveNames] -> ShowS
$cshowList :: [GetActiveNames] -> ShowS
show :: GetActiveNames -> String
$cshow :: GetActiveNames -> String
showsPrec :: Int -> GetActiveNames -> ShowS
$cshowsPrec :: Int -> GetActiveNames -> ShowS
Prelude.Show, forall x. Rep GetActiveNames x -> GetActiveNames
forall x. GetActiveNames -> Rep GetActiveNames x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetActiveNames x -> GetActiveNames
$cfrom :: forall x. GetActiveNames -> Rep GetActiveNames x
Prelude.Generic)

-- |
-- Create a value of 'GetActiveNames' 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', 'getActiveNames_pageToken' - The token to advance to the next page of results from your request.
--
-- To get a page token, perform an initial @GetActiveNames@ 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.
newGetActiveNames ::
  GetActiveNames
newGetActiveNames :: GetActiveNames
newGetActiveNames =
  GetActiveNames' {$sel:pageToken:GetActiveNames' :: 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 @GetActiveNames@ 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.
getActiveNames_pageToken :: Lens.Lens' GetActiveNames (Prelude.Maybe Prelude.Text)
getActiveNames_pageToken :: Lens' GetActiveNames (Maybe Text)
getActiveNames_pageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetActiveNames' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetActiveNames' :: GetActiveNames -> Maybe Text
pageToken} -> Maybe Text
pageToken) (\s :: GetActiveNames
s@GetActiveNames' {} Maybe Text
a -> GetActiveNames
s {$sel:pageToken:GetActiveNames' :: Maybe Text
pageToken = Maybe Text
a} :: GetActiveNames)

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

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

instance Data.ToHeaders GetActiveNames where
  toHeaders :: GetActiveNames -> 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.GetActiveNames" ::
                          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 GetActiveNames where
  toJSON :: GetActiveNames -> Value
toJSON GetActiveNames' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetActiveNames' :: GetActiveNames -> 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 GetActiveNames where
  toPath :: GetActiveNames -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newGetActiveNamesResponse' smart constructor.
data GetActiveNamesResponse = GetActiveNamesResponse'
  { -- | The list of active names returned by the get active names request.
    GetActiveNamesResponse -> Maybe [Text]
activeNames :: Prelude.Maybe [Prelude.Text],
    -- | 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 @GetActiveNames@
    -- request and specify the next page token using the @pageToken@ parameter.
    GetActiveNamesResponse -> Maybe Text
nextPageToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetActiveNamesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetActiveNamesResponse -> GetActiveNamesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetActiveNamesResponse -> GetActiveNamesResponse -> Bool
$c/= :: GetActiveNamesResponse -> GetActiveNamesResponse -> Bool
== :: GetActiveNamesResponse -> GetActiveNamesResponse -> Bool
$c== :: GetActiveNamesResponse -> GetActiveNamesResponse -> Bool
Prelude.Eq, ReadPrec [GetActiveNamesResponse]
ReadPrec GetActiveNamesResponse
Int -> ReadS GetActiveNamesResponse
ReadS [GetActiveNamesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetActiveNamesResponse]
$creadListPrec :: ReadPrec [GetActiveNamesResponse]
readPrec :: ReadPrec GetActiveNamesResponse
$creadPrec :: ReadPrec GetActiveNamesResponse
readList :: ReadS [GetActiveNamesResponse]
$creadList :: ReadS [GetActiveNamesResponse]
readsPrec :: Int -> ReadS GetActiveNamesResponse
$creadsPrec :: Int -> ReadS GetActiveNamesResponse
Prelude.Read, Int -> GetActiveNamesResponse -> ShowS
[GetActiveNamesResponse] -> ShowS
GetActiveNamesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetActiveNamesResponse] -> ShowS
$cshowList :: [GetActiveNamesResponse] -> ShowS
show :: GetActiveNamesResponse -> String
$cshow :: GetActiveNamesResponse -> String
showsPrec :: Int -> GetActiveNamesResponse -> ShowS
$cshowsPrec :: Int -> GetActiveNamesResponse -> ShowS
Prelude.Show, forall x. Rep GetActiveNamesResponse x -> GetActiveNamesResponse
forall x. GetActiveNamesResponse -> Rep GetActiveNamesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetActiveNamesResponse x -> GetActiveNamesResponse
$cfrom :: forall x. GetActiveNamesResponse -> Rep GetActiveNamesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetActiveNamesResponse' 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:
--
-- 'activeNames', 'getActiveNamesResponse_activeNames' - The list of active names returned by the get active names request.
--
-- 'nextPageToken', 'getActiveNamesResponse_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 @GetActiveNames@
-- request and specify the next page token using the @pageToken@ parameter.
--
-- 'httpStatus', 'getActiveNamesResponse_httpStatus' - The response's http status code.
newGetActiveNamesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetActiveNamesResponse
newGetActiveNamesResponse :: Int -> GetActiveNamesResponse
newGetActiveNamesResponse Int
pHttpStatus_ =
  GetActiveNamesResponse'
    { $sel:activeNames:GetActiveNamesResponse' :: Maybe [Text]
activeNames =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextPageToken:GetActiveNamesResponse' :: Maybe Text
nextPageToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetActiveNamesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of active names returned by the get active names request.
getActiveNamesResponse_activeNames :: Lens.Lens' GetActiveNamesResponse (Prelude.Maybe [Prelude.Text])
getActiveNamesResponse_activeNames :: Lens' GetActiveNamesResponse (Maybe [Text])
getActiveNamesResponse_activeNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetActiveNamesResponse' {Maybe [Text]
activeNames :: Maybe [Text]
$sel:activeNames:GetActiveNamesResponse' :: GetActiveNamesResponse -> Maybe [Text]
activeNames} -> Maybe [Text]
activeNames) (\s :: GetActiveNamesResponse
s@GetActiveNamesResponse' {} Maybe [Text]
a -> GetActiveNamesResponse
s {$sel:activeNames:GetActiveNamesResponse' :: Maybe [Text]
activeNames = Maybe [Text]
a} :: GetActiveNamesResponse) 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 @GetActiveNames@
-- request and specify the next page token using the @pageToken@ parameter.
getActiveNamesResponse_nextPageToken :: Lens.Lens' GetActiveNamesResponse (Prelude.Maybe Prelude.Text)
getActiveNamesResponse_nextPageToken :: Lens' GetActiveNamesResponse (Maybe Text)
getActiveNamesResponse_nextPageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetActiveNamesResponse' {Maybe Text
nextPageToken :: Maybe Text
$sel:nextPageToken:GetActiveNamesResponse' :: GetActiveNamesResponse -> Maybe Text
nextPageToken} -> Maybe Text
nextPageToken) (\s :: GetActiveNamesResponse
s@GetActiveNamesResponse' {} Maybe Text
a -> GetActiveNamesResponse
s {$sel:nextPageToken:GetActiveNamesResponse' :: Maybe Text
nextPageToken = Maybe Text
a} :: GetActiveNamesResponse)

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

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