{-# 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.GetPushTemplate
-- 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
-- that are sent through a push notification channel.
module Amazonka.Pinpoint.GetPushTemplate
  ( -- * Creating a Request
    GetPushTemplate (..),
    newGetPushTemplate,

    -- * Request Lenses
    getPushTemplate_version,
    getPushTemplate_templateName,

    -- * Destructuring the Response
    GetPushTemplateResponse (..),
    newGetPushTemplateResponse,

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

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

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

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

instance Prelude.Hashable GetPushTemplate

instance Prelude.NFData GetPushTemplate

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

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

-- |
-- Create a value of 'GetPushTemplateResponse' 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', 'getPushTemplateResponse_httpStatus' - The response's http status code.
--
-- 'pushNotificationTemplateResponse', 'getPushTemplateResponse_pushNotificationTemplateResponse' - Undocumented member.
newGetPushTemplateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'pushNotificationTemplateResponse'
  PushNotificationTemplateResponse ->
  GetPushTemplateResponse
newGetPushTemplateResponse :: Int -> PushNotificationTemplateResponse -> GetPushTemplateResponse
newGetPushTemplateResponse
  Int
pHttpStatus_
  PushNotificationTemplateResponse
pPushNotificationTemplateResponse_ =
    GetPushTemplateResponse' :: Int -> PushNotificationTemplateResponse -> GetPushTemplateResponse
GetPushTemplateResponse'
      { $sel:httpStatus:GetPushTemplateResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:pushNotificationTemplateResponse:GetPushTemplateResponse' :: PushNotificationTemplateResponse
pushNotificationTemplateResponse =
          PushNotificationTemplateResponse
pPushNotificationTemplateResponse_
      }

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

-- | Undocumented member.
getPushTemplateResponse_pushNotificationTemplateResponse :: Lens.Lens' GetPushTemplateResponse PushNotificationTemplateResponse
getPushTemplateResponse_pushNotificationTemplateResponse :: (PushNotificationTemplateResponse
 -> f PushNotificationTemplateResponse)
-> GetPushTemplateResponse -> f GetPushTemplateResponse
getPushTemplateResponse_pushNotificationTemplateResponse = (GetPushTemplateResponse -> PushNotificationTemplateResponse)
-> (GetPushTemplateResponse
    -> PushNotificationTemplateResponse -> GetPushTemplateResponse)
-> Lens
     GetPushTemplateResponse
     GetPushTemplateResponse
     PushNotificationTemplateResponse
     PushNotificationTemplateResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPushTemplateResponse' {PushNotificationTemplateResponse
pushNotificationTemplateResponse :: PushNotificationTemplateResponse
$sel:pushNotificationTemplateResponse:GetPushTemplateResponse' :: GetPushTemplateResponse -> PushNotificationTemplateResponse
pushNotificationTemplateResponse} -> PushNotificationTemplateResponse
pushNotificationTemplateResponse) (\s :: GetPushTemplateResponse
s@GetPushTemplateResponse' {} PushNotificationTemplateResponse
a -> GetPushTemplateResponse
s {$sel:pushNotificationTemplateResponse:GetPushTemplateResponse' :: PushNotificationTemplateResponse
pushNotificationTemplateResponse = PushNotificationTemplateResponse
a} :: GetPushTemplateResponse)

instance Prelude.NFData GetPushTemplateResponse