{-# 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.CreatePushTemplate
-- 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 a push
-- notification channel.
module Amazonka.Pinpoint.CreatePushTemplate
  ( -- * Creating a Request
    CreatePushTemplate (..),
    newCreatePushTemplate,

    -- * Request Lenses
    createPushTemplate_templateName,
    createPushTemplate_pushNotificationTemplateRequest,

    -- * Destructuring the Response
    CreatePushTemplateResponse (..),
    newCreatePushTemplateResponse,

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

-- |
-- Create a value of 'CreatePushTemplate' 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', 'createPushTemplate_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.
--
-- 'pushNotificationTemplateRequest', 'createPushTemplate_pushNotificationTemplateRequest' - Undocumented member.
newCreatePushTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  -- | 'pushNotificationTemplateRequest'
  PushNotificationTemplateRequest ->
  CreatePushTemplate
newCreatePushTemplate :: Text -> PushNotificationTemplateRequest -> CreatePushTemplate
newCreatePushTemplate
  Text
pTemplateName_
  PushNotificationTemplateRequest
pPushNotificationTemplateRequest_ =
    CreatePushTemplate' :: Text -> PushNotificationTemplateRequest -> CreatePushTemplate
CreatePushTemplate'
      { $sel:templateName:CreatePushTemplate' :: Text
templateName = Text
pTemplateName_,
        $sel:pushNotificationTemplateRequest:CreatePushTemplate' :: PushNotificationTemplateRequest
pushNotificationTemplateRequest =
          PushNotificationTemplateRequest
pPushNotificationTemplateRequest_
      }

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

-- | Undocumented member.
createPushTemplate_pushNotificationTemplateRequest :: Lens.Lens' CreatePushTemplate PushNotificationTemplateRequest
createPushTemplate_pushNotificationTemplateRequest :: (PushNotificationTemplateRequest
 -> f PushNotificationTemplateRequest)
-> CreatePushTemplate -> f CreatePushTemplate
createPushTemplate_pushNotificationTemplateRequest = (CreatePushTemplate -> PushNotificationTemplateRequest)
-> (CreatePushTemplate
    -> PushNotificationTemplateRequest -> CreatePushTemplate)
-> Lens
     CreatePushTemplate
     CreatePushTemplate
     PushNotificationTemplateRequest
     PushNotificationTemplateRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePushTemplate' {PushNotificationTemplateRequest
pushNotificationTemplateRequest :: PushNotificationTemplateRequest
$sel:pushNotificationTemplateRequest:CreatePushTemplate' :: CreatePushTemplate -> PushNotificationTemplateRequest
pushNotificationTemplateRequest} -> PushNotificationTemplateRequest
pushNotificationTemplateRequest) (\s :: CreatePushTemplate
s@CreatePushTemplate' {} PushNotificationTemplateRequest
a -> CreatePushTemplate
s {$sel:pushNotificationTemplateRequest:CreatePushTemplate' :: PushNotificationTemplateRequest
pushNotificationTemplateRequest = PushNotificationTemplateRequest
a} :: CreatePushTemplate)

instance Core.AWSRequest CreatePushTemplate where
  type
    AWSResponse CreatePushTemplate =
      CreatePushTemplateResponse
  request :: CreatePushTemplate -> Request CreatePushTemplate
request = Service -> CreatePushTemplate -> Request CreatePushTemplate
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreatePushTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreatePushTemplate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreatePushTemplate))
-> Logger
-> Service
-> Proxy CreatePushTemplate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreatePushTemplate)))
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 -> CreatePushTemplateResponse
CreatePushTemplateResponse'
            (Int -> CreateTemplateMessageBody -> CreatePushTemplateResponse)
-> Either String Int
-> Either
     String (CreateTemplateMessageBody -> CreatePushTemplateResponse)
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 -> CreatePushTemplateResponse)
-> Either String CreateTemplateMessageBody
-> Either String CreatePushTemplateResponse
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 CreatePushTemplate

instance Prelude.NFData CreatePushTemplate

instance Core.ToHeaders CreatePushTemplate where
  toHeaders :: CreatePushTemplate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreatePushTemplate -> 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 CreatePushTemplate where
  toJSON :: CreatePushTemplate -> Value
toJSON CreatePushTemplate' {Text
PushNotificationTemplateRequest
pushNotificationTemplateRequest :: PushNotificationTemplateRequest
templateName :: Text
$sel:pushNotificationTemplateRequest:CreatePushTemplate' :: CreatePushTemplate -> PushNotificationTemplateRequest
$sel:templateName:CreatePushTemplate' :: CreatePushTemplate -> 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
"PushNotificationTemplateRequest"
                  Text -> PushNotificationTemplateRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PushNotificationTemplateRequest
pushNotificationTemplateRequest
              )
          ]
      )

instance Core.ToPath CreatePushTemplate where
  toPath :: CreatePushTemplate -> ByteString
toPath CreatePushTemplate' {Text
PushNotificationTemplateRequest
pushNotificationTemplateRequest :: PushNotificationTemplateRequest
templateName :: Text
$sel:pushNotificationTemplateRequest:CreatePushTemplate' :: CreatePushTemplate -> PushNotificationTemplateRequest
$sel:templateName:CreatePushTemplate' :: CreatePushTemplate -> 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
"/push"]

instance Core.ToQuery CreatePushTemplate where
  toQuery :: CreatePushTemplate -> QueryString
toQuery = QueryString -> CreatePushTemplate -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

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

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

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

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

instance Prelude.NFData CreatePushTemplateResponse