{-# 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.MigrationHubReFactorSpaces.ListServices
-- 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 all the Amazon Web Services Migration Hub Refactor Spaces services
-- within an application.
--
-- This operation returns paginated results.
module Amazonka.MigrationHubReFactorSpaces.ListServices
  ( -- * Creating a Request
    ListServices (..),
    newListServices,

    -- * Request Lenses
    listServices_maxResults,
    listServices_nextToken,
    listServices_applicationIdentifier,
    listServices_environmentIdentifier,

    -- * Destructuring the Response
    ListServicesResponse (..),
    newListServicesResponse,

    -- * Response Lenses
    listServicesResponse_nextToken,
    listServicesResponse_serviceSummaryList,
    listServicesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListServices' smart constructor.
data ListServices = ListServices'
  { -- | The maximum number of results to return with a single call. To retrieve
    -- the remaining results, make another call with the returned @nextToken@
    -- value.
    ListServices -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token for the next page of results.
    ListServices -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The ID of the application.
    ListServices -> Text
applicationIdentifier :: Prelude.Text,
    -- | The ID of the environment.
    ListServices -> Text
environmentIdentifier :: Prelude.Text
  }
  deriving (ListServices -> ListServices -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListServices -> ListServices -> Bool
$c/= :: ListServices -> ListServices -> Bool
== :: ListServices -> ListServices -> Bool
$c== :: ListServices -> ListServices -> Bool
Prelude.Eq, ReadPrec [ListServices]
ReadPrec ListServices
Int -> ReadS ListServices
ReadS [ListServices]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListServices]
$creadListPrec :: ReadPrec [ListServices]
readPrec :: ReadPrec ListServices
$creadPrec :: ReadPrec ListServices
readList :: ReadS [ListServices]
$creadList :: ReadS [ListServices]
readsPrec :: Int -> ReadS ListServices
$creadsPrec :: Int -> ReadS ListServices
Prelude.Read, Int -> ListServices -> ShowS
[ListServices] -> ShowS
ListServices -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListServices] -> ShowS
$cshowList :: [ListServices] -> ShowS
show :: ListServices -> String
$cshow :: ListServices -> String
showsPrec :: Int -> ListServices -> ShowS
$cshowsPrec :: Int -> ListServices -> ShowS
Prelude.Show, forall x. Rep ListServices x -> ListServices
forall x. ListServices -> Rep ListServices x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListServices x -> ListServices
$cfrom :: forall x. ListServices -> Rep ListServices x
Prelude.Generic)

-- |
-- Create a value of 'ListServices' 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:
--
-- 'maxResults', 'listServices_maxResults' - The maximum number of results to return with a single call. To retrieve
-- the remaining results, make another call with the returned @nextToken@
-- value.
--
-- 'nextToken', 'listServices_nextToken' - The token for the next page of results.
--
-- 'applicationIdentifier', 'listServices_applicationIdentifier' - The ID of the application.
--
-- 'environmentIdentifier', 'listServices_environmentIdentifier' - The ID of the environment.
newListServices ::
  -- | 'applicationIdentifier'
  Prelude.Text ->
  -- | 'environmentIdentifier'
  Prelude.Text ->
  ListServices
newListServices :: Text -> Text -> ListServices
newListServices
  Text
pApplicationIdentifier_
  Text
pEnvironmentIdentifier_ =
    ListServices'
      { $sel:maxResults:ListServices' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
        $sel:nextToken:ListServices' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
        $sel:applicationIdentifier:ListServices' :: Text
applicationIdentifier = Text
pApplicationIdentifier_,
        $sel:environmentIdentifier:ListServices' :: Text
environmentIdentifier = Text
pEnvironmentIdentifier_
      }

-- | The maximum number of results to return with a single call. To retrieve
-- the remaining results, make another call with the returned @nextToken@
-- value.
listServices_maxResults :: Lens.Lens' ListServices (Prelude.Maybe Prelude.Natural)
listServices_maxResults :: Lens' ListServices (Maybe Natural)
listServices_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServices' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListServices' :: ListServices -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListServices
s@ListServices' {} Maybe Natural
a -> ListServices
s {$sel:maxResults:ListServices' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListServices)

-- | The token for the next page of results.
listServices_nextToken :: Lens.Lens' ListServices (Prelude.Maybe Prelude.Text)
listServices_nextToken :: Lens' ListServices (Maybe Text)
listServices_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServices' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListServices' :: ListServices -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListServices
s@ListServices' {} Maybe Text
a -> ListServices
s {$sel:nextToken:ListServices' :: Maybe Text
nextToken = Maybe Text
a} :: ListServices)

