{-# 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.GetSmsTemplate
-- 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 SMS channel.
module Amazonka.Pinpoint.GetSmsTemplate
  ( -- * Creating a Request
    GetSmsTemplate (..),
    newGetSmsTemplate,

    -- * Request Lenses
    getSmsTemplate_version,
    getSmsTemplate_templateName,

    -- * Destructuring the Response
    GetSmsTemplateResponse (..),
    newGetSmsTemplateResponse,

    -- * Response Lenses
    getSmsTemplateResponse_httpStatus,
    getSmsTemplateResponse_sMSTemplateResponse,
  )
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:/ 'newGetSmsTemplate' smart constructor.
data GetSmsTemplate = GetSmsTemplate'
  { -- | 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.
    GetSmsTemplate -> 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.
    GetSmsTemplate -> Text
templateName :: Prelude.Text
  }
  deriving (GetSmsTemplate -> GetSmsTemplate -> Bool
(GetSmsTemplate -> GetSmsTemplate -> Bool)
-> (GetSmsTemplate -> GetSmsTemplate -> Bool) -> Eq GetSmsTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetSmsTemplate -> GetSmsTemplate -> Bool
$c/= :: GetSmsTemplate -> GetSmsTemplate -> Bool
== :: GetSmsTemplate -> GetSmsTemplate -> Bool
$c== :: GetSmsTemplate -> GetSmsTemplate -> Bool
Prelude.Eq, ReadPrec [GetSmsTemplate]
ReadPrec GetSmsTemplate
Int -> ReadS GetSmsTemplate
ReadS [GetSmsTemplate]
(Int -> ReadS GetSmsTemplate)
-> ReadS [GetSmsTemplate]
-> ReadPrec GetSmsTemplate
-> ReadPrec [GetSmsTemplate]
-> Read GetSmsTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetSmsTemplate]
$creadListPrec :: ReadPrec [GetSmsTemplate]
readPrec :: ReadPrec GetSmsTemplate
$creadPrec :: ReadPrec GetSmsTemplate
readList :: ReadS [GetSmsTemplate]
$creadList :: ReadS [GetSmsTemplate]
readsPrec :: Int -> ReadS GetSmsTemplate
$creadsPrec :: Int -> ReadS GetSmsTemplate
Prelude.Read, Int -> GetSmsTemplate -> ShowS
[GetSmsTemplate] -> ShowS
GetSmsTemplate -> String
(Int -> GetSmsTemplate -> ShowS)
-> (GetSmsTemplate -> String)
-> ([GetSmsTemplate] -> ShowS)
-> Show GetSmsTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetSmsTemplate] -> ShowS
$cshowList :: [GetSmsTemplate] -> ShowS
show :: GetSmsTemplate -> String
$cshow :: GetSmsTemplate -> String
showsPrec :: Int -> GetSmsTemplate -> ShowS
$cshowsPrec :: Int -> GetSmsTemplate -> ShowS
Prelude.Show, (forall x. GetSmsTemplate -> Rep GetSmsTemplate x)
-> (forall x. Rep GetSmsTemplate x -> GetSmsTemplate)
-> Generic GetSmsTemplate
forall x. Rep GetSmsTemplate x -> GetSmsTemplate
forall x. GetSmsTemplate -> Rep GetSmsTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetSmsTemplate x -> GetSmsTemplate
$cfrom :: forall x. GetSmsTemplate -> Rep GetSmsTemplate x
Prelude.Generic)

-- |
-- Create a value of 'GetSmsTemplate' 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', 'getSmsTemplate_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', 'getSmsTemplate_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.
newGetSmsTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  GetSmsTemplate
newGetSmsTemplate :: Text -> GetSmsTemplate
newGetSmsTemplate Text
pTemplateName_ =
  GetSmsTemplate' :: Maybe Text -> Text -> GetSmsTemplate
