{-# 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.CreateSmsTemplate
-- 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)
--
-- Creates a message template for messages that are sent through the SMS
-- channel.
module Amazonka.Pinpoint.CreateSmsTemplate
  ( -- * Creating a Request
    CreateSmsTemplate (..),
    newCreateSmsTemplate,

    -- * Request Lenses
    createSmsTemplate_templateName,
    createSmsTemplate_sMSTemplateRequest,

    -- * Destructuring the Response
    CreateSmsTemplateResponse (..),
    newCreateSmsTemplateResponse,

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

-- |
-- Create a value of 'CreateSmsTemplate' 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', 'createSmsTemplate_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.
--
-- 'sMSTemplateRequest', 'createSmsTemplate_sMSTemplateRequest' - Undocumented member.
newCreateSmsTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  -- | 'sMSTemplateRequest'
  SMSTemplateRequest ->
  CreateSmsTemplate
newCreateSmsTemplate :: Text -> SMSTemplateRequest -> CreateSmsTemplate
newCreateSmsTemplate
  Text
pTemplateName_
  SMSTemplateRequest
pSMSTemplateRequest_ =
    CreateSmsTemplate' :: Text -> SMSTemplateRequest -> CreateSmsTemplate
CreateSmsTemplate'
      { $sel:templateName:CreateSmsTemplate' :: Text
templateName = Text
pTemplateName_,
        $sel:sMSTemplateRequest:CreateSmsTemplate' :: SMSTemplateRequest
sMSTemplateRequest = SMSTemplateRequest
pSMSTemplateRequest_
      }

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

-- | Undocumented member.
createSmsTemplate_sMSTemplateRequest :: Lens.Lens' CreateSmsTemplate SMSTemplateRequest
createSmsTemplate_sMSTemplateRequest :: (SMSTemplateRequest -> f SMSTemplateRequest)
-> CreateSmsTemplate -> f CreateSmsTemplate
createSmsTemplate_sMSTemplateRequest = (CreateSmsTemplate -> SMSTemplateRequest)
-> (CreateSmsTemplate -> SMSTemplateRequest -> CreateSmsTemplate)
-> Lens
     CreateSmsTemplate
     CreateSmsTemplate
     SMSTemplateRequest
     SMSTemplateRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSmsTemplate' {SMSTemplateRequest
sMSTemplateRequest :: SMSTemplateRequest
$sel:sMSTemplateRequest:CreateSmsTemplate' :: CreateSmsTemplate -> SMSTemplateRequest
sMSTemplateRequest} -> SMSTemplateRequest
sMSTemplateRequest) (\s :: CreateSmsTemplate
s@CreateSmsTemplate' {} SMSTemplateRequest
a -> CreateSmsTemplate
s {$sel:sMSTemplateRequest:CreateSmsTemplate' :: SMSTemplateRequest
sMSTemplateRequest = SMSTemplateRequest
a} :: CreateSmsTemplate)

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

instance Prelude.Hashable CreateSmsTemplate

instance Prelude.NFData CreateSmsTemplate

instance Core.ToHeaders CreateSmsTemplate where
  toHeaders :: CreateSmsTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateSmsTemplate -> 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.ToJSON CreateSmsTemplate where
  toJSON :: CreateSmsTemplate -> Value
toJSON CreateSmsTemplate' {Text
SMSTemplateRequest
sMSTemplateRequest :: SMSTemplateRequest
templateName :: Text
$sel:sMSTemplateRequest:CreateSmsTemplate' :: CreateSmsTemplate -> SMSTemplateRequest
$sel:templateName:CreateSmsTemplate' :: CreateSmsTemplate -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"SMSTemplateRequest" Text -> SMSTemplateRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SMSTemplateRequest
sMSTemplateRequest)
          ]
      )

instance Core.ToPath CreateSmsTemplate where
  toPath :: CreateSmsTemplate -> ByteString
toPath CreateSmsTemplate' {Text
SMSTemplateRequest
sMSTemplateRequest :: SMSTemplateRequest
templateName :: Text
$sel:sMSTemplateRequest:CreateSmsTemplate' :: CreateSmsTemplate -> SMSTemplateRequest
$sel:templateName:CreateSmsTemplate' :: CreateSmsTemplate -> 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 CreateSmsTemplate where
  toQuery :: CreateSmsTemplate -> QueryString
toQuery = QueryString -> CreateSmsTemplate -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

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

-- |
-- Create a value of 'CreateSmsTemplateResponse' 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', 'createSmsTemplateResponse_httpStatus' - The response's http status code.
--
-- 'createTemplateMessageBody', 'createSmsTemplateResponse_createTemplateMessageBody' - Undocumented member.
newCreateSmsTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'createTemplateMessageBody'
  CreateTemplateMessageBody ->
  CreateSmsTemplateResponse
newCreateSmsTemplateResponse :: Int -> CreateTemplateMessageBody -> CreateSmsTemplateResponse
newCreateSmsTemplateResponse
  Int
pHttpStatus_
  CreateTemplateMessageBody
pCreateTemplateMessageBody_ =
    CreateSmsTemplateResponse' :: Int -> CreateTemplateMessageBody -> CreateSmsTemplateResponse
CreateSmsTemplateResponse'
      { $sel:httpStatus:CreateSmsTemplateResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:createTemplateMessageBody:CreateSmsTemplateResponse' :: CreateTemplateMessageBody
createTemplateMessageBody =
          CreateTemplateMessageBody
pCreateTemplateMessageBody_
      }

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

-- | Undocumented member.
createSmsTemplateResponse_createTemplateMessageBody :: Lens.Lens' CreateSmsTemplateResponse CreateTemplateMessageBody
createSmsTemplateResponse_createTemplateMessageBody :: (CreateTemplateMessageBody -> f CreateTemplateMessageBody)
-> CreateSmsTemplateResponse -> f CreateSmsTemplateResponse
createSmsTemplateResponse_createTemplateMessageBody = (CreateSmsTemplateResponse -> CreateTemplateMessageBody)
-> (CreateSmsTemplateResponse
    -> CreateTemplateMessageBody -> CreateSmsTemplateResponse)
-> Lens
     CreateSmsTemplateResponse
     CreateSmsTemplateResponse
     CreateTemplateMessageBody
     CreateTemplateMessageBody
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSmsTemplateResponse' {CreateTemplateMessageBody
createTemplateMessageBody :: CreateTemplateMessageBody
$sel:createTemplateMessageBody:CreateSmsTemplateResponse' :: CreateSmsTemplateResponse -> CreateTemplateMessageBody
createTemplateMessageBody} -> CreateTemplateMessageBody
createTemplateMessageBody) (\s :: CreateSmsTemplateResponse
s@CreateSmsTemplateResponse' {} CreateTemplateMessageBody
a -> CreateSmsTemplateResponse
s {$sel:createTemplateMessageBody:CreateSmsTemplateResponse' :: CreateTemplateMessageBody
createTemplateMessageBody = CreateTemplateMessageBody
a} :: CreateSmsTemplateResponse)

instance Prelude.NFData CreateSmsTemplateResponse