{-# 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.GetTemplate
-- 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.SES.GetTemplate
  ( -- * Creating a Request
    GetTemplate (..),
    newGetTemplate,

    -- * Request Lenses
    getTemplate_templateName,

    -- * Destructuring the Response
    GetTemplateResponse (..),
    newGetTemplateResponse,

    -- * Response Lenses
    getTemplateResponse_template,
    getTemplateResponse_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.SES.Types

-- | /See:/ 'newGetTemplate' smart constructor.
data GetTemplate = GetTemplate'
  { -- | The name of the template you want to retrieve.
    GetTemplate -> Text
templateName :: Prelude.Text
  }
  deriving (GetTemplate -> GetTemplate -> Bool
(GetTemplate -> GetTemplate -> Bool)
-> (GetTemplate -> GetTemplate -> Bool) -> Eq GetTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetTemplate -> GetTemplate -> Bool
== :: GetTemplate -> GetTemplate -> Bool
$c/= :: GetTemplate -> GetTemplate -> Bool
/= :: GetTemplate -> GetTemplate -> Bool
Prelude.Eq, ReadPrec [GetTemplate]
ReadPrec GetTemplate
Int -> ReadS GetTemplate
ReadS [GetTemplate]
(Int -> ReadS GetTemplate)
-> ReadS [GetTemplate]
-> ReadPrec GetTemplate
-> ReadPrec [GetTemplate]
-> Read GetTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS GetTemplate
readsPrec :: Int -> ReadS GetTemplate
$creadList :: ReadS [GetTemplate]
readList :: ReadS [GetTemplate]
$creadPrec :: ReadPrec GetTemplate
readPrec :: ReadPrec GetTemplate
$creadListPrec :: ReadPrec [GetTemplate]
readListPrec :: ReadPrec [GetTemplate]
Prelude.Read, Int -> GetTemplate -> ShowS
[GetTemplate] -> ShowS
GetTemplate -> String
(Int -> GetTemplate -> ShowS)
-> (GetTemplate -> String)
-> ([GetTemplate] -> ShowS)
-> Show GetTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetTemplate -> ShowS
showsPrec :: Int -> GetTemplate -> ShowS
$cshow :: GetTemplate -> String
show :: GetTemplate -> String
$cshowList :: [GetTemplate] -> ShowS
showList :: [GetTemplate] -> ShowS
Prelude.Show, (forall x. GetTemplate -> Rep GetTemplate x)
-> (forall x. Rep GetTemplate x -> GetTemplate)
-> Generic GetTemplate
forall x. Rep GetTemplate x -> GetTemplate
forall x. GetTemplate -> Rep GetTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GetTemplate -> Rep GetTemplate x
from :: forall x. GetTemplate -> Rep GetTemplate x
$cto :: forall x. Rep GetTemplate x -> GetTemplate
to :: forall x. Rep GetTemplate x -> GetTemplate
Prelude.Generic)

-- |
-- Create a value of 'GetTemplate' 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', 'getTemplate_templateName' - The name of the template you want to retrieve.
newGetTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  GetTemplate
newGetTemplate :: Text -> GetTemplate
newGetTemplate Text
pTemplateName_ =
  GetTemplate' {$sel:templateName:GetTemplate' :: Text
templateName = Text
pTemplateName_}

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

instance Core.AWSRequest GetTemplate where
  type AWSResponse GetTemplate = GetTemplateResponse
  request :: (Service -> Service) -> GetTemplate -> Request GetTemplate
request Service -> Service
overrides =
    Service -> GetTemplate -> Request GetTemplate
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetTemplate)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetTemplate))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetTemplate)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"GetTemplateResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Template -> Int -> GetTemplateResponse
GetTemplateResponse'
            (Maybe Template -> Int -> GetTemplateResponse)
-> Either String (Maybe Template)
-> Either String (Int -> GetTemplateResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Template)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Template")
            Either String (Int -> GetTemplateResponse)
-> Either String Int -> Either String GetTemplateResponse
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall a. a -> Either String a
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 GetTemplate where
  hashWithSalt :: Int -> GetTemplate -> Int
hashWithSalt Int
_salt GetTemplate' {Text
$sel:templateName:GetTemplate' :: GetTemplate -> Text
templateName :: Text
..} =
    Int
_salt Int -> Text -> Int
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
templateName

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

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

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

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

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

-- |
-- Create a value of 'GetTemplateResponse' 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:
--
-- 'template', 'getTemplateResponse_template' - Undocumented member.
--
-- 'httpStatus', 'getTemplateResponse_httpStatus' - The response's http status code.
newGetTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetTemplateResponse
newGetTemplateResponse :: Int -> GetTemplateResponse
newGetTemplateResponse Int
pHttpStatus_ =
  GetTemplateResponse'
    { $sel:template:GetTemplateResponse' :: Maybe Template
template = Maybe Template
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
getTemplateResponse_template :: Lens.Lens' GetTemplateResponse (Prelude.Maybe Template)
getTemplateResponse_template :: Lens' GetTemplateResponse (Maybe Template)
getTemplateResponse_template = (GetTemplateResponse -> Maybe Template)
-> (GetTemplateResponse -> Maybe Template -> GetTemplateResponse)
-> Lens' GetTemplateResponse (Maybe Template)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTemplateResponse' {Maybe Template
$sel:template:GetTemplateResponse' :: GetTemplateResponse -> Maybe Template
template :: Maybe Template
template} -> Maybe Template
template) (\s :: GetTemplateResponse
s@GetTemplateResponse' {} Maybe Template
a -> GetTemplateResponse
s {template = a} :: GetTemplateResponse)

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

instance Prelude.NFData GetTemplateResponse where
  rnf :: GetTemplateResponse -> ()
rnf GetTemplateResponse' {Int
Maybe Template
$sel:template:GetTemplateResponse' :: GetTemplateResponse -> Maybe Template
$sel:httpStatus:GetTemplateResponse' :: GetTemplateResponse -> Int
template :: Maybe Template
httpStatus :: Int
..} =
    Maybe Template -> ()
forall a. NFData a => a -> ()
Prelude.rnf Maybe Template
template
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Int -> ()
forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus