{-# 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-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 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.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:/ '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
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]
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
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. 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'
    { $sel:version:GetSmsTemplate' :: Maybe Text
version = 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 :: Lens' GetSmsTemplate (Maybe Text)
getSmsTemplate_version = 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 :: Lens' GetSmsTemplate Text
getSmsTemplate_templateName = 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 :: (Service -> Service) -> GetSmsTemplate -> Request GetSmsTemplate
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 GetSmsTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetSmsTemplate)))
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 -> SMSTemplateResponse -> GetSmsTemplateResponse
GetSmsTemplateResponse'
            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 GetSmsTemplate where
  hashWithSalt :: Int -> GetSmsTemplate -> Int
hashWithSalt Int
_salt GetSmsTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetSmsTemplate' :: GetSmsTemplate -> Text
$sel:version:GetSmsTemplate' :: GetSmsTemplate -> 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 GetSmsTemplate where
  rnf :: GetSmsTemplate -> ()
rnf GetSmsTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetSmsTemplate' :: GetSmsTemplate -> Text
$sel:version:GetSmsTemplate' :: GetSmsTemplate -> 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 GetSmsTemplate where
  toHeaders :: GetSmsTemplate -> 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 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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/templates/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
templateName, ByteString
"/sms"]

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"version" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: 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
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]
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
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. 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'
      { $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 :: Lens' GetSmsTemplateResponse Int
getSmsTemplateResponse_httpStatus = 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 :: Lens' GetSmsTemplateResponse SMSTemplateResponse
getSmsTemplateResponse_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 where
  rnf :: GetSmsTemplateResponse -> ()
rnf GetSmsTemplateResponse' {Int
SMSTemplateResponse
sMSTemplateResponse :: SMSTemplateResponse
httpStatus :: Int
$sel:sMSTemplateResponse:GetSmsTemplateResponse' :: GetSmsTemplateResponse -> SMSTemplateResponse
$sel:httpStatus:GetSmsTemplateResponse' :: GetSmsTemplateResponse -> 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 SMSTemplateResponse
sMSTemplateResponse