{-# 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.IoTEvents.Types.NotificationAction
-- 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.IoTEvents.Types.NotificationAction where

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.EmailConfiguration
import Amazonka.IoTEvents.Types.NotificationTargetActions
import Amazonka.IoTEvents.Types.SMSConfiguration
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains the notification settings of an alarm model. The settings apply
-- to all alarms that were created based on this alarm model.
--
-- /See:/ 'newNotificationAction' smart constructor.
data NotificationAction = NotificationAction'
  { -- | Contains the configuration information of email notifications.
    NotificationAction -> Maybe (NonEmpty EmailConfiguration)
emailConfigurations :: Prelude.Maybe (Prelude.NonEmpty EmailConfiguration),
    -- | Contains the configuration information of SMS notifications.
    NotificationAction -> Maybe (NonEmpty SMSConfiguration)
smsConfigurations :: Prelude.Maybe (Prelude.NonEmpty SMSConfiguration),
    -- | Specifies an AWS Lambda function to manage alarm notifications. You can
    -- create one or use the
    -- <https://docs.aws.amazon.com/iotevents/latest/developerguide/lambda-support.html AWS Lambda function provided by AWS IoT Events>.
    NotificationAction -> NotificationTargetActions
action :: NotificationTargetActions
  }
  deriving (NotificationAction -> NotificationAction -> Bool
(NotificationAction -> NotificationAction -> Bool)
-> (NotificationAction -> NotificationAction -> Bool)
-> Eq NotificationAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NotificationAction -> NotificationAction -> Bool
$c/= :: NotificationAction -> NotificationAction -> Bool
== :: NotificationAction -> NotificationAction -> Bool
$c== :: NotificationAction -> NotificationAction -> Bool
Prelude.Eq, ReadPrec [NotificationAction]
ReadPrec NotificationAction
Int -> ReadS NotificationAction
ReadS [NotificationAction]
(Int -> ReadS NotificationAction)
-> ReadS [NotificationAction]
-> ReadPrec NotificationAction
-> ReadPrec [NotificationAction]
-> Read NotificationAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NotificationAction]
$creadListPrec :: ReadPrec [NotificationAction]
readPrec :: ReadPrec NotificationAction
$creadPrec :: ReadPrec NotificationAction
readList :: ReadS [NotificationAction]
$creadList :: ReadS [NotificationAction]
readsPrec :: Int -> ReadS NotificationAction
$creadsPrec :: Int -> ReadS NotificationAction
Prelude.Read, Int -> NotificationAction -> ShowS
[NotificationAction] -> ShowS
NotificationAction -> String
(Int -> NotificationAction -> ShowS)
-> (NotificationAction -> String)
-> ([NotificationAction] -> ShowS)
-> Show NotificationAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NotificationAction] -> ShowS
$cshowList :: [NotificationAction] -> ShowS
show :: NotificationAction -> String
$cshow :: NotificationAction -> String
showsPrec :: Int -> NotificationAction -> ShowS
$cshowsPrec :: Int -> NotificationAction -> ShowS
Prelude.Show, (forall x. NotificationAction -> Rep NotificationAction x)
-> (forall x. Rep NotificationAction x -> NotificationAction)
-> Generic NotificationAction
forall x. Rep NotificationAction x -> NotificationAction
forall x. NotificationAction -> Rep NotificationAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NotificationAction x -> NotificationAction
$cfrom :: forall x. NotificationAction -> Rep NotificationAction x
Prelude.Generic)

-- |
-- Create a value of 'NotificationAction' 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:
--
-- 'emailConfigurations', 'notificationAction_emailConfigurations' - Contains the configuration information of email notifications.
--
-- 'smsConfigurations', 'notificationAction_smsConfigurations' - Contains the configuration information of SMS notifications.
--
-- 'action', 'notificationAction_action' - Specifies an AWS Lambda function to manage alarm notifications. You can
-- create one or use the
-- <https://docs.aws.amazon.com/iotevents/latest/developerguide/lambda-support.html AWS Lambda function provided by AWS IoT Events>.
newNotificationAction ::
  -- | 'action'
  NotificationTargetActions ->
  NotificationAction
newNotificationAction :: NotificationTargetActions -> NotificationAction
newNotificationAction NotificationTargetActions
pAction_ =
  NotificationAction' :: Maybe (NonEmpty EmailConfiguration)
-> Maybe (NonEmpty SMSConfiguration)
-> NotificationTargetActions
-> NotificationAction
NotificationAction'
    { $sel:emailConfigurations:NotificationAction' :: Maybe (NonEmpty EmailConfiguration)
emailConfigurations =
        Maybe (NonEmpty EmailConfiguration)
forall a. Maybe a
Prelude.Nothing,
      $sel:smsConfigurations:NotificationAction' :: Maybe (NonEmpty SMSConfiguration)
smsConfigurations = Maybe (NonEmpty SMSConfiguration)
forall a. Maybe a
Prelude.Nothing,
      $sel:action:NotificationAction' :: NotificationTargetActions
action = NotificationTargetActions
pAction_
    }

