{-# 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.InAppMessage
-- 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.InAppMessage 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

-- | Provides all fields required for building an in-app message.
--
-- /See:/ 'newInAppMessage' smart constructor.
data InAppMessage = InAppMessage'
  { -- | The layout of the message.
    InAppMessage -> Maybe Layout
layout :: Prelude.Maybe Layout,
    -- | In-app message content.
    InAppMessage -> Maybe [InAppMessageContent]
content :: Prelude.Maybe [InAppMessageContent],
    -- | Custom config to be sent to SDK.
    InAppMessage -> Maybe (HashMap Text Text)
customConfig :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (InAppMessage -> InAppMessage -> Bool
(InAppMessage -> InAppMessage -> Bool)
-> (InAppMessage -> InAppMessage -> Bool) -> Eq InAppMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InAppMessage -> InAppMessage -> Bool
$c/= :: InAppMessage -> InAppMessage -> Bool
== :: InAppMessage -> InAppMessage -> Bool
$c== :: InAppMessage -> InAppMessage -> Bool
Prelude.Eq, ReadPrec [InAppMessage]
ReadPrec InAppMessage
Int -> ReadS InAppMessage
ReadS [InAppMessage]
(Int -> ReadS InAppMessage)
-> ReadS [InAppMessage]
-> ReadPrec InAppMessage
-> ReadPrec [InAppMessage]
-> Read InAppMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InAppMessage]
$creadListPrec :: ReadPrec [InAppMessage]
readPrec :: ReadPrec InAppMessage
$creadPrec :: ReadPrec InAppMessage
readList :: ReadS [InAppMessage]
$creadList :: ReadS [InAppMessage]
readsPrec :: Int -> ReadS InAppMessage
$creadsPrec :: Int -> ReadS InAppMessage
Prelude.Read, Int -> InAppMessage -> ShowS
[InAppMessage] -> ShowS
InAppMessage -> String
(Int -> InAppMessage -> ShowS)
-> (InAppMessage -> String)
-> ([InAppMessage] -> ShowS)
-> Show InAppMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InAppMessage] -> ShowS
$cshowList :: [InAppMessage] -> ShowS
show :: InAppMessage -> String
$cshow :: InAppMessage -> String
showsPrec :: Int -> InAppMessage -> ShowS
$cshowsPrec :: Int -> InAppMessage -> ShowS
Prelude.Show, (forall x. InAppMessage -> Rep InAppMessage x)
-> (forall x. Rep InAppMessage x -> InAppMessage)
-> Generic InAppMessage
forall x. Rep InAppMessage x -> InAppMessage
forall x. InAppMessage -> Rep InAppMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InAppMessage x -> InAppMessage
$cfrom :: forall x. InAppMessage -> Rep InAppMessage x
Prelude.Generic)

-- |
-- Create a value of 'InAppMessage' 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', 'inAppMessage_layout' - The layout of the message.
--
-- 'content', 'inAppMessage_content' - In-app message content.
--
-- 'customConfig', 'inAppMessage_customConfig' - Custom config to be sent to SDK.
newInAppMessage ::
  InAppMessage
newInAppMessage :: InAppMessage
newInAppMessage =
  InAppMessage' :: Maybe Layout
-> Maybe [InAppMessageContent]
-> Maybe (HashMap Text Text)
-> InAppMessage
InAppMessage'
    { $sel:layout:InAppMessage' :: Maybe Layout
layout = Maybe Layout
forall a. Maybe a
Prelude.Nothing,
      $sel:content:InAppMessage' :: Maybe [InAppMessageContent]
content = Maybe [InAppMessageContent]
forall a. Maybe a
Prelude.Nothing,
      $sel:customConfig:InAppMessage' :: Maybe (HashMap Text Text)
customConfig = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | The layout of the message.
inAppMessage_layout :: Lens.Lens' InAppMessage (Prelude.Maybe Layout)
inAppMessage_layout :: (Maybe Layout -> f (Maybe Layout))
-> InAppMessage -> f InAppMessage
inAppMessage_layout = (InAppMessage -> Maybe Layout)
-> (InAppMessage -> Maybe Layout -> InAppMessage)
-> Lens InAppMessage InAppMessage (Maybe Layout) (Maybe Layout)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InAppMessage' {Maybe Layout
layout :: Maybe Layout
$sel:layout:InAppMessage' :: InAppMessage -> Maybe Layout
layout} -> Maybe Layout
layout) (\s :: InAppMessage
s@InAppMessage' {} Maybe Layout
a -> InAppMessage
s {$sel:layout:InAppMessage' :: Maybe Layout
layout = Maybe Layout
a} :: InAppMessage)

