{-# 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.ChimeSDKMessaging.Types.PushNotificationPreferences
-- 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.ChimeSDKMessaging.Types.PushNotificationPreferences where

import Amazonka.ChimeSDKMessaging.Types.AllowNotifications
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

-- | The channel membership preferences for push notification.
--
-- /See:/ 'newPushNotificationPreferences' smart constructor.
data PushNotificationPreferences = PushNotificationPreferences'
  { -- | The simple JSON object used to send a subset of a push notification to
    -- the requested member.
    PushNotificationPreferences -> Maybe (Sensitive Text)
filterRule :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | Enum value that indicates which push notifications to send to the
    -- requested member of a channel. @ALL@ sends all push notifications,
    -- @NONE@ sends no push notifications, @FILTERED@ sends only filtered push
    -- notifications.
    PushNotificationPreferences -> AllowNotifications
allowNotifications :: AllowNotifications
  }
  deriving (PushNotificationPreferences -> PushNotificationPreferences -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PushNotificationPreferences -> PushNotificationPreferences -> Bool
$c/= :: PushNotificationPreferences -> PushNotificationPreferences -> Bool
== :: PushNotificationPreferences -> PushNotificationPreferences -> Bool
$c== :: PushNotificationPreferences -> PushNotificationPreferences -> Bool
Prelude.Eq, Int -> PushNotificationPreferences -> ShowS
[PushNotificationPreferences] -> ShowS
PushNotificationPreferences -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PushNotificationPreferences] -> ShowS
$cshowList :: [PushNotificationPreferences] -> ShowS
show :: PushNotificationPreferences -> String
$cshow :: PushNotificationPreferences -> String
showsPrec :: Int -> PushNotificationPreferences -> ShowS
$cshowsPrec :: Int -> PushNotificationPreferences -> ShowS
Prelude.Show, forall x.
Rep PushNotificationPreferences x -> PushNotificationPreferences
forall x.
PushNotificationPreferences -> Rep PushNotificationPreferences x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PushNotificationPreferences x -> PushNotificationPreferences
$cfrom :: forall x.
PushNotificationPreferences -> Rep PushNotificationPreferences x
Prelude.Generic)

-- |
-- Create a value of 'PushNotificationPreferences' 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:
--
-- 'filterRule', 'pushNotificationPreferences_filterRule' - The simple JSON object used to send a subset of a push notification to
-- the requested member.
--
-- 'allowNotifications', 'pushNotificationPreferences_allowNotifications' - Enum value that indicates which push notifications to send to the
-- requested member of a channel. @ALL@ sends all push notifications,
-- @NONE@ sends no push notifications, @FILTERED@ sends only filtered push
-- notifications.
newPushNotificationPreferences ::
  -- | 'allowNotifications'
  AllowNotifications ->
  PushNotificationPreferences
newPushNotificationPreferences :: AllowNotifications -> PushNotificationPreferences
newPushNotificationPreferences AllowNotifications
pAllowNotifications_ =
  PushNotificationPreferences'
    { $sel:filterRule:PushNotificationPreferences' :: Maybe (Sensitive Text)
filterRule =
        forall a. Maybe a
Prelude.Nothing,
      $sel:allowNotifications:PushNotificationPreferences' :: AllowNotifications
allowNotifications = AllowNotifications
pAllowNotifications_
    }

-- | The simple JSON object used to send a subset of a push notification to
-- the requested member.
pushNotificationPreferences_filterRule :: Lens.Lens' PushNotificationPreferences (Prelude.Maybe Prelude.Text)
pushNotificationPreferences_filterRule :: Lens' PushNotificationPreferences (Maybe Text)
pushNotificationPreferences_filterRule = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PushNotificationPreferences' {Maybe (Sensitive Text)
filterRule :: Maybe (Sensitive Text)
$sel:filterRule:PushNotificationPreferences' :: PushNotificationPreferences -> Maybe (Sensitive Text)
filterRule} -> Maybe (Sensitive Text)
filterRule) (\s :: PushNotificationPreferences
s@PushNotificationPreferences' {} Maybe (Sensitive Text)
a -> PushNotificationPreferences
s {$sel:filterRule:PushNotificationPreferences' :: Maybe (Sensitive Text)
filterRule = Maybe (Sensitive Text)
a} :: PushNotificationPreferences) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | Enum value that indicates which push notifications to send to the
-- requested member of a channel. @ALL@ sends all push notifications,
-- @NONE@ sends no push notifications, @FILTERED@ sends only filtered push
-- notifications.
pushNotificationPreferences_allowNotifications :: Lens.Lens' PushNotificationPreferences AllowNotifications
pushNotificationPreferences_allowNotifications :: Lens' PushNotificationPreferences AllowNotifications
pushNotificationPreferences_allowNotifications = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PushNotificationPreferences' {AllowNotifications
allowNotifications :: AllowNotifications
$sel:allowNotifications:PushNotificationPreferences' :: PushNotificationPreferences -> AllowNotifications
allowNotifications} -> AllowNotifications
allowNotifications) (\s :: PushNotificationPreferences
s@PushNotificationPreferences' {} AllowNotifications
a -> PushNotificationPreferences
s {$sel:allowNotifications:PushNotificationPreferences' :: AllowNotifications
allowNotifications = AllowNotifications
a} :: PushNotificationPreferences)

instance Data.FromJSON PushNotificationPreferences where
  parseJSON :: Value -> Parser PushNotificationPreferences
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PushNotificationPreferences"
      ( \Object
x ->
          Maybe (Sensitive Text)
-> AllowNotifications -> PushNotificationPreferences
PushNotificationPreferences'
            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
"FilterRule")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"AllowNotifications")
      )

instance Prelude.Hashable PushNotificationPreferences where
  hashWithSalt :: Int -> PushNotificationPreferences -> Int
hashWithSalt Int
_salt PushNotificationPreferences' {Maybe (Sensitive Text)
AllowNotifications
allowNotifications :: AllowNotifications
filterRule :: Maybe (Sensitive Text)
$sel:allowNotifications:PushNotificationPreferences' :: PushNotificationPreferences -> AllowNotifications
$sel:filterRule:PushNotificationPreferences' :: PushNotificationPreferences -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
filterRule
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AllowNotifications
allowNotifications

instance Prelude.NFData PushNotificationPreferences where
  rnf :: PushNotificationPreferences -> ()
rnf PushNotificationPreferences' {Maybe (Sensitive Text)
AllowNotifications
allowNotifications :: AllowNotifications
filterRule :: Maybe (Sensitive Text)
$sel:allowNotifications:PushNotificationPreferences' :: PushNotificationPreferences -> AllowNotifications
$sel:filterRule:PushNotificationPreferences' :: PushNotificationPreferences -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
filterRule
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AllowNotifications
allowNotifications

instance Data.ToJSON PushNotificationPreferences where
  toJSON :: PushNotificationPreferences -> Value
toJSON PushNotificationPreferences' {Maybe (Sensitive Text)
AllowNotifications
allowNotifications :: AllowNotifications
filterRule :: Maybe (Sensitive Text)
$sel:allowNotifications:PushNotificationPreferences' :: PushNotificationPreferences -> AllowNotifications
$sel:filterRule:PushNotificationPreferences' :: PushNotificationPreferences -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"FilterRule" 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 (Sensitive Text)
filterRule,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"AllowNotifications" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AllowNotifications
allowNotifications)
          ]
      )