{-# 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-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
-- 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.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:/ '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
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]
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
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. 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'
    { $sel:version:GetInAppTemplate' :: Maybe Text
version = 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 :: Lens' GetInAppTemplate (Maybe Text)
getInAppTemplate_version = 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 :: Lens' GetInAppTemplate Text
getInAppTemplate_templateName = 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 :: (Service -> Service)
-> GetInAppTemplate -> Request GetInAppTemplate
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 GetInAppTemplate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetInAppTemplate)))
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 -> InAppTemplateResponse -> GetInAppTemplateResponse
GetInAppTemplateResponse'
            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 GetInAppTemplate where
  hashWithSalt :: Int -> GetInAppTemplate -> Int
hashWithSalt Int
_salt GetInAppTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetInAppTemplate' :: GetInAppTemplate -> Text
$sel:version:GetInAppTemplate' :: GetInAppTemplate -> 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 GetInAppTemplate where
  rnf :: GetInAppTemplate -> ()
rnf GetInAppTemplate' {Maybe Text
Text
templateName :: Text
version :: Maybe Text
$sel:templateName:GetInAppTemplate' :: GetInAppTemplate -> Text
$sel:version:GetInAppTemplate' :: GetInAppTemplate -> 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 GetInAppTemplate where
  toHeaders :: GetInAppTemplate -> 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 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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/templates/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
templateName, ByteString
"/inapp"]

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"version" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: 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
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]
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
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.
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'
      { $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 :: Lens' GetInAppTemplateResponse Int
getInAppTemplateResponse_httpStatus = 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 :: Lens' GetInAppTemplateResponse InAppTemplateResponse
getInAppTemplateResponse_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 where
  rnf :: GetInAppTemplateResponse -> ()
rnf GetInAppTemplateResponse' {Int
InAppTemplateResponse
inAppTemplateResponse :: InAppTemplateResponse
httpStatus :: Int
$sel:inAppTemplateResponse:GetInAppTemplateResponse' :: GetInAppTemplateResponse -> InAppTemplateResponse
$sel:httpStatus:GetInAppTemplateResponse' :: GetInAppTemplateResponse -> 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 InAppTemplateResponse
inAppTemplateResponse