{-# 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.SES.TestRenderTemplate
-- 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)
--
-- Creates a preview of the MIME content of an email when provided with a
-- template and a set of replacement data.
--
-- You can execute this operation no more than once per second.
module Amazonka.SES.TestRenderTemplate
  ( -- * Creating a Request
    TestRenderTemplate (..),
    newTestRenderTemplate,

    -- * Request Lenses
    testRenderTemplate_templateName,
    testRenderTemplate_templateData,

    -- * Destructuring the Response
    TestRenderTemplateResponse (..),
    newTestRenderTemplateResponse,

    -- * Response Lenses
    testRenderTemplateResponse_renderedTemplate,
    testRenderTemplateResponse_httpStatus,
  )
where

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

-- | /See:/ 'newTestRenderTemplate' smart constructor.
data TestRenderTemplate = TestRenderTemplate'
  { -- | The name of the template that you want to render.
    TestRenderTemplate -> Text
templateName :: Prelude.Text,
    -- | A list of replacement values to apply to the template. This parameter is
    -- a JSON object, typically consisting of key-value pairs in which the keys
    -- correspond to replacement tags in the email template.
    TestRenderTemplate -> Text
templateData :: Prelude.Text
  }
  deriving (TestRenderTemplate -> TestRenderTemplate -> Bool
(TestRenderTemplate -> TestRenderTemplate -> Bool)
-> (TestRenderTemplate -> TestRenderTemplate -> Bool)
-> Eq TestRenderTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestRenderTemplate -> TestRenderTemplate -> Bool
$c/= :: TestRenderTemplate -> TestRenderTemplate -> Bool
== :: TestRenderTemplate -> TestRenderTemplate -> Bool
$c== :: TestRenderTemplate -> TestRenderTemplate -> Bool
Prelude.Eq, ReadPrec [TestRenderTemplate]
ReadPrec TestRenderTemplate
Int -> ReadS TestRenderTemplate
ReadS [TestRenderTemplate]
(Int -> ReadS TestRenderTemplate)
-> ReadS [TestRenderTemplate]
-> ReadPrec TestRenderTemplate
-> ReadPrec [TestRenderTemplate]
-> Read TestRenderTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestRenderTemplate]
$creadListPrec :: ReadPrec [TestRenderTemplate]
readPrec :: ReadPrec TestRenderTemplate
$creadPrec :: ReadPrec TestRenderTemplate
readList :: ReadS [TestRenderTemplate]
$creadList :: ReadS [TestRenderTemplate]
readsPrec :: Int -> ReadS TestRenderTemplate
$creadsPrec :: Int -> ReadS TestRenderTemplate
Prelude.Read, Int -> TestRenderTemplate -> ShowS
[TestRenderTemplate] -> ShowS
TestRenderTemplate -> String
(Int -> TestRenderTemplate -> ShowS)
-> (TestRenderTemplate -> String)
-> ([TestRenderTemplate] -> ShowS)
-> Show TestRenderTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestRenderTemplate] -> ShowS
$cshowList :: [TestRenderTemplate] -> ShowS
show :: TestRenderTemplate -> String
$cshow :: TestRenderTemplate -> String
showsPrec :: Int -> TestRenderTemplate -> ShowS
$cshowsPrec :: Int -> TestRenderTemplate -> ShowS
Prelude.Show, (forall x. TestRenderTemplate -> Rep TestRenderTemplate x)
-> (forall x. Rep TestRenderTemplate x -> TestRenderTemplate)
-> Generic TestRenderTemplate
forall x. Rep TestRenderTemplate x -> TestRenderTemplate
forall x. TestRenderTemplate -> Rep TestRenderTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TestRenderTemplate x -> TestRenderTemplate
$cfrom :: forall x. TestRenderTemplate -> Rep TestRenderTemplate x
Prelude.Generic)

-- |
-- Create a value of 'TestRenderTemplate' 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:
--
-- 'templateName', 'testRenderTemplate_templateName' - The name of the template that you want to render.
--
-- 'templateData', 'testRenderTemplate_templateData' - A list of replacement values to apply to the template. This parameter is
-- a JSON object, typically consisting of key-value pairs in which the keys
-- correspond to replacement tags in the email template.
newTestRenderTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  -- | 'templateData'
  Prelude.Text ->
  TestRenderTemplate
newTestRenderTemplate :: Text -> Text -> TestRenderTemplate
newTestRenderTemplate Text
pTemplateName_ Text
pTemplateData_ =
  TestRenderTemplate' :: Text -> Text -> TestRenderTemplate
