{-# 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.SESV2.ListEmailTemplates
-- 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 the email templates present in your Amazon SES account in the
-- current Amazon Web Services Region.
--
-- You can execute this operation no more than once per second.
module Amazonka.SESV2.ListEmailTemplates
  ( -- * Creating a Request
    ListEmailTemplates (..),
    newListEmailTemplates,

    -- * Request Lenses
    listEmailTemplates_nextToken,
    listEmailTemplates_pageSize,

    -- * Destructuring the Response
    ListEmailTemplatesResponse (..),
    newListEmailTemplatesResponse,

    -- * Response Lenses
    listEmailTemplatesResponse_nextToken,
    listEmailTemplatesResponse_templatesMetadata,
    listEmailTemplatesResponse_httpStatus,
  )
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 qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SESV2.Types

-- | Represents a request to list the email templates present in your Amazon
-- SES account in the current Amazon Web Services Region. For more
-- information, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html Amazon SES Developer Guide>.
--
-- /See:/ 'newListEmailTemplates' smart constructor.
data ListEmailTemplates = ListEmailTemplates'
  { -- | A token returned from a previous call to @ListEmailTemplates@ to
    -- indicate the position in the list of email templates.
    ListEmailTemplates -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The number of results to show in a single call to @ListEmailTemplates@.
    -- If the number of results is larger than the number you specified in this
    -- parameter, then the response includes a @NextToken@ element, which you
    -- can use to obtain additional results.
    --
    -- The value you specify has to be at least 1, and can be no more than 10.
    ListEmailTemplates -> Maybe Int
pageSize :: Prelude.Maybe Prelude.Int
  }
  deriving (ListEmailTemplates -> ListEmailTemplates -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListEmailTemplates -> ListEmailTemplates -> Bool
$c/= :: ListEmailTemplates -> ListEmailTemplates -> Bool
== :: ListEmailTemplates -> ListEmailTemplates -> Bool
$c== :: ListEmailTemplates -> ListEmailTemplates -> Bool
Prelude.Eq, ReadPrec [ListEmailTemplates]
ReadPrec ListEmailTemplates
Int -> ReadS ListEmailTemplates
ReadS [ListEmailTemplates]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListEmailTemplates]
$creadListPrec :: ReadPrec [ListEmailTemplates]
readPrec :: ReadPrec ListEmailTemplates
$creadPrec :: ReadPrec ListEmailTemplates
readList :: ReadS [ListEmailTemplates]
$creadList :: ReadS [ListEmailTemplates]
readsPrec :: Int -> ReadS ListEmailTemplates
$creadsPrec :: Int -> ReadS ListEmailTemplates
Prelude.Read, Int -> ListEmailTemplates -> ShowS
[ListEmailTemplates] -> ShowS
ListEmailTemplates -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListEmailTemplates] -> ShowS
$cshowList :: [ListEmailTemplates] -> ShowS
show :: ListEmailTemplates -> String
$cshow :: ListEmailTemplates -> String
showsPrec :: Int -> ListEmailTemplates -> ShowS
$cshowsPrec :: Int -> ListEmailTemplates -> ShowS
Prelude.Show, forall x. Rep ListEmailTemplates x -> ListEmailTemplates
forall x. ListEmailTemplates -> Rep ListEmailTemplates x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListEmailTemplates x -> ListEmailTemplates
$cfrom :: forall x. ListEmailTemplates -> Rep ListEmailTemplates x
Prelude.Generic)

-- |
-- Create a value of 'ListEmailTemplates' 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', 'listEmailTemplates_nextToken' - A token returned from a previous call to @ListEmailTemplates@ to
-- indicate the position in the list of email templates.
--
-- 'pageSize', 'listEmailTemplates_pageSize' - The number of results to show in a single call to @ListEmailTemplates@.
-- If the number of results is larger than the number you specified in this
-- parameter, then the response includes a @NextToken@ element, which you
-- can use to obtain additional results.
--
-- The value you specify has to be at least 1, and can be no more than 10.
newListEmailTemplates ::
  ListEmailTemplates
newListEmailTemplates :: ListEmailTemplates
newListEmailTemplates =
  ListEmailTemplates'
    { $sel:nextToken:ListEmailTemplates' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:pageSize:ListEmailTemplates' :: Maybe Int
pageSize = forall a. Maybe a
Prelude.Nothing
    }

-- | A token returned from a previous call to @ListEmailTemplates@ to
-- indicate the position in the list of email templates.
listEmailTemplates_nextToken :: Lens.Lens' ListEmailTemplates (Prelude.Maybe Prelude.Text)
listEmailTemplates_nextToken :: Lens' ListEmailTemplates (Maybe Text)
listEmailTemplates_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEmailTemplates' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListEmailTemplates' :: ListEmailTemplates -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListEmailTemplates
s@ListEmailTemplates' {} Maybe Text
a -> ListEmailTemplates
s {$sel:nextToken:ListEmailTemplates' :: Maybe Text
nextToken = Maybe Text
a} :: ListEmailTemplates)

