{-# 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.GetInAppTemplate
-- 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
-- sent through the in-app channel.
module Amazonka.Pinpoint.GetInAppTemplate
  ( -- * Creating a Request
    GetInAppTemplate (..),
    newGetInAppTemplate,

    -- * Request Lenses
    getInAppTemplate_version,
    getInAppTemplate_templateName,

    -- * Destructuring the Response
    GetInAppTemplateResponse (..),
    newGetInAppTemplateResponse,

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

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

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

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

instance Prelude.Hashable GetInAppTemplate

instance Prelude.NFData GetInAppTemplate

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

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

-- |
-- Create a value of 'GetInAppTemplateResponse' 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', 'getInAppTemplateResponse_httpStatus' - The response's http status code.
--
-- 'inAppTemplateResponse', 'getInAppTemplateResponse_inAppTemplateResponse' - Undocumented member.
newGetInAppTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'inAppTemplateResponse'
  InAppTemplateResponse ->
  GetInAppTemplateResponse
newGetInAppTemplateResponse :: Int -> InAppTemplateResponse -> GetInAppTemplateResponse
newGetInAppTemplateResponse
  Int
pHttpStatus_
  InAppTemplateResponse
pInAppTemplateResponse_ =
    GetInAppTemplateResponse' :: Int -> InAppTemplateResponse -> GetInAppTemplateResponse
GetInAppTemplateResponse'
      { $sel:httpStatus:GetInAppTemplateResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:inAppTemplateResponse:GetInAppTemplateResponse' :: InAppTemplateResponse
inAppTemplateResponse = InAppTemplateResponse
pInAppTemplateResponse_
      }

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

-- | Undocumented member.
getInAppTemplateResponse_inAppTemplateResponse :: Lens.Lens' GetInAppTemplateResponse InAppTemplateResponse
getInAppTemplateResponse_inAppTemplateResponse :: (InAppTemplateResponse -> f InAppTemplateResponse)
-> GetInAppTemplateResponse -> f GetInAppTemplateResponse
getInAppTemplateResponse_inAppTemplateResponse = (GetInAppTemplateResponse -> InAppTemplateResponse)
-> (GetInAppTemplateResponse
    -> InAppTemplateResponse -> GetInAppTemplateResponse)
-> Lens
     GetInAppTemplateResponse
     GetInAppTemplateResponse
     InAppTemplateResponse
     InAppTemplateResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInAppTemplateResponse' {InAppTemplateResponse
inAppTemplateResponse :: InAppTemplateResponse
$sel:inAppTemplateResponse:GetInAppTemplateResponse' :: GetInAppTemplateResponse -> InAppTemplateResponse
inAppTemplateResponse} -> InAppTemplateResponse
inAppTemplateResponse) (\s :: GetInAppTemplateResponse
s@GetInAppTemplateResponse' {} InAppTemplateResponse
a -> GetInAppTemplateResponse
s {$sel:inAppTemplateResponse:GetInAppTemplateResponse' :: InAppTemplateResponse
inAppTemplateResponse = InAppTemplateResponse
a} :: GetInAppTemplateResponse)

instance Prelude.NFData GetInAppTemplateResponse