-- | The ID of the application.
listServices_applicationIdentifier :: Lens.Lens' ListServices Prelude.Text
listServices_applicationIdentifier :: Lens' ListServices Text
listServices_applicationIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServices' {Text
applicationIdentifier :: Text
$sel:applicationIdentifier:ListServices' :: ListServices -> Text
applicationIdentifier} -> Text
applicationIdentifier) (\s :: ListServices
s@ListServices' {} Text
a -> ListServices
s {$sel:applicationIdentifier:ListServices' :: Text
applicationIdentifier = Text
a} :: ListServices)

-- | The ID of the environment.
listServices_environmentIdentifier :: Lens.Lens' ListServices Prelude.Text
listServices_environmentIdentifier :: Lens' ListServices Text
listServices_environmentIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServices' {Text
environmentIdentifier :: Text
$sel:environmentIdentifier:ListServices' :: ListServices -> Text
environmentIdentifier} -> Text
environmentIdentifier) (\s :: ListServices
s@ListServices' {} Text
a -> ListServices
s {$sel:environmentIdentifier:ListServices' :: Text
environmentIdentifier = Text
a} :: ListServices)

instance Core.AWSPager ListServices where
  page :: ListServices -> AWSResponse ListServices -> Maybe ListServices
page ListServices
rq AWSResponse ListServices
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListServices
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListServicesResponse (Maybe Text)
listServicesResponse_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 ListServices
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListServicesResponse (Maybe [ServiceSummary])
listServicesResponse_serviceSummaryList
            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.$ ListServices
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListServices (Maybe Text)
listServices_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListServices
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListServicesResponse (Maybe Text)
listServicesResponse_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 ListServices where
  type AWSResponse ListServices = ListServicesResponse
  request :: (Service -> Service) -> ListServices -> Request ListServices
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListServices
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListServices)))
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 [ServiceSummary] -> Int -> ListServicesResponse
ListServicesResponse'
            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
"NextToken")
            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
"ServiceSummaryList"
                            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListServices where
  hashWithSalt :: Int -> ListServices -> Int
hashWithSalt Int
_salt ListServices' {Maybe Natural
Maybe Text
Text
environmentIdentifier :: Text
applicationIdentifier :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentIdentifier:ListServices' :: ListServices -> Text
$sel:applicationIdentifier:ListServices' :: ListServices -> Text
$sel:nextToken:ListServices' :: ListServices -> Maybe Text
$sel:maxResults:ListServices' :: ListServices -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
applicationIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
environmentIdentifier

instance Prelude.NFData ListServices where
  rnf :: ListServices -> ()
rnf ListServices' {Maybe Natural
Maybe Text
Text
environmentIdentifier :: Text
applicationIdentifier :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentIdentifier:ListServices' :: ListServices -> Text
$sel:applicationIdentifier:ListServices' :: ListServices -> Text
$sel:nextToken:ListServices' :: ListServices -> Maybe Text
$sel:maxResults:ListServices' :: ListServices -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      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 Text
applicationIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
environmentIdentifier

instance Data.ToHeaders ListServices where
  toHeaders :: ListServices -> 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.ToPath ListServices where
  toPath :: ListServices -> ByteString
toPath ListServices' {Maybe Natural
Maybe Text
Text
environmentIdentifier :: Text
applicationIdentifier :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentIdentifier:ListServices' :: ListServices -> Text
$sel:applicationIdentifier:ListServices' :: ListServices -> Text
$sel:nextToken:ListServices' :: ListServices -> Maybe Text
$sel:maxResults:ListServices' :: ListServices -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/environments/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
environmentIdentifier,
        ByteString
"/applications/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
applicationIdentifier,
        ByteString
"/services"
      ]

instance Data.ToQuery ListServices where
  toQuery :: ListServices -> QueryString
toQuery ListServices' {Maybe Natural
Maybe Text
Text
environmentIdentifier :: Text
applicationIdentifier :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:environmentIdentifier:ListServices' :: ListServices -> Text
$sel:applicationIdentifier:ListServices' :: ListServices -> Text
$sel:nextToken:ListServices' :: ListServices -> Maybe Text
$sel:maxResults:ListServices' :: ListServices -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken
      ]

