{-# 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.Pinpoint.ListTemplates
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves information about all the message templates that are
-- associated with your Amazon Pinpoint account.
module Amazonka.Pinpoint.ListTemplates
  ( -- * Creating a Request
    ListTemplates (..),
    newListTemplates,

    -- * Request Lenses
    listTemplates_templateType,
    listTemplates_prefix,
    listTemplates_nextToken,
    listTemplates_pageSize,

    -- * Destructuring the Response
    ListTemplatesResponse (..),
    newListTemplatesResponse,

    -- * Response Lenses
    listTemplatesResponse_httpStatus,
    listTemplatesResponse_templatesResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListTemplates' smart constructor.
data ListTemplates = ListTemplates'
  { -- | The type of message template to include in the results. Valid values
    -- are: EMAIL, PUSH, SMS, and VOICE. To include all types of templates in
    -- the results, don\'t include this parameter in your request.
    ListTemplates -> Maybe Text
templateType :: Prelude.Maybe Prelude.Text,
    -- | The substring to match in the names of the message templates to include
    -- in the results. If you specify this value, Amazon Pinpoint returns only
    -- those templates whose names begin with the value that you specify.
    ListTemplates -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | The string that specifies which page of results to return in a paginated
    -- response. This parameter is not supported for application, campaign, and
    -- journey metrics.
    ListTemplates -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of items to include in each page of a paginated
    -- response. This parameter is not supported for application, campaign, and
    -- journey metrics.
    ListTemplates -> Maybe Text
pageSize :: Prelude.Maybe Prelude.Text
  }
  deriving (ListTemplates -> ListTemplates -> Bool
(ListTemplates -> ListTemplates -> Bool)
-> (ListTemplates -> ListTemplates -> Bool) -> Eq ListTemplates
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTemplates -> ListTemplates -> Bool
$c/= :: ListTemplates -> ListTemplates -> Bool
== :: ListTemplates -> ListTemplates -> Bool
$c== :: ListTemplates -> ListTemplates -> Bool
Prelude.Eq, ReadPrec [ListTemplates]
ReadPrec ListTemplates
Int -> ReadS ListTemplates
ReadS [ListTemplates]
(Int -> ReadS ListTemplates)
-> ReadS [ListTemplates]
-> ReadPrec ListTemplates
-> ReadPrec [ListTemplates]
-> Read ListTemplates
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTemplates]
$creadListPrec :: ReadPrec [ListTemplates]
readPrec :: ReadPrec ListTemplates
$creadPrec :: ReadPrec ListTemplates
readList :: ReadS [ListTemplates]
$creadList :: ReadS [ListTemplates]
readsPrec :: Int -> ReadS ListTemplates
$creadsPrec :: Int -> ReadS ListTemplates
Prelude.Read, Int -> ListTemplates -> ShowS
[ListTemplates] -> ShowS
ListTemplates -> String
(Int -> ListTemplates -> ShowS)
-> (ListTemplates -> String)
-> ([ListTemplates] -> ShowS)
-> Show ListTemplates
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTemplates] -> ShowS
$cshowList :: [ListTemplates] -> ShowS
show :: ListTemplates -> String
$cshow :: ListTemplates -> String
showsPrec :: Int -> ListTemplates -> ShowS
$cshowsPrec :: Int -> ListTemplates -> ShowS
Prelude.Show, (forall x. ListTemplates -> Rep ListTemplates x)
-> (forall x. Rep ListTemplates x -> ListTemplates)
-> Generic ListTemplates
forall x. Rep ListTemplates x -> ListTemplates
forall x. ListTemplates -> Rep ListTemplates x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTemplates x -> ListTemplates
$cfrom :: forall x. ListTemplates -> Rep ListTemplates x
Prelude.Generic)