TestRenderTemplate'
    { $sel:templateName:TestRenderTemplate' :: Text
templateName = Text
pTemplateName_,
      $sel:templateData:TestRenderTemplate' :: Text
templateData = Text
pTemplateData_
    }

-- | The name of the template that you want to render.
testRenderTemplate_templateName :: Lens.Lens' TestRenderTemplate Prelude.Text
testRenderTemplate_templateName :: (Text -> f Text) -> TestRenderTemplate -> f TestRenderTemplate
testRenderTemplate_templateName = (TestRenderTemplate -> Text)
-> (TestRenderTemplate -> Text -> TestRenderTemplate)
-> Lens TestRenderTemplate TestRenderTemplate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestRenderTemplate' {Text
templateName :: Text
$sel:templateName:TestRenderTemplate' :: TestRenderTemplate -> Text
templateName} -> Text
templateName) (\s :: TestRenderTemplate
s@TestRenderTemplate' {} Text
a -> TestRenderTemplate
s {$sel:templateName:TestRenderTemplate' :: Text
templateName = Text
a} :: TestRenderTemplate)

-- | A list of replacement values to apply to the template. This parameter is
-- a JSON object, typically consisting of key-value pairs in which the keys
-- correspond to replacement tags in the email template.
testRenderTemplate_templateData :: Lens.Lens' TestRenderTemplate Prelude.Text
testRenderTemplate_templateData :: (Text -> f Text) -> TestRenderTemplate -> f TestRenderTemplate
testRenderTemplate_templateData = (TestRenderTemplate -> Text)
-> (TestRenderTemplate -> Text -> TestRenderTemplate)
-> Lens TestRenderTemplate TestRenderTemplate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestRenderTemplate' {Text
templateData :: Text
$sel:templateData:TestRenderTemplate' :: TestRenderTemplate -> Text
templateData} -> Text
templateData) (\s :: TestRenderTemplate
s@TestRenderTemplate' {} Text
a -> TestRenderTemplate
s {$sel:templateData:TestRenderTemplate' :: Text
templateData = Text
a} :: TestRenderTemplate)

instance Core.AWSRequest TestRenderTemplate where
  type
    AWSResponse TestRenderTemplate =
      TestRenderTemplateResponse
  request :: TestRenderTemplate -> Request TestRenderTemplate
request = Service -> TestRenderTemplate -> Request TestRenderTemplate
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy TestRenderTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TestRenderTemplate)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse TestRenderTemplate))
-> Logger
-> Service
-> Proxy TestRenderTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TestRenderTemplate)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"TestRenderTemplateResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Int -> TestRenderTemplateResponse
TestRenderTemplateResponse'
            (Maybe Text -> Int -> TestRenderTemplateResponse)
-> Either String (Maybe Text)
-> Either String (Int -> TestRenderTemplateResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"RenderedTemplate")
            Either String (Int -> TestRenderTemplateResponse)
-> Either String Int -> Either String TestRenderTemplateResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable TestRenderTemplate

instance Prelude.NFData TestRenderTemplate

instance Core.ToHeaders TestRenderTemplate where
  toHeaders :: TestRenderTemplate -> ResponseHeaders
toHeaders = ResponseHeaders -> TestRenderTemplate -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery TestRenderTemplate where
  toQuery :: TestRenderTemplate -> QueryString
toQuery TestRenderTemplate' {Text
templateData :: Text
templateName :: Text
$sel:templateData:TestRenderTemplate' :: TestRenderTemplate -> Text
$sel:templateName:TestRenderTemplate' :: TestRenderTemplate -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"TestRenderTemplate" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-12-01" :: Prelude.ByteString),
        ByteString
"TemplateName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
templateName,
        ByteString
"TemplateData" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
templateData
      ]