GetSmsTemplate'
    { $sel:version:GetSmsTemplate' :: Maybe Text
version = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:templateName:GetSmsTemplate' :: 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.
getSmsTemplate_version :: Lens.Lens' GetSmsTemplate (Prelude.Maybe Prelude.Text)
getSmsTemplate_version :: (Maybe Text -> f (Maybe Text))
-> GetSmsTemplate -> f GetSmsTemplate
getSmsTemplate_version = (GetSmsTemplate -> Maybe Text)
-> (GetSmsTemplate -> Maybe Text -> GetSmsTemplate)
-> Lens GetSmsTemplate GetSmsTemplate (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSmsTemplate' {Maybe Text
version :: Maybe Text
$sel:version:GetSmsTemplate' :: GetSmsTemplate -> Maybe Text
version} -> Maybe Text
version) (\s :: GetSmsTemplate
s@GetSmsTemplate' {} Maybe Text
a -> GetSmsTemplate
s {$sel:version:GetSmsTemplate' :: Maybe Text
version = Maybe Text
a} :: GetSmsTemplate)

-- | 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.
getSmsTemplate_templateName :: Lens.Lens' GetSmsTemplate Prelude.Text
getSmsTemplate_templateName :: (Text -> f Text) -> GetSmsTemplate -> f GetSmsTemplate
getSmsTemplate_templateName = (GetSmsTemplate -> Text)
-> (GetSmsTemplate -> Text -> GetSmsTemplate)
-> Lens GetSmsTemplate GetSmsTemplate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSmsTemplate' {Text
templateName :: Text
$sel:templateName:GetSmsTemplate' :: GetSmsTemplate -> Text
templateName} -> Text
templateName) (\s :: GetSmsTemplate
s@GetSmsTemplate' {} Text
a -> GetSmsTemplate
s {$sel:templateName:GetSmsTemplate' :: Text
templateName = Text
a} :: GetSmsTemplate)

instance Core.AWSRequest GetSmsTemplate where
  type
    AWSResponse GetSmsTemplate =
      GetSmsTemplateResponse
  request :: GetSmsTemplate -> Request GetSmsTemplate
request = Service -> GetSmsTemplate -> Request GetSmsTemplate
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetSmsTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetSmsTemplate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetSmsTemplate))
-> Logger
-> Service
-> Proxy GetSmsTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetSmsTemplate)))
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 -> SMSTemplateResponse -> GetSmsTemplateResponse
GetSmsTemplateResponse'
            (Int -> SMSTemplateResponse -> GetSmsTemplateResponse)
-> Either String Int
-> Either String (SMSTemplateResponse -> GetSmsTemplateResponse)
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 (SMSTemplateResponse -> GetSmsTemplateResponse)
-> Either String SMSTemplateResponse
-> Either String GetSmsTemplateResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object -> Either String SMSTemplateResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
      )

instance Prelude.Hashable GetSmsTemplate

instance Prelude.NFData GetSmsTemplate

instance Core.ToHeaders GetSmsTemplate where
  toHeaders :: GetSmsTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetSmsTemplate -> 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 GetSmsTemplate where
  toPath :: GetSmsTemplate -> ByteString
toPath GetSmsTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetSmsTemplate' :: GetSmsTemplate -> Text
$sel:version:GetSmsTemplate' :: GetSmsTemplate -> 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
"/sms"]

instance Core.ToQuery GetSmsTemplate where
  toQuery :: GetSmsTemplate -> QueryString
