{-# 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.GetEmailTemplate
-- 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 the content and settings of a message template for messages
-- that are sent through the email channel.
module Amazonka.Pinpoint.GetEmailTemplate
  ( -- * Creating a Request
    GetEmailTemplate (..),
    newGetEmailTemplate,

    -- * Request Lenses
    getEmailTemplate_version,
    getEmailTemplate_templateName,

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

    -- * Response Lenses
    getEmailTemplateResponse_httpStatus,
    getEmailTemplateResponse_emailTemplateResponse,
  )
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:/ 'newGetEmailTemplate' smart constructor.
data GetEmailTemplate = GetEmailTemplate'
  { -- | The unique identifier for the version of the message template to update,
    -- retrieve information about, or delete. To retrieve identifiers and other
    -- information for all the versions of a template, use the Template
    -- Versions resource.
    --
    -- If specified, this value must match the identifier for an existing
    -- template version. If specified for an update operation, this value must
    -- match the identifier for the latest existing version of the template.
    -- This restriction helps ensure that race conditions don\'t occur.
    --
    -- If you don\'t specify a value for this parameter, Amazon Pinpoint does
    -- the following:
    --
    -- -   For a get operation, retrieves information about the active version
    --     of the template.
    --
    -- -   For an update operation, saves the updates to (overwrites) the
    --     latest existing version of the template, if the create-new-version
    --     parameter isn\'t used or is set to false.
    --
    -- -   For a delete operation, deletes the template, including all versions
    --     of the template.
    GetEmailTemplate -> Maybe Text
version :: Prelude.Maybe Prelude.Text,
    -- | The name of the message template. A template name must start with an
    -- alphanumeric character and can contain a maximum of 128 characters. The
    -- characters can be alphanumeric characters, underscores (_), or hyphens
    -- (-). Template names are case sensitive.
    GetEmailTemplate -> Text
templateName :: Prelude.Text
  }
  deriving (GetEmailTemplate -> GetEmailTemplate -> Bool
(GetEmailTemplate -> GetEmailTemplate -> Bool)
-> (GetEmailTemplate -> GetEmailTemplate -> Bool)
-> Eq GetEmailTemplate
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]
(Int -> ReadS GetEmailTemplate)
-> ReadS [GetEmailTemplate]
-> ReadPrec GetEmailTemplate
-> ReadPrec [GetEmailTemplate]
-> Read 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
(Int -> GetEmailTemplate -> ShowS)
-> (GetEmailTemplate -> String)
-> ([GetEmailTemplate] -> ShowS)
-> Show GetEmailTemplate
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. GetEmailTemplate -> Rep GetEmailTemplate x)
-> (forall x. Rep GetEmailTemplate x -> GetEmailTemplate)
-> Generic GetEmailTemplate
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:
--
-- 'version', 'getEmailTemplate_version' - The unique identifier for the version of the message template to update,
-- retrieve information about, or delete. To retrieve identifiers and other
-- information for all the versions of a template, use the Template
-- Versions resource.
--
-- If specified, this value must match the identifier for an existing
-- template version. If specified for an update operation, this value must
-- match the identifier for the latest existing version of the template.
-- This restriction helps ensure that race conditions don\'t occur.
--
-- If you don\'t specify a value for this parameter, Amazon Pinpoint does
-- the following:
--
-- -   For a get operation, retrieves information about the active version
--     of the template.
--
-- -   For an update operation, saves the updates to (overwrites) the
--     latest existing version of the template, if the create-new-version
--     parameter isn\'t used or is set to false.
--
-- -   For a delete operation, deletes the template, including all versions
--     of the template.
--
-- 'templateName', 'getEmailTemplate_templateName' - The name of the message template. A template name must start with an
-- alphanumeric character and can contain a maximum of 128 characters. The
-- characters can be alphanumeric characters, underscores (_), or hyphens
-- (-). Template names are case sensitive.
newGetEmailTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  GetEmailTemplate
newGetEmailTemplate :: Text -> GetEmailTemplate
newGetEmailTemplate Text
pTemplateName_ =
  GetEmailTemplate' :: Maybe Text -> Text -> GetEmailTemplate
