{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:version:GetPushTemplate' :: Maybe Text
version = 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 :: Lens' GetPushTemplate (Maybe Text)
getPushTemplate_version = 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 :: Lens' GetPushTemplate Text
getPushTemplate_templateName = 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 :: (Service -> Service) -> GetPushTemplate -> Request GetPushTemplate
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetPushTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetPushTemplate)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> PushNotificationTemplateResponse -> GetPushTemplateResponse
GetPushTemplateResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)
      )

instance Prelude.Hashable GetPushTemplate where
  hashWithSalt :: Int -> GetPushTemplate -> Int
hashWithSalt Int
_salt GetPushTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetPushTemplate' :: GetPushTemplate -> Text
$sel:version:GetPushTemplate' :: GetPushTemplate -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
version
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
templateName

instance Prelude.NFData GetPushTemplate where
  rnf :: GetPushTemplate -> ()
rnf GetPushTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetPushTemplate' :: GetPushTemplate -> Text
$sel:version:GetPushTemplate' :: GetPushTemplate -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
version
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
templateName

instance Data.ToHeaders GetPushTemplate where
  toHeaders :: GetPushTemplate -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/templates/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
templateName, ByteString
"/push"]

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"version" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: 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
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]
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
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. 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'
      { $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 :: Lens' GetPushTemplateResponse Int
getPushTemplateResponse_httpStatus = 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 :: Lens' GetPushTemplateResponse PushNotificationTemplateResponse
getPushTemplateResponse_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 where
  rnf :: GetPushTemplateResponse -> ()
rnf GetPushTemplateResponse' {Int
PushNotificationTemplateResponse
pushNotificationTemplateResponse :: PushNotificationTemplateResponse
httpStatus :: Int
$sel:pushNotificationTemplateResponse:GetPushTemplateResponse' :: GetPushTemplateResponse -> PushNotificationTemplateResponse
$sel:httpStatus:GetPushTemplateResponse' :: GetPushTemplateResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PushNotificationTemplateResponse
pushNotificationTemplateResponse