-- |
-- Create a value of 'ListTemplates' 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:
--
-- 'templateType', 'listTemplates_templateType' - The type of message template to include in the results. Valid values
-- are: EMAIL, PUSH, SMS, and VOICE. To include all types of templates in
-- the results, don\'t include this parameter in your request.
--
-- 'prefix', 'listTemplates_prefix' - The substring to match in the names of the message templates to include
-- in the results. If you specify this value, Amazon Pinpoint returns only
-- those templates whose names begin with the value that you specify.
--
-- 'nextToken', 'listTemplates_nextToken' - The string that specifies which page of results to return in a paginated
-- response. This parameter is not supported for application, campaign, and
-- journey metrics.
--
-- 'pageSize', 'listTemplates_pageSize' - The maximum number of items to include in each page of a paginated
-- response. This parameter is not supported for application, campaign, and
-- journey metrics.
newListTemplates ::
  ListTemplates
newListTemplates :: ListTemplates
newListTemplates =
  ListTemplates' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> ListTemplates
ListTemplates'
    { $sel:templateType:ListTemplates' :: Maybe Text
templateType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:prefix:ListTemplates' :: Maybe Text
prefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListTemplates' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:pageSize:ListTemplates' :: Maybe Text
pageSize = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The type of message template to include in the results. Valid values
-- are: EMAIL, PUSH, SMS, and VOICE. To include all types of templates in
-- the results, don\'t include this parameter in your request.
listTemplates_templateType :: Lens.Lens' ListTemplates (Prelude.Maybe Prelude.Text)
listTemplates_templateType :: (Maybe Text -> f (Maybe Text)) -> ListTemplates -> f ListTemplates
listTemplates_templateType = (ListTemplates -> Maybe Text)
-> (ListTemplates -> Maybe Text -> ListTemplates)
-> Lens ListTemplates ListTemplates (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTemplates' {Maybe Text
templateType :: Maybe Text
$sel:templateType:ListTemplates' :: ListTemplates -> Maybe Text
templateType} -> Maybe Text
templateType) (\s :: ListTemplates
s@ListTemplates' {} Maybe Text
a -> ListTemplates
s {$sel:templateType:ListTemplates' :: Maybe Text
templateType = Maybe Text
a} :: ListTemplates)

-- | The substring to match in the names of the message templates to include
-- in the results. If you specify this value, Amazon Pinpoint returns only
-- those templates whose names begin with the value that you specify.
listTemplates_prefix :: Lens.Lens' ListTemplates (Prelude.Maybe Prelude.Text)
listTemplates_prefix :: (Maybe Text -> f (Maybe Text)) -> ListTemplates -> f ListTemplates
listTemplates_prefix = (ListTemplates -> Maybe Text)
-> (ListTemplates -> Maybe Text -> ListTemplates)
-> Lens ListTemplates ListTemplates (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTemplates' {Maybe Text
prefix :: Maybe Text
$sel:prefix:ListTemplates' :: ListTemplates -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: ListTemplates
s@ListTemplates' {} Maybe Text
a -> ListTemplates
s {$sel:prefix:ListTemplates' :: Maybe Text
prefix = Maybe Text
a} :: ListTemplates)

-- | The string that specifies which page of results to return in a paginated
-- response. This parameter is not supported for application, campaign, and
-- journey metrics.
listTemplates_nextToken :: Lens.Lens' ListTemplates (Prelude.Maybe Prelude.Text)
listTemplates_nextToken :: (Maybe Text -> f (Maybe Text)) -> ListTemplates -> f ListTemplates
listTemplates_nextToken = (ListTemplates -> Maybe Text)
-> (ListTemplates -> Maybe Text -> ListTemplates)
-> Lens ListTemplates ListTemplates (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTemplates' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTemplates' :: ListTemplates -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTemplates
s@ListTemplates' {} Maybe Text
a -> ListTemplates
s {$sel:nextToken:ListTemplates' :: Maybe Text
nextToken = Maybe Text
a} :: ListTemplates)