-- | In-app message content.
inAppMessage_content :: Lens.Lens' InAppMessage (Prelude.Maybe [InAppMessageContent])
inAppMessage_content :: (Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
-> InAppMessage -> f InAppMessage
inAppMessage_content = (InAppMessage -> Maybe [InAppMessageContent])
-> (InAppMessage -> Maybe [InAppMessageContent] -> InAppMessage)
-> Lens
     InAppMessage
     InAppMessage
     (Maybe [InAppMessageContent])
     (Maybe [InAppMessageContent])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InAppMessage' {Maybe [InAppMessageContent]
content :: Maybe [InAppMessageContent]
$sel:content:InAppMessage' :: InAppMessage -> Maybe [InAppMessageContent]
content} -> Maybe [InAppMessageContent]
content) (\s :: InAppMessage
s@InAppMessage' {} Maybe [InAppMessageContent]
a -> InAppMessage
s {$sel:content:InAppMessage' :: Maybe [InAppMessageContent]
content = Maybe [InAppMessageContent]
a} :: InAppMessage) ((Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
 -> InAppMessage -> f InAppMessage)
-> ((Maybe [InAppMessageContent]
     -> f (Maybe [InAppMessageContent]))
    -> Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
-> (Maybe [InAppMessageContent] -> f (Maybe [InAppMessageContent]))
-> InAppMessage
-> f InAppMessage
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 SDK.
inAppMessage_customConfig :: Lens.Lens' InAppMessage (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
inAppMessage_customConfig :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> InAppMessage -> f InAppMessage
inAppMessage_customConfig = (InAppMessage -> Maybe (HashMap Text Text))
-> (InAppMessage -> Maybe (HashMap Text Text) -> InAppMessage)
-> Lens
     InAppMessage
     InAppMessage
     (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 (\InAppMessage' {Maybe (HashMap Text Text)
customConfig :: Maybe (HashMap Text Text)
$sel:customConfig:InAppMessage' :: InAppMessage -> Maybe (HashMap Text Text)
customConfig} -> Maybe (HashMap Text Text)
customConfig) (\s :: InAppMessage
s@InAppMessage' {} Maybe (HashMap Text Text)
a -> InAppMessage
s {$sel:customConfig:InAppMessage' :: Maybe (HashMap Text Text)
customConfig = Maybe (HashMap Text Text)
a} :: InAppMessage) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> InAppMessage -> f InAppMessage)
-> ((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)))
-> InAppMessage
-> f InAppMessage
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 InAppMessage where
  parseJSON :: Value -> Parser InAppMessage
parseJSON =
    String
-> (Object -> Parser InAppMessage) -> Value -> Parser InAppMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InAppMessage"
      ( \Object
x ->
          Maybe Layout
-> Maybe [InAppMessageContent]
-> Maybe (HashMap Text Text)
-> InAppMessage
InAppMessage'
            (Maybe Layout
 -> Maybe [InAppMessageContent]
 -> Maybe (HashMap Text Text)
 -> InAppMessage)
-> Parser (Maybe Layout)
-> Parser
     (Maybe [InAppMessageContent]
      -> Maybe (HashMap Text Text) -> InAppMessage)
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 [InAppMessageContent]
   -> Maybe (HashMap Text Text) -> InAppMessage)
-> Parser (Maybe [InAppMessageContent])
-> Parser (Maybe (HashMap Text Text) -> InAppMessage)
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) -> InAppMessage)
-> Parser (Maybe (HashMap Text Text)) -> Parser InAppMessage
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 InAppMessage

instance Prelude.NFData InAppMessage