{-# 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.GetDomains
-- 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 a list of all domains in the user\'s account.
--
-- This operation returns paginated results.
module Amazonka.Lightsail.GetDomains
  ( -- * Creating a Request
    GetDomains (..),
    newGetDomains,

    -- * Request Lenses
    getDomains_pageToken,

    -- * Destructuring the Response
    GetDomainsResponse (..),
    newGetDomainsResponse,

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

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

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

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

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

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

-- | /See:/ 'newGetDomainsResponse' smart constructor.
data GetDomainsResponse = GetDomainsResponse'
  { -- | An array of key-value pairs containing information about each of the
    -- domain entries in the user\'s account.
    GetDomainsResponse -> Maybe [Domain]
domains :: Prelude.Maybe [Domain],
    -- | 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 @GetDomains@ request
    -- and specify the next page token using the @pageToken@ parameter.
    GetDomainsResponse -> Maybe Text
nextPageToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetDomainsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetDomainsResponse -> GetDomainsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDomainsResponse -> GetDomainsResponse -> Bool
$c/= :: GetDomainsResponse -> GetDomainsResponse -> Bool
== :: GetDomainsResponse -> GetDomainsResponse -> Bool
$c== :: GetDomainsResponse -> GetDomainsResponse -> Bool
Prelude.Eq, ReadPrec [GetDomainsResponse]
ReadPrec GetDomainsResponse
Int -> ReadS GetDomainsResponse
ReadS [GetDomainsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDomainsResponse]
$creadListPrec :: ReadPrec [GetDomainsResponse]
readPrec :: ReadPrec GetDomainsResponse
$creadPrec :: ReadPrec GetDomainsResponse
readList :: ReadS [GetDomainsResponse]
$creadList :: ReadS [GetDomainsResponse]
readsPrec :: Int -> ReadS GetDomainsResponse
$creadsPrec :: Int -> ReadS GetDomainsResponse
Prelude.Read, Int -> GetDomainsResponse -> ShowS
[GetDomainsResponse] -> ShowS
GetDomainsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDomainsResponse] -> ShowS
$cshowList :: [GetDomainsResponse] -> ShowS
show :: GetDomainsResponse -> String
$cshow :: GetDomainsResponse -> String
showsPrec :: Int -> GetDomainsResponse -> ShowS
$cshowsPrec :: Int -> GetDomainsResponse -> ShowS
Prelude.Show, forall x. Rep GetDomainsResponse x -> GetDomainsResponse
forall x. GetDomainsResponse -> Rep GetDomainsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDomainsResponse x -> GetDomainsResponse
$cfrom :: forall x. GetDomainsResponse -> Rep GetDomainsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetDomainsResponse' 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:
--
-- 'domains', 'getDomainsResponse_domains' - An array of key-value pairs containing information about each of the
-- domain entries in the user\'s account.
--
-- 'nextPageToken', 'getDomainsResponse_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 @GetDomains@ request
-- and specify the next page token using the @pageToken@ parameter.
--
-- 'httpStatus', 'getDomainsResponse_httpStatus' - The response's http status code.
newGetDomainsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDomainsResponse
newGetDomainsResponse :: Int -> GetDomainsResponse
newGetDomainsResponse Int
pHttpStatus_ =
  GetDomainsResponse'
    { $sel:domains:GetDomainsResponse' :: Maybe [Domain]
domains = forall a. Maybe a
Prelude.Nothing,
      $sel:nextPageToken:GetDomainsResponse' :: Maybe Text
nextPageToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDomainsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of key-value pairs containing information about each of the
-- domain entries in the user\'s account.
getDomainsResponse_domains :: Lens.Lens' GetDomainsResponse (Prelude.Maybe [Domain])
getDomainsResponse_domains :: Lens' GetDomainsResponse (Maybe [Domain])
getDomainsResponse_domains = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDomainsResponse' {Maybe [Domain]
domains :: Maybe [Domain]
$sel:domains:GetDomainsResponse' :: GetDomainsResponse -> Maybe [Domain]
domains} -> Maybe [Domain]
domains) (\s :: GetDomainsResponse
s@GetDomainsResponse' {} Maybe [Domain]
a -> GetDomainsResponse
s {$sel:domains:GetDomainsResponse' :: Maybe [Domain]
domains = Maybe [Domain]
a} :: GetDomainsResponse) 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 @GetDomains@ request
-- and specify the next page token using the @pageToken@ parameter.
getDomainsResponse_nextPageToken :: Lens.Lens' GetDomainsResponse (Prelude.Maybe Prelude.Text)
getDomainsResponse_nextPageToken :: Lens' GetDomainsResponse (Maybe Text)
getDomainsResponse_nextPageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDomainsResponse' {Maybe Text
nextPageToken :: Maybe Text
$sel:nextPageToken:GetDomainsResponse' :: GetDomainsResponse -> Maybe Text
nextPageToken} -> Maybe Text
nextPageToken) (\s :: GetDomainsResponse
s@GetDomainsResponse' {} Maybe Text
a -> GetDomainsResponse
s {$sel:nextPageToken:GetDomainsResponse' :: Maybe Text
nextPageToken = Maybe Text
a} :: GetDomainsResponse)

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

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