{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.Template
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Pinpoint.Types.Template where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Specifies the name and version of the message template to use for the
-- message.
--
-- /See:/ 'newTemplate' smart constructor.
data Template = Template'
  { -- | The name of the message template to use for the message. If specified,
    -- this value must match the name of an existing message template.
    Template -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier for the version of the message template to use for
    -- the message. If specified, this value must match the identifier for an
    -- existing template version. To retrieve a list of versions and version
    -- identifiers for a template, use the Template Versions resource.
    --
    -- If you don\'t specify a value for this property, Amazon Pinpoint uses
    -- the /active version/ of the template. The /active version/ is typically
    -- the version of a template that\'s been most recently reviewed and
    -- approved for use, depending on your workflow. It isn\'t necessarily the
    -- latest version of a template.
    Template -> Maybe Text
version :: Prelude.Maybe Prelude.Text
  }
  deriving (Template -> Template -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Template -> Template -> Bool
$c/= :: Template -> Template -> Bool
== :: Template -> Template -> Bool
$c== :: Template -> Template -> Bool
Prelude.Eq, ReadPrec [Template]
ReadPrec Template
Int -> ReadS Template
ReadS [Template]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Template]
$creadListPrec :: ReadPrec [Template]
readPrec :: ReadPrec Template
$creadPrec :: ReadPrec Template
readList :: ReadS [Template]
$creadList :: ReadS [Template]
readsPrec :: Int -> ReadS Template
$creadsPrec :: Int -> ReadS Template
Prelude.Read, Int -> Template -> ShowS
[Template] -> ShowS
Template -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Template] -> ShowS
$cshowList :: [Template] -> ShowS
show :: Template -> String
$cshow :: Template -> String
showsPrec :: Int -> Template -> ShowS
$cshowsPrec :: Int -> Template -> ShowS
Prelude.Show, forall x. Rep Template x -> Template
forall x. Template -> Rep Template x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Template x -> Template
$cfrom :: forall x. Template -> Rep Template x
Prelude.Generic)

-- |
-- Create a value of 'Template' 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:
--
-- 'name', 'template_name' - The name of the message template to use for the message. If specified,
-- this value must match the name of an existing message template.
--
-- 'version', 'template_version' - The unique identifier for the version of the message template to use for
-- the message. If specified, this value must match the identifier for an
-- existing template version. To retrieve a list of versions and version
-- identifiers for a template, use the Template Versions resource.
--
-- If you don\'t specify a value for this property, Amazon Pinpoint uses
-- the /active version/ of the template. The /active version/ is typically
-- the version of a template that\'s been most recently reviewed and
-- approved for use, depending on your workflow. It isn\'t necessarily the
-- latest version of a template.
newTemplate ::
  Template
newTemplate :: Template
newTemplate =
  Template'
    { $sel:name:Template' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:version:Template' :: Maybe Text
version = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the message template to use for the message. If specified,
-- this value must match the name of an existing message template.
template_name :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_name :: Lens' Template (Maybe Text)
template_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Template' {Maybe Text
name :: Maybe Text
$sel:name:Template' :: Template -> Maybe Text
name} -> Maybe Text
name) (\s :: Template
s@Template' {} Maybe Text
a -> Template
s {$sel:name:Template' :: Maybe Text
name = Maybe Text
a} :: Template)

-- | The unique identifier for the version of the message template to use for
-- the message. If specified, this value must match the identifier for an
-- existing template version. To retrieve a list of versions and version
-- identifiers for a template, use the Template Versions resource.
--
-- If you don\'t specify a value for this property, Amazon Pinpoint uses
-- the /active version/ of the template. The /active version/ is typically
-- the version of a template that\'s been most recently reviewed and
-- approved for use, depending on your workflow. It isn\'t necessarily the
-- latest version of a template.
template_version :: Lens.Lens' Template (Prelude.Maybe Prelude.Text)
template_version :: Lens' Template (Maybe Text)
template_version = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Template' {Maybe Text
version :: Maybe Text
$sel:version:Template' :: Template -> Maybe Text
version} -> Maybe Text
version) (\s :: Template
s@Template' {} Maybe Text
a -> Template
s {$sel:version:Template' :: Maybe Text
version = Maybe Text
a} :: Template)

instance Data.FromJSON Template where
  parseJSON :: Value -> Parser Template
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Template"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Template
Template'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Version")
      )

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

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

instance Data.ToJSON Template where
  toJSON :: Template -> Value
toJSON Template' {Maybe Text
version :: Maybe Text
name :: Maybe Text
$sel:version:Template' :: Template -> Maybe Text
$sel:name:Template' :: Template -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Key
"Version" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
version
          ]
      )