-- | Contains the configuration information of email notifications.
notificationAction_emailConfigurations :: Lens.Lens' NotificationAction (Prelude.Maybe (Prelude.NonEmpty EmailConfiguration))
notificationAction_emailConfigurations :: (Maybe (NonEmpty EmailConfiguration)
 -> f (Maybe (NonEmpty EmailConfiguration)))
-> NotificationAction -> f NotificationAction
notificationAction_emailConfigurations = (NotificationAction -> Maybe (NonEmpty EmailConfiguration))
-> (NotificationAction
    -> Maybe (NonEmpty EmailConfiguration) -> NotificationAction)
-> Lens
     NotificationAction
     NotificationAction
     (Maybe (NonEmpty EmailConfiguration))
     (Maybe (NonEmpty EmailConfiguration))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationAction' {Maybe (NonEmpty EmailConfiguration)
emailConfigurations :: Maybe (NonEmpty EmailConfiguration)
$sel:emailConfigurations:NotificationAction' :: NotificationAction -> Maybe (NonEmpty EmailConfiguration)
emailConfigurations} -> Maybe (NonEmpty EmailConfiguration)
emailConfigurations) (\s :: NotificationAction
s@NotificationAction' {} Maybe (NonEmpty EmailConfiguration)
a -> NotificationAction
s {$sel:emailConfigurations:NotificationAction' :: Maybe (NonEmpty EmailConfiguration)
emailConfigurations = Maybe (NonEmpty EmailConfiguration)
a} :: NotificationAction) ((Maybe (NonEmpty EmailConfiguration)
  -> f (Maybe (NonEmpty EmailConfiguration)))
 -> NotificationAction -> f NotificationAction)
-> ((Maybe (NonEmpty EmailConfiguration)
     -> f (Maybe (NonEmpty EmailConfiguration)))
    -> Maybe (NonEmpty EmailConfiguration)
    -> f (Maybe (NonEmpty EmailConfiguration)))
-> (Maybe (NonEmpty EmailConfiguration)
    -> f (Maybe (NonEmpty EmailConfiguration)))
-> NotificationAction
-> f NotificationAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty EmailConfiguration)
  (NonEmpty EmailConfiguration)
  (NonEmpty EmailConfiguration)
  (NonEmpty EmailConfiguration)
-> Iso
     (Maybe (NonEmpty EmailConfiguration))
     (Maybe (NonEmpty EmailConfiguration))
     (Maybe (NonEmpty EmailConfiguration))
     (Maybe (NonEmpty EmailConfiguration))
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
  (NonEmpty EmailConfiguration)
  (NonEmpty EmailConfiguration)
  (NonEmpty EmailConfiguration)
  (NonEmpty EmailConfiguration)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Contains the configuration information of SMS notifications.
notificationAction_smsConfigurations :: Lens.Lens' NotificationAction (Prelude.Maybe (Prelude.NonEmpty SMSConfiguration))
notificationAction_smsConfigurations :: (Maybe (NonEmpty SMSConfiguration)
 -> f (Maybe (NonEmpty SMSConfiguration)))
-> NotificationAction -> f NotificationAction
notificationAction_smsConfigurations = (NotificationAction -> Maybe (NonEmpty SMSConfiguration))
-> (NotificationAction
    -> Maybe (NonEmpty SMSConfiguration) -> NotificationAction)
-> Lens
     NotificationAction
     NotificationAction
     (Maybe (NonEmpty SMSConfiguration))
     (Maybe (NonEmpty SMSConfiguration))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationAction' {Maybe (NonEmpty SMSConfiguration)
smsConfigurations :: Maybe (NonEmpty SMSConfiguration)
$sel:smsConfigurations:NotificationAction' :: NotificationAction -> Maybe (NonEmpty SMSConfiguration)
smsConfigurations} -> Maybe (NonEmpty SMSConfiguration)
smsConfigurations) (\s :: NotificationAction
s@NotificationAction' {} Maybe (NonEmpty SMSConfiguration)
a -> NotificationAction
s {$sel:smsConfigurations:NotificationAction' :: Maybe (NonEmpty SMSConfiguration)
smsConfigurations = Maybe (NonEmpty SMSConfiguration)
a} :: NotificationAction) ((Maybe (NonEmpty SMSConfiguration)
  -> f (Maybe (NonEmpty SMSConfiguration)))
 -> NotificationAction -> f NotificationAction)