-- | The number of results to show in a single call to @ListEmailTemplates@.
-- If the number of results is larger than the number you specified in this
-- parameter, then the response includes a @NextToken@ element, which you
-- can use to obtain additional results.
--
-- The value you specify has to be at least 1, and can be no more than 10.
listEmailTemplates_pageSize :: Lens.Lens' ListEmailTemplates (Prelude.Maybe Prelude.Int)
listEmailTemplates_pageSize :: Lens' ListEmailTemplates (Maybe Int)
listEmailTemplates_pageSize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEmailTemplates' {Maybe Int
pageSize :: Maybe Int
$sel:pageSize:ListEmailTemplates' :: ListEmailTemplates -> Maybe Int
pageSize} -> Maybe Int
pageSize) (\s :: ListEmailTemplates
s@ListEmailTemplates' {} Maybe Int
a -> ListEmailTemplates
s {$sel:pageSize:ListEmailTemplates' :: Maybe Int
pageSize = Maybe Int
a} :: ListEmailTemplates)

instance Core.AWSRequest ListEmailTemplates where
  type
    AWSResponse ListEmailTemplates =
      ListEmailTemplatesResponse
  request :: (Service -> Service)
-> ListEmailTemplates -> Request ListEmailTemplates
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 ListEmailTemplates
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListEmailTemplates)))
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 [EmailTemplateMetadata]
-> Int
-> ListEmailTemplatesResponse
ListEmailTemplatesResponse'
            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
"TemplatesMetadata"
                            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 ListEmailTemplates where
  hashWithSalt :: Int -> ListEmailTemplates -> Int
hashWithSalt Int
_salt ListEmailTemplates' {Maybe Int
Maybe Text
pageSize :: Maybe Int
nextToken :: Maybe Text
$sel:pageSize:ListEmailTemplates' :: ListEmailTemplates -> Maybe Int
$sel:nextToken:ListEmailTemplates' :: ListEmailTemplates -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
pageSize

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

instance Data.ToHeaders ListEmailTemplates where
  toHeaders :: ListEmailTemplates -> 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 ListEmailTemplates where
  toPath :: ListEmailTemplates -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/v2/email/templates"

instance Data.ToQuery ListEmailTemplates where
  toQuery :: ListEmailTemplates -> QueryString
toQuery ListEmailTemplates' {Maybe Int
Maybe Text
pageSize :: Maybe Int
nextToken :: Maybe Text
$sel:pageSize:ListEmailTemplates' :: ListEmailTemplates -> Maybe Int
$sel:nextToken:ListEmailTemplates' :: ListEmailTemplates -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"NextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken,
        ByteString
"PageSize" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Int
pageSize
      ]