GetEmailTemplate'
    { $sel:version:GetEmailTemplate' :: Maybe Text
version = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:templateName:GetEmailTemplate' :: Text
templateName = Text
pTemplateName_
    }

-- | The unique identifier for the version of the message template to update,
-- retrieve information about, or delete. To retrieve identifiers and other
-- information for all the versions of a template, use the Template
-- Versions resource.
--
-- If specified, this value must match the identifier for an existing
-- template version. If specified for an update operation, this value must
-- match the identifier for the latest existing version of the template.
-- This restriction helps ensure that race conditions don\'t occur.
--
-- If you don\'t specify a value for this parameter, Amazon Pinpoint does
-- the following:
--
-- -   For a get operation, retrieves information about the active version
--     of the template.
--
-- -   For an update operation, saves the updates to (overwrites) the
--     latest existing version of the template, if the create-new-version
--     parameter isn\'t used or is set to false.
--
-- -   For a delete operation, deletes the template, including all versions
--     of the template.
getEmailTemplate_version :: Lens.Lens' GetEmailTemplate (Prelude.Maybe Prelude.Text)
getEmailTemplate_version :: (Maybe Text -> f (Maybe Text))
-> GetEmailTemplate -> f GetEmailTemplate
getEmailTemplate_version = (GetEmailTemplate -> Maybe Text)
-> (GetEmailTemplate -> Maybe Text -> GetEmailTemplate)
-> Lens GetEmailTemplate GetEmailTemplate (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailTemplate' {Maybe Text
version :: Maybe Text
$sel:version:GetEmailTemplate' :: GetEmailTemplate -> Maybe Text
version} -> Maybe Text
version) (\s :: GetEmailTemplate
s@GetEmailTemplate' {} Maybe Text
a -> GetEmailTemplate
s {$sel:version:GetEmailTemplate' :: Maybe Text
version = Maybe Text
a} :: GetEmailTemplate)

-- | The name of the message template. A template name must start with an
-- alphanumeric character and can contain a maximum of 128 characters. The
-- characters can be alphanumeric characters, underscores (_), or hyphens
-- (-). Template names are case sensitive.
getEmailTemplate_templateName :: Lens.Lens' GetEmailTemplate Prelude.Text
getEmailTemplate_templateName :: (Text -> f Text) -> GetEmailTemplate -> f GetEmailTemplate
getEmailTemplate_templateName = (GetEmailTemplate -> Text)
-> (GetEmailTemplate -> Text -> GetEmailTemplate)
-> Lens GetEmailTemplate GetEmailTemplate Text Text
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 :: GetEmailTemplate -> Request GetEmailTemplate
request = Service -> GetEmailTemplate -> Request GetEmailTemplate
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetEmailTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetEmailTemplate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetEmailTemplate))
-> Logger
-> Service
-> Proxy GetEmailTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetEmailTemplate)))
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 -> EmailTemplateResponse -> GetEmailTemplateResponse
GetEmailTemplateResponse'
            (Int -> EmailTemplateResponse -> GetEmailTemplateResponse)
-> Either String Int
-> Either
     String (EmailTemplateResponse -> GetEmailTemplateResponse)
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 (EmailTemplateResponse -> GetEmailTemplateResponse)
-> Either String EmailTemplateResponse
-> Either String GetEmailTemplateResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object -> Either String EmailTemplateResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
      )

instance Prelude.Hashable GetEmailTemplate

instance Prelude.NFData GetEmailTemplate

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

instance Core.ToQuery GetEmailTemplate where
  toQuery :: GetEmailTemplate -> QueryString
toQuery GetEmailTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
$sel:version:GetEmailTemplate' :: GetEmailTemplate -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"version" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
version]