-> ((Maybe (NonEmpty SMSConfiguration)
     -> f (Maybe (NonEmpty SMSConfiguration)))
    -> Maybe (NonEmpty SMSConfiguration)
    -> f (Maybe (NonEmpty SMSConfiguration)))
-> (Maybe (NonEmpty SMSConfiguration)
    -> f (Maybe (NonEmpty SMSConfiguration)))
-> NotificationAction
-> f NotificationAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty SMSConfiguration)
  (NonEmpty SMSConfiguration)
  (NonEmpty SMSConfiguration)
  (NonEmpty SMSConfiguration)
-> Iso
     (Maybe (NonEmpty SMSConfiguration))
     (Maybe (NonEmpty SMSConfiguration))
     (Maybe (NonEmpty SMSConfiguration))
     (Maybe (NonEmpty SMSConfiguration))
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
  (NonEmpty SMSConfiguration)
  (NonEmpty SMSConfiguration)
  (NonEmpty SMSConfiguration)
  (NonEmpty SMSConfiguration)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies an AWS Lambda function to manage alarm notifications. You can
-- create one or use the
-- <https://docs.aws.amazon.com/iotevents/latest/developerguide/lambda-support.html AWS Lambda function provided by AWS IoT Events>.
notificationAction_action :: Lens.Lens' NotificationAction NotificationTargetActions
notificationAction_action :: (NotificationTargetActions -> f NotificationTargetActions)
-> NotificationAction -> f NotificationAction
notificationAction_action = (NotificationAction -> NotificationTargetActions)
-> (NotificationAction
    -> NotificationTargetActions -> NotificationAction)
-> Lens
     NotificationAction
     NotificationAction
     NotificationTargetActions
     NotificationTargetActions
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationAction' {NotificationTargetActions
action :: NotificationTargetActions
$sel:action:NotificationAction' :: NotificationAction -> NotificationTargetActions
action} -> NotificationTargetActions
action) (\s :: NotificationAction
s@NotificationAction' {} NotificationTargetActions
a -> NotificationAction
s {$sel:action:NotificationAction' :: NotificationTargetActions
action = NotificationTargetActions
a} :: NotificationAction)

instance Core.FromJSON NotificationAction where
  parseJSON :: Value -> Parser NotificationAction
parseJSON =
    String
-> (Object -> Parser NotificationAction)
-> Value
-> Parser NotificationAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NotificationAction"
      ( \Object
x ->
          Maybe (NonEmpty EmailConfiguration)
-> Maybe (NonEmpty SMSConfiguration)
-> NotificationTargetActions
-> NotificationAction
NotificationAction'
            (Maybe (NonEmpty EmailConfiguration)
 -> Maybe (NonEmpty SMSConfiguration)
 -> NotificationTargetActions
 -> NotificationAction)
-> Parser (Maybe (NonEmpty EmailConfiguration))
-> Parser
     (Maybe (NonEmpty SMSConfiguration)
      -> NotificationTargetActions -> NotificationAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty EmailConfiguration))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"emailConfigurations")
            Parser
  (Maybe (NonEmpty SMSConfiguration)
   -> NotificationTargetActions -> NotificationAction)
-> Parser (Maybe (NonEmpty SMSConfiguration))
-> Parser (NotificationTargetActions -> NotificationAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty SMSConfiguration))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"smsConfigurations")
            Parser (NotificationTargetActions -> NotificationAction)
-> Parser NotificationTargetActions -> Parser NotificationAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser NotificationTargetActions
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"action")
      )

instance Prelude.Hashable NotificationAction

instance Prelude.NFData NotificationAction

instance Core.ToJSON NotificationAction where
  toJSON :: NotificationAction -> Value
toJSON NotificationAction' {Maybe (NonEmpty SMSConfiguration)
Maybe (NonEmpty EmailConfiguration)
NotificationTargetActions
action :: NotificationTargetActions
smsConfigurations :: Maybe (NonEmpty SMSConfiguration)
emailConfigurations :: Maybe (NonEmpty EmailConfiguration)
$sel:action:NotificationAction' :: NotificationAction -> NotificationTargetActions
$sel:smsConfigurations:NotificationAction' :: NotificationAction -> Maybe (NonEmpty SMSConfiguration)
$sel:emailConfigurations:NotificationAction' :: NotificationAction -> Maybe (NonEmpty EmailConfiguration)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"emailConfigurations" Text -> NonEmpty EmailConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty EmailConfiguration -> Pair)
-> Maybe (NonEmpty EmailConfiguration) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty EmailConfiguration)
emailConfigurations,
            (Text
"smsConfigurations" Text -> NonEmpty SMSConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty SMSConfiguration -> Pair)
-> Maybe (NonEmpty SMSConfiguration) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty SMSConfiguration)
smsConfigurations,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> NotificationTargetActions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NotificationTargetActions
action)
          ]
      )