-- | /See:/ 'newTestRenderTemplateResponse' smart constructor.
data TestRenderTemplateResponse = TestRenderTemplateResponse'
  { -- | The complete MIME message rendered by applying the data in the
    -- TemplateData parameter to the template specified in the TemplateName
    -- parameter.
    TestRenderTemplateResponse -> Maybe Text
renderedTemplate :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    TestRenderTemplateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (TestRenderTemplateResponse -> TestRenderTemplateResponse -> Bool
(TestRenderTemplateResponse -> TestRenderTemplateResponse -> Bool)
-> (TestRenderTemplateResponse
    -> TestRenderTemplateResponse -> Bool)
-> Eq TestRenderTemplateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestRenderTemplateResponse -> TestRenderTemplateResponse -> Bool
$c/= :: TestRenderTemplateResponse -> TestRenderTemplateResponse -> Bool
== :: TestRenderTemplateResponse -> TestRenderTemplateResponse -> Bool
$c== :: TestRenderTemplateResponse -> TestRenderTemplateResponse -> Bool
Prelude.Eq, ReadPrec [TestRenderTemplateResponse]
ReadPrec TestRenderTemplateResponse
Int -> ReadS TestRenderTemplateResponse
ReadS [TestRenderTemplateResponse]
(Int -> ReadS TestRenderTemplateResponse)
-> ReadS [TestRenderTemplateResponse]
-> ReadPrec TestRenderTemplateResponse
-> ReadPrec [TestRenderTemplateResponse]
-> Read TestRenderTemplateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestRenderTemplateResponse]
$creadListPrec :: ReadPrec [TestRenderTemplateResponse]
readPrec :: ReadPrec TestRenderTemplateResponse
$creadPrec :: ReadPrec TestRenderTemplateResponse
readList :: ReadS [TestRenderTemplateResponse]
$creadList :: ReadS [TestRenderTemplateResponse]
readsPrec :: Int -> ReadS TestRenderTemplateResponse
$creadsPrec :: Int -> ReadS TestRenderTemplateResponse
Prelude.Read, Int -> TestRenderTemplateResponse -> ShowS
[TestRenderTemplateResponse] -> ShowS
TestRenderTemplateResponse -> String
(Int -> TestRenderTemplateResponse -> ShowS)
-> (TestRenderTemplateResponse -> String)
-> ([TestRenderTemplateResponse] -> ShowS)
-> Show TestRenderTemplateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestRenderTemplateResponse] -> ShowS
$cshowList :: [TestRenderTemplateResponse] -> ShowS
show :: TestRenderTemplateResponse -> String
$cshow :: TestRenderTemplateResponse -> String
showsPrec :: Int -> TestRenderTemplateResponse -> ShowS
$cshowsPrec :: Int -> TestRenderTemplateResponse -> ShowS
Prelude.Show, (forall x.
 TestRenderTemplateResponse -> Rep TestRenderTemplateResponse x)
-> (forall x.
    Rep TestRenderTemplateResponse x -> TestRenderTemplateResponse)
-> Generic TestRenderTemplateResponse
forall x.
Rep TestRenderTemplateResponse x -> TestRenderTemplateResponse
forall x.
TestRenderTemplateResponse -> Rep TestRenderTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TestRenderTemplateResponse x -> TestRenderTemplateResponse
$cfrom :: forall x.
TestRenderTemplateResponse -> Rep TestRenderTemplateResponse x
Prelude.Generic)

-- |
-- Create a value of 'TestRenderTemplateResponse' 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:
--
-- 'renderedTemplate', 'testRenderTemplateResponse_renderedTemplate' - The complete MIME message rendered by applying the data in the
-- TemplateData parameter to the template specified in the TemplateName
-- parameter.
--
-- 'httpStatus', 'testRenderTemplateResponse_httpStatus' - The response's http status code.
newTestRenderTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TestRenderTemplateResponse
newTestRenderTemplateResponse :: Int -> TestRenderTemplateResponse
newTestRenderTemplateResponse Int
pHttpStatus_ =
  TestRenderTemplateResponse' :: Maybe Text -> Int -> TestRenderTemplateResponse
TestRenderTemplateResponse'
    { $sel:renderedTemplate:TestRenderTemplateResponse' :: Maybe Text
renderedTemplate =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TestRenderTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The complete MIME message rendered by applying the data in the
-- TemplateData parameter to the template specified in the TemplateName
-- parameter.
testRenderTemplateResponse_renderedTemplate :: Lens.Lens' TestRenderTemplateResponse (Prelude.Maybe Prelude.Text)
testRenderTemplateResponse_renderedTemplate :: (Maybe Text -> f (Maybe Text))
-> TestRenderTemplateResponse -> f TestRenderTemplateResponse
testRenderTemplateResponse_renderedTemplate = (TestRenderTemplateResponse -> Maybe Text)
-> (TestRenderTemplateResponse
    -> Maybe Text -> TestRenderTemplateResponse)
-> Lens
     TestRenderTemplateResponse
     TestRenderTemplateResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestRenderTemplateResponse' {Maybe Text
renderedTemplate :: Maybe Text
$sel:renderedTemplate:TestRenderTemplateResponse' :: TestRenderTemplateResponse -> Maybe Text
renderedTemplate} -> Maybe Text
renderedTemplate) (\s :: TestRenderTemplateResponse
s@TestRenderTemplateResponse' {} Maybe Text
a -> TestRenderTemplateResponse
s {$sel:renderedTemplate:TestRenderTemplateResponse' :: Maybe Text
renderedTemplate = Maybe Text
a} :: TestRenderTemplateResponse)

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

instance Prelude.NFData TestRenderTemplateResponse