{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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:
--
-- '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'
    { $sel:version:GetEmailTemplate' :: Maybe Text
version = 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 :: Lens' GetEmailTemplate (Maybe Text)
getEmailTemplate_version = 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 :: 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 -> EmailTemplateResponse -> 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.<*> (forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)
      )

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

instance Prelude.NFData GetEmailTemplate where
  rnf :: GetEmailTemplate -> ()
rnf GetEmailTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
$sel:version:GetEmailTemplate' :: GetEmailTemplate -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
version
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetEmailTemplate' :: GetEmailTemplate -> Text
$sel:version:GetEmailTemplate' :: GetEmailTemplate -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/templates/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
templateName, ByteString
"/email"]

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"version" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: 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
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.
--
-- 'emailTemplateResponse', 'getEmailTemplateResponse_emailTemplateResponse' - Undocumented member.
newGetEmailTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'emailTemplateResponse'
  EmailTemplateResponse ->
  GetEmailTemplateResponse
newGetEmailTemplateResponse :: Int -> EmailTemplateResponse -> GetEmailTemplateResponse
newGetEmailTemplateResponse
  Int
pHttpStatus_
  EmailTemplateResponse
pEmailTemplateResponse_ =
    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 :: 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)

-- | Undocumented member.
getEmailTemplateResponse_emailTemplateResponse :: Lens.Lens' GetEmailTemplateResponse EmailTemplateResponse
getEmailTemplateResponse_emailTemplateResponse :: Lens' GetEmailTemplateResponse EmailTemplateResponse
getEmailTemplateResponse_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 where
  rnf :: GetEmailTemplateResponse -> ()
rnf GetEmailTemplateResponse' {Int
EmailTemplateResponse
emailTemplateResponse :: EmailTemplateResponse
httpStatus :: Int
$sel:emailTemplateResponse:GetEmailTemplateResponse' :: GetEmailTemplateResponse -> EmailTemplateResponse
$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 EmailTemplateResponse
emailTemplateResponse