-- | The maximum number of items to include in each page of a paginated
-- response. This parameter is not supported for application, campaign, and
-- journey metrics.
listTemplates_pageSize :: Lens.Lens' ListTemplates (Prelude.Maybe Prelude.Text)
listTemplates_pageSize :: (Maybe Text -> f (Maybe Text)) -> ListTemplates -> f ListTemplates
listTemplates_pageSize = (ListTemplates -> Maybe Text)
-> (ListTemplates -> Maybe Text -> ListTemplates)
-> Lens ListTemplates ListTemplates (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTemplates' {Maybe Text
pageSize :: Maybe Text
$sel:pageSize:ListTemplates' :: ListTemplates -> Maybe Text
pageSize} -> Maybe Text
pageSize) (\s :: ListTemplates
s@ListTemplates' {} Maybe Text
a -> ListTemplates
s {$sel:pageSize:ListTemplates' :: Maybe Text
pageSize = Maybe Text
a} :: ListTemplates)

instance Core.AWSRequest ListTemplates where
  type
    AWSResponse ListTemplates =
      ListTemplatesResponse
  request :: ListTemplates -> Request ListTemplates
request = Service -> ListTemplates -> Request ListTemplates
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy ListTemplates
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTemplates)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListTemplates))
-> Logger
-> Service
-> Proxy ListTemplates
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTemplates)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> TemplatesResponse -> ListTemplatesResponse
ListTemplatesResponse'
            (Int -> TemplatesResponse -> ListTemplatesResponse)
-> Either String Int
-> Either String (TemplatesResponse -> ListTemplatesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (TemplatesResponse -> ListTemplatesResponse)
-> Either String TemplatesResponse
-> Either String ListTemplatesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object -> Either String TemplatesResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
      )

instance Prelude.Hashable ListTemplates

instance Prelude.NFData ListTemplates

instance Core.ToHeaders ListTemplates where
  toHeaders :: ListTemplates -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ListTemplates -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToPath ListTemplates where
  toPath :: ListTemplates -> ByteString
toPath = ByteString -> ListTemplates -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/v1/templates"

instance Core.ToQuery ListTemplates where
  toQuery :: ListTemplates -> QueryString
toQuery ListTemplates' {Maybe Text
pageSize :: Maybe Text
nextToken :: Maybe Text
prefix :: Maybe Text
templateType :: Maybe Text
$sel:pageSize:ListTemplates' :: ListTemplates -> Maybe Text
$sel:nextToken:ListTemplates' :: ListTemplates -> Maybe Text
$sel:prefix:ListTemplates' :: ListTemplates -> Maybe Text
$sel:templateType:ListTemplates' :: ListTemplates -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"template-type" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
templateType,
        ByteString
"prefix" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
prefix,
        ByteString
"next-token" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
nextToken,
        ByteString
"page-size" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
pageSize
      ]

