{-# 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.GetEmailTemplate
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Displays the template object (which includes the subject line, HTML part
-- and text part) for the template you specify.
--
-- You can execute this operation no more than once per second.
module Amazonka.SESV2.GetEmailTemplate
  ( -- * Creating a Request
    GetEmailTemplate (..),
    newGetEmailTemplate,

    -- * Request Lenses
    getEmailTemplate_templateName,

    -- * Destructuring the Response
    GetEmailTemplateResponse (..),
    newGetEmailTemplateResponse,

    -- * Response Lenses
    getEmailTemplateResponse_httpStatus,
    getEmailTemplateResponse_templateName,
    getEmailTemplateResponse_templateContent,
  )
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 display the template object (which includes the
-- subject line, HTML part and text part) for the template you specify.
--
-- /See:/ 'newGetEmailTemplate' smart constructor.
data GetEmailTemplate = GetEmailTemplate'
  { -- | The name of the template.
    GetEmailTemplate -> Text
templateName :: Prelude.Text
  }
  deriving (GetEmailTemplate -> GetEmailTemplate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEmailTemplate -> GetEmailTemplate -> Bool
$c/= :: GetEmailTemplate -> GetEmailTemplate -> Bool
== :: GetEmailTemplate -> GetEmailTemplate -> Bool
$c== :: GetEmailTemplate -> GetEmailTemplate -> Bool
Prelude.Eq, ReadPrec [GetEmailTemplate]
ReadPrec GetEmailTemplate
Int -> ReadS GetEmailTemplate
ReadS [GetEmailTemplate]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEmailTemplate]
$creadListPrec :: ReadPrec [GetEmailTemplate]
readPrec :: ReadPrec GetEmailTemplate
$creadPrec :: ReadPrec GetEmailTemplate
readList :: ReadS [GetEmailTemplate]
$creadList :: ReadS [GetEmailTemplate]
readsPrec :: Int -> ReadS GetEmailTemplate
$creadsPrec :: Int -> ReadS GetEmailTemplate
Prelude.Read, Int -> GetEmailTemplate -> ShowS
[GetEmailTemplate] -> ShowS
GetEmailTemplate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEmailTemplate] -> ShowS
$cshowList :: [GetEmailTemplate] -> ShowS
show :: GetEmailTemplate -> String
$cshow :: GetEmailTemplate -> String
showsPrec :: Int -> GetEmailTemplate -> ShowS
$cshowsPrec :: Int -> GetEmailTemplate -> ShowS
Prelude.Show, forall x. Rep GetEmailTemplate x -> GetEmailTemplate
forall x. GetEmailTemplate -> Rep GetEmailTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetEmailTemplate x -> GetEmailTemplate
$cfrom :: forall x. GetEmailTemplate -> Rep GetEmailTemplate x
Prelude.Generic)

-- |
-- Create a value of 'GetEmailTemplate' 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', 'getEmailTemplate_templateName' - The name of the template.
newGetEmailTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  GetEmailTemplate
newGetEmailTemplate :: Text -> GetEmailTemplate
newGetEmailTemplate Text
pTemplateName_ =
  GetEmailTemplate' {$sel:templateName:GetEmailTemplate' :: Text
templateName = Text
pTemplateName_}

-- | The name of the template.
getEmailTemplate_templateName :: Lens.Lens' GetEmailTemplate Prelude.Text
getEmailTemplate_templateName :: Lens' GetEmailTemplate Text
getEmailTemplate_templateName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailTemplate' {Text
templateName :: Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
templateName} -> Text
templateName) (\s :: GetEmailTemplate
s@GetEmailTemplate' {} Text
a -> GetEmailTemplate
s {$sel:templateName:GetEmailTemplate' :: Text
templateName = Text
a} :: GetEmailTemplate)

instance Core.AWSRequest GetEmailTemplate where
  type
    AWSResponse GetEmailTemplate =
      GetEmailTemplateResponse
  request :: (Service -> Service)
-> GetEmailTemplate -> Request GetEmailTemplate
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 GetEmailTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetEmailTemplate)))
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 ->
          Int -> Text -> EmailTemplateContent -> GetEmailTemplateResponse
GetEmailTemplateResponse'
            forall (f :: * -> *) a b. Functor 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 a
Data..:> Key
"TemplateName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"TemplateContent")
      )

instance Prelude.Hashable GetEmailTemplate where
  hashWithSalt :: Int -> GetEmailTemplate -> Int
hashWithSalt Int
_salt GetEmailTemplate' {Text
templateName :: Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
templateName

instance Prelude.NFData GetEmailTemplate where
  rnf :: GetEmailTemplate -> ()
rnf GetEmailTemplate' {Text
templateName :: Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
templateName

instance Data.ToHeaders GetEmailTemplate where
  toHeaders :: GetEmailTemplate -> 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 GetEmailTemplate where
  toPath :: GetEmailTemplate -> ByteString
toPath GetEmailTemplate' {Text
templateName :: Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v2/email/templates/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
templateName]

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