-- | The following elements are returned by the service.
--
-- /See:/ 'newListEmailTemplatesResponse' smart constructor.
data ListEmailTemplatesResponse = ListEmailTemplatesResponse'
  { -- | A token indicating that there are additional email templates available
    -- to be listed. Pass this token to a subsequent @ListEmailTemplates@ call
    -- to retrieve the next 10 email templates.
    ListEmailTemplatesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | An array the contains the name and creation time stamp for each template
    -- in your Amazon SES account.
    ListEmailTemplatesResponse -> Maybe [EmailTemplateMetadata]
templatesMetadata :: Prelude.Maybe [EmailTemplateMetadata],
    -- | The response's http status code.
    ListEmailTemplatesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListEmailTemplatesResponse -> ListEmailTemplatesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListEmailTemplatesResponse -> ListEmailTemplatesResponse -> Bool
$c/= :: ListEmailTemplatesResponse -> ListEmailTemplatesResponse -> Bool
== :: ListEmailTemplatesResponse -> ListEmailTemplatesResponse -> Bool
$c== :: ListEmailTemplatesResponse -> ListEmailTemplatesResponse -> Bool
Prelude.Eq, ReadPrec [ListEmailTemplatesResponse]
ReadPrec ListEmailTemplatesResponse
Int -> ReadS ListEmailTemplatesResponse
ReadS [ListEmailTemplatesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListEmailTemplatesResponse]
$creadListPrec :: ReadPrec [ListEmailTemplatesResponse]
readPrec :: ReadPrec ListEmailTemplatesResponse
$creadPrec :: ReadPrec ListEmailTemplatesResponse
readList :: ReadS [ListEmailTemplatesResponse]
$creadList :: ReadS [ListEmailTemplatesResponse]
readsPrec :: Int -> ReadS ListEmailTemplatesResponse
$creadsPrec :: Int -> ReadS ListEmailTemplatesResponse
Prelude.Read, Int -> ListEmailTemplatesResponse -> ShowS
[ListEmailTemplatesResponse] -> ShowS
ListEmailTemplatesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListEmailTemplatesResponse] -> ShowS
$cshowList :: [ListEmailTemplatesResponse] -> ShowS
show :: ListEmailTemplatesResponse -> String
$cshow :: ListEmailTemplatesResponse -> String
showsPrec :: Int -> ListEmailTemplatesResponse -> ShowS
$cshowsPrec :: Int -> ListEmailTemplatesResponse -> ShowS
Prelude.Show, forall x.
Rep ListEmailTemplatesResponse x -> ListEmailTemplatesResponse
forall x.
ListEmailTemplatesResponse -> Rep ListEmailTemplatesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListEmailTemplatesResponse x -> ListEmailTemplatesResponse
$cfrom :: forall x.
ListEmailTemplatesResponse -> Rep ListEmailTemplatesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListEmailTemplatesResponse' 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', 'listEmailTemplatesResponse_nextToken' - A token indicating that there are additional email templates available
-- to be listed. Pass this token to a subsequent @ListEmailTemplates@ call
-- to retrieve the next 10 email templates.
--
-- 'templatesMetadata', 'listEmailTemplatesResponse_templatesMetadata' - An array the contains the name and creation time stamp for each template
-- in your Amazon SES account.
--
-- 'httpStatus', 'listEmailTemplatesResponse_httpStatus' - The response's http status code.
newListEmailTemplatesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListEmailTemplatesResponse
newListEmailTemplatesResponse :: Int -> ListEmailTemplatesResponse
newListEmailTemplatesResponse Int
pHttpStatus_ =
  ListEmailTemplatesResponse'
    { $sel:nextToken:ListEmailTemplatesResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:templatesMetadata:ListEmailTemplatesResponse' :: Maybe [EmailTemplateMetadata]
templatesMetadata = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListEmailTemplatesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A token indicating that there are additional email templates available
-- to be listed. Pass this token to a subsequent @ListEmailTemplates@ call
-- to retrieve the next 10 email templates.
listEmailTemplatesResponse_nextToken :: Lens.Lens' ListEmailTemplatesResponse (Prelude.Maybe Prelude.Text)
listEmailTemplatesResponse_nextToken :: Lens' ListEmailTemplatesResponse (Maybe Text)
listEmailTemplatesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEmailTemplatesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListEmailTemplatesResponse' :: ListEmailTemplatesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListEmailTemplatesResponse
s@ListEmailTemplatesResponse' {} Maybe Text
a -> ListEmailTemplatesResponse
s {$sel:nextToken:ListEmailTemplatesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListEmailTemplatesResponse)

-- | An array the contains the name and creation time stamp for each template
-- in your Amazon SES account.
listEmailTemplatesResponse_templatesMetadata :: Lens.Lens' ListEmailTemplatesResponse (Prelude.Maybe [EmailTemplateMetadata])
listEmailTemplatesResponse_templatesMetadata :: Lens' ListEmailTemplatesResponse (Maybe [EmailTemplateMetadata])
listEmailTemplatesResponse_templatesMetadata = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEmailTemplatesResponse' {Maybe [EmailTemplateMetadata]
templatesMetadata :: Maybe [EmailTemplateMetadata]
$sel:templatesMetadata:ListEmailTemplatesResponse' :: ListEmailTemplatesResponse -> Maybe [EmailTemplateMetadata]
templatesMetadata} -> Maybe [EmailTemplateMetadata]
templatesMetadata) (\s :: ListEmailTemplatesResponse
s@ListEmailTemplatesResponse' {} Maybe [EmailTemplateMetadata]
a -> ListEmailTemplatesResponse
s {$sel:templatesMetadata:ListEmailTemplatesResponse' :: Maybe [EmailTemplateMetadata]
templatesMetadata = Maybe [EmailTemplateMetadata]
a} :: ListEmailTemplatesResponse) 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.
listEmailTemplatesResponse_httpStatus :: Lens.Lens' ListEmailTemplatesResponse Prelude.Int
listEmailTemplatesResponse_httpStatus :: Lens' ListEmailTemplatesResponse Int
listEmailTemplatesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListEmailTemplatesResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListEmailTemplatesResponse' :: ListEmailTemplatesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListEmailTemplatesResponse
s@ListEmailTemplatesResponse' {} Int
a -> ListEmailTemplatesResponse
s {$sel:httpStatus:ListEmailTemplatesResponse' :: Int
httpStatus = Int
a} :: ListEmailTemplatesResponse)

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