-- | /See:/ 'newGetEmailTemplateResponse' smart constructor.
data GetEmailTemplateResponse = GetEmailTemplateResponse'
  { -- | The response's http status code.
    GetEmailTemplateResponse -> Int
httpStatus :: Prelude.Int,
    GetEmailTemplateResponse -> EmailTemplateResponse
emailTemplateResponse :: EmailTemplateResponse
  }
  deriving (GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool
(GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool)
-> (GetEmailTemplateResponse -> GetEmailTemplateResponse -> Bool)
-> Eq GetEmailTemplateResponse
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]
(Int -> ReadS GetEmailTemplateResponse)
-> ReadS [GetEmailTemplateResponse]
-> ReadPrec GetEmailTemplateResponse
-> ReadPrec [GetEmailTemplateResponse]
-> Read 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
(Int -> GetEmailTemplateResponse -> ShowS)
-> (GetEmailTemplateResponse -> String)
-> ([GetEmailTemplateResponse] -> ShowS)
-> Show GetEmailTemplateResponse
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.
 GetEmailTemplateResponse -> Rep GetEmailTemplateResponse x)
-> (forall x.
    Rep GetEmailTemplateResponse x -> GetEmailTemplateResponse)
-> Generic GetEmailTemplateResponse
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.
--
-- 'emailTemplateResponse', 'getEmailTemplateResponse_emailTemplateResponse' - Undocumented member.
newGetEmailTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'emailTemplateResponse'
  EmailTemplateResponse ->
  GetEmailTemplateResponse
newGetEmailTemplateResponse :: Int -> EmailTemplateResponse -> GetEmailTemplateResponse
newGetEmailTemplateResponse
  Int
pHttpStatus_
  EmailTemplateResponse
pEmailTemplateResponse_ =
    GetEmailTemplateResponse' :: Int -> EmailTemplateResponse -> GetEmailTemplateResponse
GetEmailTemplateResponse'
      { $sel:httpStatus:GetEmailTemplateResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:emailTemplateResponse:GetEmailTemplateResponse' :: EmailTemplateResponse
emailTemplateResponse = EmailTemplateResponse
pEmailTemplateResponse_
      }

-- | The response's http status code.
getEmailTemplateResponse_httpStatus :: Lens.Lens' GetEmailTemplateResponse Prelude.Int
getEmailTemplateResponse_httpStatus :: (Int -> f Int)
-> GetEmailTemplateResponse -> f GetEmailTemplateResponse
getEmailTemplateResponse_httpStatus = (GetEmailTemplateResponse -> Int)
-> (GetEmailTemplateResponse -> Int -> GetEmailTemplateResponse)
-> Lens GetEmailTemplateResponse GetEmailTemplateResponse Int Int
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)

-- | Undocumented member.
getEmailTemplateResponse_emailTemplateResponse :: Lens.Lens' GetEmailTemplateResponse EmailTemplateResponse
getEmailTemplateResponse_emailTemplateResponse :: (EmailTemplateResponse -> f EmailTemplateResponse)
-> GetEmailTemplateResponse -> f GetEmailTemplateResponse
getEmailTemplateResponse_emailTemplateResponse = (GetEmailTemplateResponse -> EmailTemplateResponse)
-> (GetEmailTemplateResponse
    -> EmailTemplateResponse -> GetEmailTemplateResponse)
-> Lens
     GetEmailTemplateResponse
     GetEmailTemplateResponse
     EmailTemplateResponse
     EmailTemplateResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailTemplateResponse' {EmailTemplateResponse
emailTemplateResponse :: EmailTemplateResponse
$sel:emailTemplateResponse:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> EmailTemplateResponse
emailTemplateResponse} -> EmailTemplateResponse
emailTemplateResponse) (\s :: GetEmailTemplateResponse
s@GetEmailTemplateResponse' {} EmailTemplateResponse
a -> GetEmailTemplateResponse
s {$sel:emailTemplateResponse:GetEmailTemplateResponse' :: EmailTemplateResponse
emailTemplateResponse = EmailTemplateResponse
a} :: GetEmailTemplateResponse)

instance Prelude.NFData GetEmailTemplateResponse