{-# 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.CreateInAppTemplate
-- 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 new message template for messages using the in-app message
-- channel.
module Amazonka.Pinpoint.CreateInAppTemplate
  ( -- * Creating a Request
    CreateInAppTemplate (..),
    newCreateInAppTemplate,

    -- * Request Lenses
    createInAppTemplate_templateName,
    createInAppTemplate_inAppTemplateRequest,

    -- * Destructuring the Response
    CreateInAppTemplateResponse (..),
    newCreateInAppTemplateResponse,

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

-- |
-- Create a value of 'CreateInAppTemplate' 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', 'createInAppTemplate_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.
--
-- 'inAppTemplateRequest', 'createInAppTemplate_inAppTemplateRequest' - Undocumented member.
newCreateInAppTemplate ::
  -- | 'templateName'
  Prelude.Text ->
  -- | 'inAppTemplateRequest'
  InAppTemplateRequest ->
  CreateInAppTemplate
newCreateInAppTemplate :: Text -> InAppTemplateRequest -> CreateInAppTemplate
newCreateInAppTemplate
  Text
pTemplateName_
  InAppTemplateRequest
pInAppTemplateRequest_ =
    CreateInAppTemplate' :: Text -> InAppTemplateRequest -> CreateInAppTemplate
CreateInAppTemplate'
      { $sel:templateName:CreateInAppTemplate' :: Text
templateName = Text
pTemplateName_,
        $sel:inAppTemplateRequest:CreateInAppTemplate' :: InAppTemplateRequest
inAppTemplateRequest = InAppTemplateRequest
pInAppTemplateRequest_
      }

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

-- | Undocumented member.
createInAppTemplate_inAppTemplateRequest :: Lens.Lens' CreateInAppTemplate InAppTemplateRequest
createInAppTemplate_inAppTemplateRequest :: (InAppTemplateRequest -> f InAppTemplateRequest)
-> CreateInAppTemplate -> f CreateInAppTemplate
createInAppTemplate_inAppTemplateRequest = (CreateInAppTemplate -> InAppTemplateRequest)
-> (CreateInAppTemplate
    -> InAppTemplateRequest -> CreateInAppTemplate)
-> Lens
     CreateInAppTemplate
     CreateInAppTemplate
     InAppTemplateRequest
     InAppTemplateRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInAppTemplate' {InAppTemplateRequest
inAppTemplateRequest :: InAppTemplateRequest
$sel:inAppTemplateRequest:CreateInAppTemplate' :: CreateInAppTemplate -> InAppTemplateRequest
inAppTemplateRequest} -> InAppTemplateRequest
inAppTemplateRequest) (\s :: CreateInAppTemplate
s@CreateInAppTemplate' {} InAppTemplateRequest
a -> CreateInAppTemplate
s {$sel:inAppTemplateRequest:CreateInAppTemplate' :: InAppTemplateRequest
inAppTemplateRequest = InAppTemplateRequest
a} :: CreateInAppTemplate)

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

instance Prelude.Hashable CreateInAppTemplate

instance Prelude.NFData CreateInAppTemplate

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

instance Core.ToPath CreateInAppTemplate where
  toPath :: CreateInAppTemplate -> ByteString
toPath CreateInAppTemplate' {Text
InAppTemplateRequest
inAppTemplateRequest :: InAppTemplateRequest
templateName :: Text
$sel:inAppTemplateRequest:CreateInAppTemplate' :: CreateInAppTemplate -> InAppTemplateRequest
$sel:templateName:CreateInAppTemplate' :: CreateInAppTemplate -> 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
"/inapp"]

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

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

-- |
-- Create a value of 'CreateInAppTemplateResponse' 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', 'createInAppTemplateResponse_httpStatus' - The response's http status code.
--
-- 'templateCreateMessageBody', 'createInAppTemplateResponse_templateCreateMessageBody' - Undocumented member.
newCreateInAppTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'templateCreateMessageBody'
  TemplateCreateMessageBody ->
  CreateInAppTemplateResponse
newCreateInAppTemplateResponse :: Int -> TemplateCreateMessageBody -> CreateInAppTemplateResponse
newCreateInAppTemplateResponse
  Int
pHttpStatus_
  TemplateCreateMessageBody
pTemplateCreateMessageBody_ =
    CreateInAppTemplateResponse' :: Int -> TemplateCreateMessageBody -> CreateInAppTemplateResponse
CreateInAppTemplateResponse'
      { $sel:httpStatus:CreateInAppTemplateResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:templateCreateMessageBody:CreateInAppTemplateResponse' :: TemplateCreateMessageBody
templateCreateMessageBody =
          TemplateCreateMessageBody
pTemplateCreateMessageBody_
      }

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

-- | Undocumented member.
createInAppTemplateResponse_templateCreateMessageBody :: Lens.Lens' CreateInAppTemplateResponse TemplateCreateMessageBody
createInAppTemplateResponse_templateCreateMessageBody :: (TemplateCreateMessageBody -> f TemplateCreateMessageBody)
-> CreateInAppTemplateResponse -> f CreateInAppTemplateResponse
createInAppTemplateResponse_templateCreateMessageBody = (CreateInAppTemplateResponse -> TemplateCreateMessageBody)
-> (CreateInAppTemplateResponse
    -> TemplateCreateMessageBody -> CreateInAppTemplateResponse)
-> Lens
     CreateInAppTemplateResponse
     CreateInAppTemplateResponse
     TemplateCreateMessageBody
     TemplateCreateMessageBody
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInAppTemplateResponse' {TemplateCreateMessageBody
templateCreateMessageBody :: TemplateCreateMessageBody
$sel:templateCreateMessageBody:CreateInAppTemplateResponse' :: CreateInAppTemplateResponse -> TemplateCreateMessageBody
templateCreateMessageBody} -> TemplateCreateMessageBody
templateCreateMessageBody) (\s :: CreateInAppTemplateResponse
s@CreateInAppTemplateResponse' {} TemplateCreateMessageBody
a -> CreateInAppTemplateResponse
s {$sel:templateCreateMessageBody:CreateInAppTemplateResponse' :: TemplateCreateMessageBody
templateCreateMessageBody = TemplateCreateMessageBody
a} :: CreateInAppTemplateResponse)

instance Prelude.NFData CreateInAppTemplateResponse