-- | /See:/ 'newListTemplatesResponse' smart constructor.
data ListTemplatesResponse = ListTemplatesResponse'
  { -- | The response's http status code.
    ListTemplatesResponse -> Int
httpStatus :: Prelude.Int,
    ListTemplatesResponse -> TemplatesResponse
templatesResponse :: TemplatesResponse
  }
  deriving (ListTemplatesResponse -> ListTemplatesResponse -> Bool
(ListTemplatesResponse -> ListTemplatesResponse -> Bool)
-> (ListTemplatesResponse -> ListTemplatesResponse -> Bool)
-> Eq ListTemplatesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTemplatesResponse -> ListTemplatesResponse -> Bool
$c/= :: ListTemplatesResponse -> ListTemplatesResponse -> Bool
== :: ListTemplatesResponse -> ListTemplatesResponse -> Bool
$c== :: ListTemplatesResponse -> ListTemplatesResponse -> Bool
Prelude.Eq, ReadPrec [ListTemplatesResponse]
ReadPrec ListTemplatesResponse
Int -> ReadS ListTemplatesResponse
ReadS [ListTemplatesResponse]
(Int -> ReadS ListTemplatesResponse)
-> ReadS [ListTemplatesResponse]
-> ReadPrec ListTemplatesResponse
-> ReadPrec [ListTemplatesResponse]
-> Read ListTemplatesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTemplatesResponse]
$creadListPrec :: ReadPrec [ListTemplatesResponse]
readPrec :: ReadPrec ListTemplatesResponse
$creadPrec :: ReadPrec ListTemplatesResponse
readList :: ReadS [ListTemplatesResponse]
$creadList :: ReadS [ListTemplatesResponse]
readsPrec :: Int -> ReadS ListTemplatesResponse
$creadsPrec :: Int -> ReadS ListTemplatesResponse
Prelude.Read, Int -> ListTemplatesResponse -> ShowS
[ListTemplatesResponse] -> ShowS
ListTemplatesResponse -> String
(Int -> ListTemplatesResponse -> ShowS)
-> (ListTemplatesResponse -> String)
-> ([ListTemplatesResponse] -> ShowS)
-> Show ListTemplatesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTemplatesResponse] -> ShowS
$cshowList :: [ListTemplatesResponse] -> ShowS
show :: ListTemplatesResponse -> String
$cshow :: ListTemplatesResponse -> String
showsPrec :: Int -> ListTemplatesResponse -> ShowS
$cshowsPrec :: Int -> ListTemplatesResponse -> ShowS
Prelude.Show, (forall x. ListTemplatesResponse -> Rep ListTemplatesResponse x)
-> (forall x. Rep ListTemplatesResponse x -> ListTemplatesResponse)
-> Generic ListTemplatesResponse
forall x. Rep ListTemplatesResponse x -> ListTemplatesResponse
forall x. ListTemplatesResponse -> Rep ListTemplatesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTemplatesResponse x -> ListTemplatesResponse
$cfrom :: forall x. ListTemplatesResponse -> Rep ListTemplatesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListTemplatesResponse' 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:
--
-- 'httpStatus', 'listTemplatesResponse_httpStatus' - The response's http status code.
--
-- 'templatesResponse', 'listTemplatesResponse_templatesResponse' - Undocumented member.
newListTemplatesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'templatesResponse'
  TemplatesResponse ->
  ListTemplatesResponse
newListTemplatesResponse :: Int -> TemplatesResponse -> ListTemplatesResponse
newListTemplatesResponse
  Int
pHttpStatus_
  TemplatesResponse
pTemplatesResponse_ =
    ListTemplatesResponse' :: Int -> TemplatesResponse -> ListTemplatesResponse
ListTemplatesResponse'
      { $sel:httpStatus:ListTemplatesResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:templatesResponse:ListTemplatesResponse' :: TemplatesResponse
templatesResponse = TemplatesResponse
pTemplatesResponse_
      }

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

-- | Undocumented member.
listTemplatesResponse_templatesResponse :: Lens.Lens' ListTemplatesResponse TemplatesResponse
listTemplatesResponse_templatesResponse :: (TemplatesResponse -> f TemplatesResponse)
-> ListTemplatesResponse -> f ListTemplatesResponse
listTemplatesResponse_templatesResponse = (ListTemplatesResponse -> TemplatesResponse)
-> (ListTemplatesResponse
    -> TemplatesResponse -> ListTemplatesResponse)
-> Lens
     ListTemplatesResponse
     ListTemplatesResponse
     TemplatesResponse
     TemplatesResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTemplatesResponse' {TemplatesResponse
templatesResponse :: TemplatesResponse
$sel:templatesResponse:ListTemplatesResponse' :: ListTemplatesResponse -> TemplatesResponse
templatesResponse} -> TemplatesResponse
templatesResponse) (\s :: ListTemplatesResponse
s@ListTemplatesResponse' {} TemplatesResponse
a -> ListTemplatesResponse
s {$sel:templatesResponse:ListTemplatesResponse' :: TemplatesResponse
templatesResponse = TemplatesResponse
a} :: ListTemplatesResponse)

instance Prelude.NFData ListTemplatesResponse