toQuery GetSmsTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetSmsTemplate' :: GetSmsTemplate -> Text
$sel:version:GetSmsTemplate' :: GetSmsTemplate -> 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:/ 'newGetSmsTemplateResponse' smart constructor.
data GetSmsTemplateResponse = GetSmsTemplateResponse'
  { -- | The response's http status code.
    GetSmsTemplateResponse -> Int
httpStatus :: Prelude.Int,
    GetSmsTemplateResponse -> SMSTemplateResponse
sMSTemplateResponse :: SMSTemplateResponse
  }
  deriving (GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool
(GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool)
-> (GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool)
-> Eq GetSmsTemplateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool
$c/= :: GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool
== :: GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool
$c== :: GetSmsTemplateResponse -> GetSmsTemplateResponse -> Bool
Prelude.Eq, ReadPrec [GetSmsTemplateResponse]
ReadPrec GetSmsTemplateResponse
Int -> ReadS GetSmsTemplateResponse
ReadS [GetSmsTemplateResponse]
(Int -> ReadS GetSmsTemplateResponse)
-> ReadS [GetSmsTemplateResponse]
-> ReadPrec GetSmsTemplateResponse
-> ReadPrec [GetSmsTemplateResponse]
-> Read GetSmsTemplateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetSmsTemplateResponse]
$creadListPrec :: ReadPrec [GetSmsTemplateResponse]
readPrec :: ReadPrec GetSmsTemplateResponse
$creadPrec :: ReadPrec GetSmsTemplateResponse
readList :: ReadS [GetSmsTemplateResponse]
$creadList :: ReadS [GetSmsTemplateResponse]
readsPrec :: Int -> ReadS GetSmsTemplateResponse
$creadsPrec :: Int -> ReadS GetSmsTemplateResponse
Prelude.Read, Int -> GetSmsTemplateResponse -> ShowS
[GetSmsTemplateResponse] -> ShowS
GetSmsTemplateResponse -> String
(Int -> GetSmsTemplateResponse -> ShowS)
-> (GetSmsTemplateResponse -> String)
-> ([GetSmsTemplateResponse] -> ShowS)
-> Show GetSmsTemplateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetSmsTemplateResponse] -> ShowS
$cshowList :: [GetSmsTemplateResponse] -> ShowS
show :: GetSmsTemplateResponse -> String
$cshow :: GetSmsTemplateResponse -> String
showsPrec :: Int -> GetSmsTemplateResponse -> ShowS
$cshowsPrec :: Int -> GetSmsTemplateResponse -> ShowS
Prelude.Show, (forall x. GetSmsTemplateResponse -> Rep GetSmsTemplateResponse x)
-> (forall x.
    Rep GetSmsTemplateResponse x -> GetSmsTemplateResponse)
-> Generic GetSmsTemplateResponse
forall x. Rep GetSmsTemplateResponse x -> GetSmsTemplateResponse
forall x. GetSmsTemplateResponse -> Rep GetSmsTemplateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetSmsTemplateResponse x -> GetSmsTemplateResponse
$cfrom :: forall x. GetSmsTemplateResponse -> Rep GetSmsTemplateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetSmsTemplateResponse' 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', 'getSmsTemplateResponse_httpStatus' - The response's http status code.
--
-- 'sMSTemplateResponse', 'getSmsTemplateResponse_sMSTemplateResponse' - Undocumented member.
newGetSmsTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'sMSTemplateResponse'
  SMSTemplateResponse ->
  GetSmsTemplateResponse
newGetSmsTemplateResponse :: Int -> SMSTemplateResponse -> GetSmsTemplateResponse
newGetSmsTemplateResponse
  Int
pHttpStatus_
  SMSTemplateResponse
pSMSTemplateResponse_ =
    GetSmsTemplateResponse' :: Int -> SMSTemplateResponse -> GetSmsTemplateResponse
GetSmsTemplateResponse'
      { $sel:httpStatus:GetSmsTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:sMSTemplateResponse:GetSmsTemplateResponse' :: SMSTemplateResponse
sMSTemplateResponse = SMSTemplateResponse
pSMSTemplateResponse_
      }

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

-- | Undocumented member.
getSmsTemplateResponse_sMSTemplateResponse :: Lens.Lens' GetSmsTemplateResponse SMSTemplateResponse
getSmsTemplateResponse_sMSTemplateResponse :: (SMSTemplateResponse -> f SMSTemplateResponse)
-> GetSmsTemplateResponse -> f GetSmsTemplateResponse
getSmsTemplateResponse_sMSTemplateResponse = (GetSmsTemplateResponse -> SMSTemplateResponse)
-> (GetSmsTemplateResponse
    -> SMSTemplateResponse -> GetSmsTemplateResponse)
-> Lens
     GetSmsTemplateResponse
     GetSmsTemplateResponse
     SMSTemplateResponse
     SMSTemplateResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSmsTemplateResponse' {SMSTemplateResponse
sMSTemplateResponse :: SMSTemplateResponse
$sel:sMSTemplateResponse:GetSmsTemplateResponse' :: GetSmsTemplateResponse -> SMSTemplateResponse
sMSTemplateResponse} -> SMSTemplateResponse
sMSTemplateResponse) (\s :: GetSmsTemplateResponse
s@GetSmsTemplateResponse' {} SMSTemplateResponse
a -> GetSmsTemplateResponse
s {$sel:sMSTemplateResponse:GetSmsTemplateResponse' :: SMSTemplateResponse
sMSTemplateResponse = SMSTemplateResponse
a} :: GetSmsTemplateResponse)

instance Prelude.NFData GetSmsTemplateResponse