-- | /See:/ 'newListServicesResponse' smart constructor.
data ListServicesResponse = ListServicesResponse'
  { -- | The token for the next page of results.
    ListServicesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The list of @ServiceSummary@ objects.
    ListServicesResponse -> Maybe [ServiceSummary]
serviceSummaryList :: Prelude.Maybe [ServiceSummary],
    -- | The response's http status code.
    ListServicesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListServicesResponse -> ListServicesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListServicesResponse -> ListServicesResponse -> Bool
$c/= :: ListServicesResponse -> ListServicesResponse -> Bool
== :: ListServicesResponse -> ListServicesResponse -> Bool
$c== :: ListServicesResponse -> ListServicesResponse -> Bool
Prelude.Eq, Int -> ListServicesResponse -> ShowS
[ListServicesResponse] -> ShowS
ListServicesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListServicesResponse] -> ShowS
$cshowList :: [ListServicesResponse] -> ShowS
show :: ListServicesResponse -> String
$cshow :: ListServicesResponse -> String
showsPrec :: Int -> ListServicesResponse -> ShowS
$cshowsPrec :: Int -> ListServicesResponse -> ShowS
Prelude.Show, forall x. Rep ListServicesResponse x -> ListServicesResponse
forall x. ListServicesResponse -> Rep ListServicesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListServicesResponse x -> ListServicesResponse
$cfrom :: forall x. ListServicesResponse -> Rep ListServicesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListServicesResponse' 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:
--
-- 'nextToken', 'listServicesResponse_nextToken' - The token for the next page of results.
--
-- 'serviceSummaryList', 'listServicesResponse_serviceSummaryList' - The list of @ServiceSummary@ objects.
--
-- 'httpStatus', 'listServicesResponse_httpStatus' - The response's http status code.
newListServicesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListServicesResponse
newListServicesResponse :: Int -> ListServicesResponse
newListServicesResponse Int
pHttpStatus_ =
  ListServicesResponse'
    { $sel:nextToken:ListServicesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:serviceSummaryList:ListServicesResponse' :: Maybe [ServiceSummary]
serviceSummaryList = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListServicesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The token for the next page of results.
listServicesResponse_nextToken :: Lens.Lens' ListServicesResponse (Prelude.Maybe Prelude.Text)
listServicesResponse_nextToken :: Lens' ListServicesResponse (Maybe Text)
listServicesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServicesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListServicesResponse' :: ListServicesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListServicesResponse
s@ListServicesResponse' {} Maybe Text
a -> ListServicesResponse
s {$sel:nextToken:ListServicesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListServicesResponse)

-- | The list of @ServiceSummary@ objects.
listServicesResponse_serviceSummaryList :: Lens.Lens' ListServicesResponse (Prelude.Maybe [ServiceSummary])
listServicesResponse_serviceSummaryList :: Lens' ListServicesResponse (Maybe [ServiceSummary])
listServicesResponse_serviceSummaryList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServicesResponse' {Maybe [ServiceSummary]
serviceSummaryList :: Maybe [ServiceSummary]
$sel:serviceSummaryList:ListServicesResponse' :: ListServicesResponse -> Maybe [ServiceSummary]
serviceSummaryList} -> Maybe [ServiceSummary]
serviceSummaryList) (\s :: ListServicesResponse
s@ListServicesResponse' {} Maybe [ServiceSummary]
a -> ListServicesResponse
s {$sel:serviceSummaryList:ListServicesResponse' :: Maybe [ServiceSummary]
serviceSummaryList = Maybe [ServiceSummary]
a} :: ListServicesResponse) 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 response's http status code.
listServicesResponse_httpStatus :: Lens.Lens' ListServicesResponse Prelude.Int
listServicesResponse_httpStatus :: Lens' ListServicesResponse Int
listServicesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServicesResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListServicesResponse' :: ListServicesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListServicesResponse
s@ListServicesResponse' {} Int
a -> ListServicesResponse
s {$sel:httpStatus:ListServicesResponse' :: Int
httpStatus = Int
a} :: ListServicesResponse)

instance Prelude.NFData ListServicesResponse where
  rnf :: ListServicesResponse -> ()
rnf ListServicesResponse' {Int
Maybe [ServiceSummary]
Maybe Text
httpStatus :: Int
serviceSummaryList :: Maybe [ServiceSummary]
nextToken :: Maybe Text
$sel:httpStatus:ListServicesResponse' :: ListServicesResponse -> Int
$sel:serviceSummaryList:ListServicesResponse' :: ListServicesResponse -> Maybe [ServiceSummary]
$sel:nextToken:ListServicesResponse' :: ListServicesResponse -> Maybe Text
..} =
    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 Maybe [ServiceSummary]
serviceSummaryList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus