{-# 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.CampaignInAppMessage
-- 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)
module Amazonka.Pinpoint.Types.CampaignInAppMessage where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.InAppMessageContent
import Amazonka.Pinpoint.Types.Layout
import qualified Amazonka.Prelude as Prelude

-- | In-app message configuration.
--
-- /See:/ 'newCampaignInAppMessage' smart constructor.
data CampaignInAppMessage = CampaignInAppMessage'
  { -- | In-app message layout.
    CampaignInAppMessage -> Maybe Layout
layout :: Prelude.Maybe Layout,
    -- | The message body of the notification, the email body or the text
    -- message.
    CampaignInAppMessage -> Maybe Text
body :: Prelude.Maybe Prelude.Text,
    -- | In-app message content.
    CampaignInAppMessage -> Maybe [InAppMessageContent]
content :: Prelude.Maybe [InAppMessageContent],
    -- | Custom config to be sent to client.
    CampaignInAppMessage -> Maybe (HashMap Text Text)
customConfig :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (CampaignInAppMessage -> CampaignInAppMessage -> Bool
(CampaignInAppMessage -> CampaignInAppMessage -> Bool)
-> (CampaignInAppMessage -> CampaignInAppMessage -> Bool)
-> Eq CampaignInAppMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CampaignInAppMessage -> CampaignInAppMessage -> Bool
$c/= :: CampaignInAppMessage -> CampaignInAppMessage -> Bool
== :: CampaignInAppMessage -> CampaignInAppMessage -> Bool
$c== :: CampaignInAppMessage -> CampaignInAppMessage -> Bool
Prelude.Eq, ReadPrec [CampaignInAppMessage]
ReadPrec CampaignInAppMessage
Int -> ReadS CampaignInAppMessage
ReadS [CampaignInAppMessage]
(Int -> ReadS CampaignInAppMessage)
-> ReadS [CampaignInAppMessage]
-> ReadPrec CampaignInAppMessage
-> ReadPrec [CampaignInAppMessage]
-> Read CampaignInAppMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CampaignInAppMessage]
$creadListPrec :: ReadPrec [CampaignInAppMessage]
readPrec :: ReadPrec CampaignInAppMessage
$creadPrec :: ReadPrec CampaignInAppMessage
readList :: ReadS [CampaignInAppMessage]
$creadList :: ReadS [CampaignInAppMessage]
readsPrec :: Int -> ReadS CampaignInAppMessage
$creadsPrec :: Int -> ReadS CampaignInAppMessage
Prelude.Read, Int -> CampaignInAppMessage -> ShowS
[CampaignInAppMessage] -> ShowS
CampaignInAppMessage -> String
(Int -> CampaignInAppMessage -> ShowS)
-> (CampaignInAppMessage -> String)
-> ([CampaignInAppMessage] -> ShowS)
-> Show CampaignInAppMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CampaignInAppMessage] -> ShowS
$cshowList :: [CampaignInAppMessage] -> ShowS
show :: CampaignInAppMessage -> String
$cshow :: CampaignInAppMessage -> String
showsPrec :: Int -> CampaignInAppMessage -> ShowS
$cshowsPrec :: Int -> CampaignInAppMessage -> ShowS
Prelude.Show, (forall x. CampaignInAppMessage -> Rep CampaignInAppMessage x)
-> (forall x. Rep CampaignInAppMessage x -> CampaignInAppMessage)
-> Generic CampaignInAppMessage
forall x. Rep CampaignInAppMessage x -> CampaignInAppMessage
forall x. CampaignInAppMessage -> Rep CampaignInAppMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CampaignInAppMessage x -> CampaignInAppMessage
$cfrom :: forall x. CampaignInAppMessage -> Rep CampaignInAppMessage x
Prelude.Generic)

-- |
-- Create a value of 'CampaignInAppMessage' 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:
--
-- 'layout', 'campaignInAppMessage_layout' - In-app message layout.
--
-- 'body', 'campaignInAppMessage_body' - The message body of the notification, the email body or the text
-- message.
--
-- 'content', 'campaignInAppMessage_content' - In-app message content.
--
-- 'customConfig', 'campaignInAppMessage_customConfig' - Custom config to be sent to client.
newCampaignInAppMessage ::
  CampaignInAppMessage
newCampaignInAppMessage :: CampaignInAppMessage
newCampaignInAppMessage =
  CampaignInAppMessage' :: Maybe Layout
-> Maybe Text
-> Maybe [InAppMessageContent]
-> Maybe (HashMap Text Text)
-> CampaignInAppMessage
CampaignInAppMessage'
    { $sel:layout:CampaignInAppMessage' :: Maybe Layout
layout = Maybe Layout
forall a. Maybe a
Prelude.Nothing,
      $sel:body:CampaignInAppMessage' :: Maybe Text
body = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:content:CampaignInAppMessage' :: Maybe [InAppMessageContent]
content = Maybe [InAppMessageContent]
forall a. Maybe a
Prelude.Nothing,
      $sel:customConfig:CampaignInAppMessage' :: Maybe (HashMap Text Text)
customConfig = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | In-app message layout.
campaignInAppMessage_layout :: Lens.Lens' CampaignInAppMessage (Prelude.Maybe Layout)
campaignInAppMessage_layout :: (Maybe Layout -> f (Maybe Layout))
-> CampaignInAppMessage -> f CampaignInAppMessage
campaignInAppMessage_layout = (CampaignInAppMessage -> Maybe Layout)
-> (CampaignInAppMessage -> Maybe Layout -> CampaignInAppMessage)
-> Lens
     CampaignInAppMessage
     CampaignInAppMessage
     (Maybe Layout)
     (Maybe Layout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignInAppMessage' {Maybe Layout
layout :: Maybe Layout
$sel:layout:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe Layout
layout} -> Maybe Layout
layout) (\s :: CampaignInAppMessage
s@CampaignInAppMessage' {} Maybe Layout
a -> CampaignInAppMessage
s {$sel:layout:CampaignInAppMessage' :: Maybe Layout
layout = Maybe Layout
a} :: CampaignInAppMessage)

-- | The message body of the notification, the email body or the text
-- message.
campaignInAppMessage_body :: Lens.Lens' CampaignInAppMessage (Prelude.Maybe Prelude.Text)
campaignInAppMessage_body :: (Maybe Text -> f (Maybe Text))
-> CampaignInAppMessage -> f CampaignInAppMessage
campaignInAppMessage_body = (CampaignInAppMessage -> Maybe Text)
-> (CampaignInAppMessage -> Maybe Text -> CampaignInAppMessage)
-> Lens
     CampaignInAppMessage CampaignInAppMessage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignInAppMessage' {Maybe Text
body :: Maybe Text
$sel:body:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe Text
body} -> Maybe Text
body) (\s :: CampaignInAppMessage
s@CampaignInAppMessage' {} Maybe Text
a -> CampaignInAppMessage
s {$sel:body:CampaignInAppMessage' :: Maybe Text
body = Maybe Text
a} :: CampaignInAppMessage)

-- | In-app message content.
campaignInAppMessage_content :: Lens.Lens' CampaignInAppMessage (Prelude.Maybe [InAppMessageContent])
campaignInAppMessage_content :: (Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
-> CampaignInAppMessage -> f CampaignInAppMessage
campaignInAppMessage_content = (CampaignInAppMessage -> Maybe [InAppMessageContent])
-> (CampaignInAppMessage
    -> Maybe [InAppMessageContent] -> CampaignInAppMessage)
-> Lens
     CampaignInAppMessage
     CampaignInAppMessage
     (Maybe [InAppMessageContent])
     (Maybe [InAppMessageContent])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignInAppMessage' {Maybe [InAppMessageContent]
content :: Maybe [InAppMessageContent]
$sel:content:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe [InAppMessageContent]
content} -> Maybe [InAppMessageContent]
content) (\s :: CampaignInAppMessage
s@CampaignInAppMessage' {} Maybe [InAppMessageContent]
a -> CampaignInAppMessage
s {$sel:content:CampaignInAppMessage' :: Maybe [InAppMessageContent]
content = Maybe [InAppMessageContent]
a} :: CampaignInAppMessage) ((Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
 -> CampaignInAppMessage -> f CampaignInAppMessage)
-> ((Maybe [InAppMessageContent]
     -> f (Maybe [InAppMessageContent]))
    -> Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
-> (Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
-> CampaignInAppMessage
-> f CampaignInAppMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [InAppMessageContent]
  [InAppMessageContent]
  [InAppMessageContent]
  [InAppMessageContent]
-> Iso
     (Maybe [InAppMessageContent])
     (Maybe [InAppMessageContent])
     (Maybe [InAppMessageContent])
     (Maybe [InAppMessageContent])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [InAppMessageContent]
  [InAppMessageContent]
  [InAppMessageContent]
  [InAppMessageContent]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Custom config to be sent to client.
campaignInAppMessage_customConfig :: Lens.Lens' CampaignInAppMessage (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
campaignInAppMessage_customConfig :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CampaignInAppMessage -> f CampaignInAppMessage
campaignInAppMessage_customConfig = (CampaignInAppMessage -> Maybe (HashMap Text Text))
-> (CampaignInAppMessage
    -> Maybe (HashMap Text Text) -> CampaignInAppMessage)
-> Lens
     CampaignInAppMessage
     CampaignInAppMessage
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CampaignInAppMessage' {Maybe (HashMap Text Text)
customConfig :: Maybe (HashMap Text Text)
$sel:customConfig:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe (HashMap Text Text)
customConfig} -> Maybe (HashMap Text Text)
customConfig) (\s :: CampaignInAppMessage
s@CampaignInAppMessage' {} Maybe (HashMap Text Text)
a -> CampaignInAppMessage
s {$sel:customConfig:CampaignInAppMessage' :: Maybe (HashMap Text Text)
customConfig = Maybe (HashMap Text Text)
a} :: CampaignInAppMessage) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CampaignInAppMessage -> f CampaignInAppMessage)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CampaignInAppMessage
-> f CampaignInAppMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON CampaignInAppMessage where
  parseJSON :: Value -> Parser CampaignInAppMessage
parseJSON =
    String
-> (Object -> Parser CampaignInAppMessage)
-> Value
-> Parser CampaignInAppMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CampaignInAppMessage"
      ( \Object
x ->
          Maybe Layout
-> Maybe Text
-> Maybe [InAppMessageContent]
-> Maybe (HashMap Text Text)
-> CampaignInAppMessage
CampaignInAppMessage'
            (Maybe Layout
 -> Maybe Text
 -> Maybe [InAppMessageContent]
 -> Maybe (HashMap Text Text)
 -> CampaignInAppMessage)
-> Parser (Maybe Layout)
-> Parser
     (Maybe Text
      -> Maybe [InAppMessageContent]
      -> Maybe (HashMap Text Text)
      -> CampaignInAppMessage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Layout)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Layout")
            Parser
  (Maybe Text
   -> Maybe [InAppMessageContent]
   -> Maybe (HashMap Text Text)
   -> CampaignInAppMessage)
-> Parser (Maybe Text)
-> Parser
     (Maybe [InAppMessageContent]
      -> Maybe (HashMap Text Text) -> CampaignInAppMessage)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Body")
            Parser
  (Maybe [InAppMessageContent]
   -> Maybe (HashMap Text Text) -> CampaignInAppMessage)
-> Parser (Maybe [InAppMessageContent])
-> Parser (Maybe (HashMap Text Text) -> CampaignInAppMessage)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [InAppMessageContent]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Content" Parser (Maybe (Maybe [InAppMessageContent]))
-> Maybe [InAppMessageContent]
-> Parser (Maybe [InAppMessageContent])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [InAppMessageContent]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe (HashMap Text Text) -> CampaignInAppMessage)
-> Parser (Maybe (HashMap Text Text))
-> Parser CampaignInAppMessage
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CustomConfig" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable CampaignInAppMessage

instance Prelude.NFData CampaignInAppMessage

instance Core.ToJSON CampaignInAppMessage where
  toJSON :: CampaignInAppMessage -> Value
toJSON CampaignInAppMessage' {Maybe [InAppMessageContent]
Maybe Text
Maybe (HashMap Text Text)
Maybe Layout
customConfig :: Maybe (HashMap Text Text)
content :: Maybe [InAppMessageContent]
body :: Maybe Text
layout :: Maybe Layout
$sel:customConfig:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe (HashMap Text Text)
$sel:content:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe [InAppMessageContent]
$sel:body:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe Text
$sel:layout:CampaignInAppMessage' :: CampaignInAppMessage -> Maybe Layout
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Layout" Text -> Layout -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Layout -> Pair) -> Maybe Layout -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Layout
layout,
            (Text
"Body" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
body,
            (Text
"Content" Text -> [InAppMessageContent] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([InAppMessageContent] -> Pair)
-> Maybe [InAppMessageContent] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [InAppMessageContent]
content,
            (Text
"CustomConfig" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
customConfig
          ]
      )