-- | The following element is returned by the service.
--
-- /See:/ 'newGetEmailTemplateResponse' smart constructor.
data GetEmailTemplateResponse = GetEmailTemplateResponse'
  { -- | The response's http status code.
    GetEmailTemplateResponse -> Int
httpStatus :: Prelude.Int,
    -- | The name of the template.
    GetEmailTemplateResponse -> Text
templateName :: Prelude.Text,
    -- | The content of the email template, composed of a subject line, an HTML
    -- part, and a text-only part.
    GetEmailTemplateResponse -> EmailTemplateContent
templateContent :: EmailTemplateContent
  }
  deriving (GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool
$c/= :: GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool
== :: GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool
$c== :: GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool
Prelude.Eq, ReadPrec [GetEmailTemplateResponse]
ReadPrec GetEmailTemplateResponse
Int -> ReadS GetEmailTemplateResponse
ReadS [GetEmailTemplateResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEmailTemplateResponse]
$creadListPrec :: ReadPrec [GetEmailTemplateResponse]
readPrec :: ReadPrec GetEmailTemplateResponse
$creadPrec :: ReadPrec GetEmailTemplateResponse
readList :: ReadS [GetEmailTemplateResponse]
$creadList :: ReadS [GetEmailTemplateResponse]
readsPrec :: Int -> ReadS GetEmailTemplateResponse
$creadsPrec :: Int -> ReadS GetEmailTemplateResponse
Prelude.Read, Int -> GetEmailTemplateResponse -> ShowS
[GetEmailTemplateResponse] -> ShowS
GetEmailTemplateResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEmailTemplateResponse] -> ShowS
$cshowList :: [GetEmailTemplateResponse] -> ShowS
show :: GetEmailTemplateResponse -> String
$cshow :: GetEmailTemplateResponse -> String
showsPrec :: Int -> GetEmailTemplateResponse -> ShowS
$cshowsPrec :: Int -> GetEmailTemplateResponse -> ShowS
Prelude.Show, forall x.
Rep GetEmailTemplateResponse x -> GetEmailTemplateResponse
forall x.
GetEmailTemplateResponse -> Rep GetEmailTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetEmailTemplateResponse x -> GetEmailTemplateResponse
$cfrom :: forall x.
GetEmailTemplateResponse -> Rep GetEmailTemplateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetEmailTemplateResponse' 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', 'getEmailTemplateResponse_httpStatus' - The response's http status code.
--
-- 'templateName', 'getEmailTemplateResponse_templateName' - The name of the template.
--
-- 'templateContent', 'getEmailTemplateResponse_templateContent' - The content of the email template, composed of a subject line, an HTML
-- part, and a text-only part.
newGetEmailTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'templateName'
  Prelude.Text ->
  -- | 'templateContent'
  EmailTemplateContent ->
  GetEmailTemplateResponse
newGetEmailTemplateResponse :: Int -> Text -> EmailTemplateContent -> GetEmailTemplateResponse
newGetEmailTemplateResponse
  Int
pHttpStatus_
  Text
pTemplateName_
  EmailTemplateContent
pTemplateContent_ =
    GetEmailTemplateResponse'
      { $sel:httpStatus:GetEmailTemplateResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:templateName:GetEmailTemplateResponse' :: Text
templateName = Text
pTemplateName_,
        $sel:templateContent:GetEmailTemplateResponse' :: EmailTemplateContent
templateContent = EmailTemplateContent
pTemplateContent_
      }

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

-- | The name of the template.
getEmailTemplateResponse_templateName :: Lens.Lens' GetEmailTemplateResponse Prelude.Text
getEmailTemplateResponse_templateName :: Lens' GetEmailTemplateResponse Text
getEmailTemplateResponse_templateName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailTemplateResponse' {Text
templateName :: Text
$sel:templateName:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> Text
templateName} -> Text
templateName) (\s :: GetEmailTemplateResponse
s@GetEmailTemplateResponse' {} Text
a -> GetEmailTemplateResponse
s {$sel:templateName:GetEmailTemplateResponse' :: Text
templateName = Text
a} :: GetEmailTemplateResponse)

-- | The content of the email template, composed of a subject line, an HTML
-- part, and a text-only part.
getEmailTemplateResponse_templateContent :: Lens.Lens' GetEmailTemplateResponse EmailTemplateContent
getEmailTemplateResponse_templateContent :: Lens' GetEmailTemplateResponse EmailTemplateContent
getEmailTemplateResponse_templateContent = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailTemplateResponse' {EmailTemplateContent
templateContent :: EmailTemplateContent
$sel:templateContent:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> EmailTemplateContent
templateContent} -> EmailTemplateContent
templateContent) (\s :: GetEmailTemplateResponse
s@GetEmailTemplateResponse' {} EmailTemplateContent
a -> GetEmailTemplateResponse
s {$sel:templateContent:GetEmailTemplateResponse' :: EmailTemplateContent
templateContent = EmailTemplateContent
a} :: GetEmailTemplateResponse)

instance Prelude.NFData GetEmailTemplateResponse where
  rnf :: GetEmailTemplateResponse -> ()
rnf GetEmailTemplateResponse' {Int
Text
EmailTemplateContent
templateContent :: EmailTemplateContent
templateName :: Text
httpStatus :: Int
$sel:templateContent:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> EmailTemplateContent
$sel:templateName:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> Text
$sel:httpStatus:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> Int
..} =
    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 Text
templateName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EmailTemplateContent
templateContent