{-# 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.Proton.ListServiceTemplates
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- List service templates with detail data.
--
-- This operation returns paginated results.
module Amazonka.Proton.ListServiceTemplates
  ( -- * Creating a Request
    ListServiceTemplates (..),
    newListServiceTemplates,

    -- * Request Lenses
    listServiceTemplates_maxResults,
    listServiceTemplates_nextToken,

    -- * Destructuring the Response
    ListServiceTemplatesResponse (..),
    newListServiceTemplatesResponse,

    -- * Response Lenses
    listServiceTemplatesResponse_nextToken,
    listServiceTemplatesResponse_httpStatus,
    listServiceTemplatesResponse_templates,
  )
where

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

-- | /See:/ 'newListServiceTemplates' smart constructor.
data ListServiceTemplates = ListServiceTemplates'
  { -- | The maximum number of service templates to list.
    ListServiceTemplates -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A token that indicates the location of the next service template in the
    -- array of service templates, after the list of service templates
    -- previously requested.
    ListServiceTemplates -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListServiceTemplates -> ListServiceTemplates -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListServiceTemplates -> ListServiceTemplates -> Bool
$c/= :: ListServiceTemplates -> ListServiceTemplates -> Bool
== :: ListServiceTemplates -> ListServiceTemplates -> Bool
$c== :: ListServiceTemplates -> ListServiceTemplates -> Bool
Prelude.Eq, ReadPrec [ListServiceTemplates]
ReadPrec ListServiceTemplates
Int -> ReadS ListServiceTemplates
ReadS [ListServiceTemplates]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListServiceTemplates]
$creadListPrec :: ReadPrec [ListServiceTemplates]
readPrec :: ReadPrec ListServiceTemplates
$creadPrec :: ReadPrec ListServiceTemplates
readList :: ReadS [ListServiceTemplates]
$creadList :: ReadS [ListServiceTemplates]
readsPrec :: Int -> ReadS ListServiceTemplates
$creadsPrec :: Int -> ReadS ListServiceTemplates
Prelude.Read, Int -> ListServiceTemplates -> ShowS
[ListServiceTemplates] -> ShowS
ListServiceTemplates -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListServiceTemplates] -> ShowS
$cshowList :: [ListServiceTemplates] -> ShowS
show :: ListServiceTemplates -> String
$cshow :: ListServiceTemplates -> String
showsPrec :: Int -> ListServiceTemplates -> ShowS
$cshowsPrec :: Int -> ListServiceTemplates -> ShowS
Prelude.Show, forall x. Rep ListServiceTemplates x -> ListServiceTemplates
forall x. ListServiceTemplates -> Rep ListServiceTemplates x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListServiceTemplates x -> ListServiceTemplates
$cfrom :: forall x. ListServiceTemplates -> Rep ListServiceTemplates x
Prelude.Generic)

-- |
-- Create a value of 'ListServiceTemplates' 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', 'listServiceTemplates_maxResults' - The maximum number of service templates to list.
--
-- 'nextToken', 'listServiceTemplates_nextToken' - A token that indicates the location of the next service template in the
-- array of service templates, after the list of service templates
-- previously requested.
newListServiceTemplates ::
  ListServiceTemplates
newListServiceTemplates :: ListServiceTemplates
newListServiceTemplates =
  ListServiceTemplates'
    { $sel:maxResults:ListServiceTemplates' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListServiceTemplates' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of service templates to list.
listServiceTemplates_maxResults :: Lens.Lens' ListServiceTemplates (Prelude.Maybe Prelude.Natural)
listServiceTemplates_maxResults :: Lens' ListServiceTemplates (Maybe Natural)
listServiceTemplates_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceTemplates' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListServiceTemplates' :: ListServiceTemplates -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListServiceTemplates
s@ListServiceTemplates' {} Maybe Natural
a -> ListServiceTemplates
s {$sel:maxResults:ListServiceTemplates' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListServiceTemplates)

-- | A token that indicates the location of the next service template in the
-- array of service templates, after the list of service templates
-- previously requested.
listServiceTemplates_nextToken :: Lens.Lens' ListServiceTemplates (Prelude.Maybe Prelude.Text)
listServiceTemplates_nextToken :: Lens' ListServiceTemplates (Maybe Text)
listServiceTemplates_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceTemplates' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListServiceTemplates' :: ListServiceTemplates -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListServiceTemplates
s@ListServiceTemplates' {} Maybe Text
a -> ListServiceTemplates
s {$sel:nextToken:ListServiceTemplates' :: Maybe Text
nextToken = Maybe Text
a} :: ListServiceTemplates)

instance Core.AWSPager ListServiceTemplates where
  page :: ListServiceTemplates
-> AWSResponse ListServiceTemplates -> Maybe ListServiceTemplates
page ListServiceTemplates
rq AWSResponse ListServiceTemplates
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListServiceTemplates
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListServiceTemplatesResponse (Maybe Text)
listServiceTemplatesResponse_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 ListServiceTemplates
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' ListServiceTemplatesResponse [ServiceTemplateSummary]
listServiceTemplatesResponse_templates) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListServiceTemplates
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListServiceTemplates (Maybe Text)
listServiceTemplates_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListServiceTemplates
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListServiceTemplatesResponse (Maybe Text)
listServiceTemplatesResponse_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 ListServiceTemplates where
  type
    AWSResponse ListServiceTemplates =
      ListServiceTemplatesResponse
  request :: (Service -> Service)
-> ListServiceTemplates -> Request ListServiceTemplates
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 ListServiceTemplates
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListServiceTemplates)))
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
-> Int -> [ServiceTemplateSummary] -> ListServiceTemplatesResponse
ListServiceTemplatesResponse'
            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            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
"templates" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ListServiceTemplates where
  hashWithSalt :: Int -> ListServiceTemplates -> Int
hashWithSalt Int
_salt ListServiceTemplates' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListServiceTemplates' :: ListServiceTemplates -> Maybe Text
$sel:maxResults:ListServiceTemplates' :: ListServiceTemplates -> 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

instance Prelude.NFData ListServiceTemplates where
  rnf :: ListServiceTemplates -> ()
rnf ListServiceTemplates' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListServiceTemplates' :: ListServiceTemplates -> Maybe Text
$sel:maxResults:ListServiceTemplates' :: ListServiceTemplates -> 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

instance Data.ToHeaders ListServiceTemplates where
  toHeaders :: ListServiceTemplates -> 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
"AwsProton20200720.ListServiceTemplates" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListServiceTemplates where
  toJSON :: ListServiceTemplates -> Value
toJSON ListServiceTemplates' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListServiceTemplates' :: ListServiceTemplates -> Maybe Text
$sel:maxResults:ListServiceTemplates' :: ListServiceTemplates -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (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 Natural
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 ListServiceTemplates where
  toPath :: ListServiceTemplates -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListServiceTemplatesResponse' smart constructor.
data ListServiceTemplatesResponse = ListServiceTemplatesResponse'
  { -- | A token that indicates the location of the next service template in the
    -- array of service templates, after the current requested list of service
    -- templates.
    ListServiceTemplatesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListServiceTemplatesResponse -> Int
httpStatus :: Prelude.Int,
    -- | An array of service templates with detail data.
    ListServiceTemplatesResponse -> [ServiceTemplateSummary]
templates :: [ServiceTemplateSummary]
  }
  deriving (ListServiceTemplatesResponse
-> ListServiceTemplatesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListServiceTemplatesResponse
-> ListServiceTemplatesResponse -> Bool
$c/= :: ListServiceTemplatesResponse
-> ListServiceTemplatesResponse -> Bool
== :: ListServiceTemplatesResponse
-> ListServiceTemplatesResponse -> Bool
$c== :: ListServiceTemplatesResponse
-> ListServiceTemplatesResponse -> Bool
Prelude.Eq, Int -> ListServiceTemplatesResponse -> ShowS
[ListServiceTemplatesResponse] -> ShowS
ListServiceTemplatesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListServiceTemplatesResponse] -> ShowS
$cshowList :: [ListServiceTemplatesResponse] -> ShowS
show :: ListServiceTemplatesResponse -> String
$cshow :: ListServiceTemplatesResponse -> String
showsPrec :: Int -> ListServiceTemplatesResponse -> ShowS
$cshowsPrec :: Int -> ListServiceTemplatesResponse -> ShowS
Prelude.Show, forall x.
Rep ListServiceTemplatesResponse x -> ListServiceTemplatesResponse
forall x.
ListServiceTemplatesResponse -> Rep ListServiceTemplatesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListServiceTemplatesResponse x -> ListServiceTemplatesResponse
$cfrom :: forall x.
ListServiceTemplatesResponse -> Rep ListServiceTemplatesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListServiceTemplatesResponse' 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', 'listServiceTemplatesResponse_nextToken' - A token that indicates the location of the next service template in the
-- array of service templates, after the current requested list of service
-- templates.
--
-- 'httpStatus', 'listServiceTemplatesResponse_httpStatus' - The response's http status code.
--
-- 'templates', 'listServiceTemplatesResponse_templates' - An array of service templates with detail data.
newListServiceTemplatesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListServiceTemplatesResponse
newListServiceTemplatesResponse :: Int -> ListServiceTemplatesResponse
newListServiceTemplatesResponse Int
pHttpStatus_ =
  ListServiceTemplatesResponse'
    { $sel:nextToken:ListServiceTemplatesResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListServiceTemplatesResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:templates:ListServiceTemplatesResponse' :: [ServiceTemplateSummary]
templates = forall a. Monoid a => a
Prelude.mempty
    }

-- | A token that indicates the location of the next service template in the
-- array of service templates, after the current requested list of service
-- templates.
listServiceTemplatesResponse_nextToken :: Lens.Lens' ListServiceTemplatesResponse (Prelude.Maybe Prelude.Text)
listServiceTemplatesResponse_nextToken :: Lens' ListServiceTemplatesResponse (Maybe Text)
listServiceTemplatesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceTemplatesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListServiceTemplatesResponse' :: ListServiceTemplatesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListServiceTemplatesResponse
s@ListServiceTemplatesResponse' {} Maybe Text
a -> ListServiceTemplatesResponse
s {$sel:nextToken:ListServiceTemplatesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListServiceTemplatesResponse)

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

-- | An array of service templates with detail data.
listServiceTemplatesResponse_templates :: Lens.Lens' ListServiceTemplatesResponse [ServiceTemplateSummary]
listServiceTemplatesResponse_templates :: Lens' ListServiceTemplatesResponse [ServiceTemplateSummary]
listServiceTemplatesResponse_templates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListServiceTemplatesResponse' {[ServiceTemplateSummary]
templates :: [ServiceTemplateSummary]
$sel:templates:ListServiceTemplatesResponse' :: ListServiceTemplatesResponse -> [ServiceTemplateSummary]
templates} -> [ServiceTemplateSummary]
templates) (\s :: ListServiceTemplatesResponse
s@ListServiceTemplatesResponse' {} [ServiceTemplateSummary]
a -> ListServiceTemplatesResponse
s {$sel:templates:ListServiceTemplatesResponse' :: [ServiceTemplateSummary]
templates = [ServiceTemplateSummary]
a} :: ListServiceTemplatesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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