{-# 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.SSM.Types.NotificationConfig
-- 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.SSM.Types.NotificationConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSM.Types.NotificationEvent
import Amazonka.SSM.Types.NotificationType

-- | Configurations for sending notifications.
--
-- /See:/ 'newNotificationConfig' smart constructor.
data NotificationConfig = NotificationConfig'
  { -- | The different events for which you can receive notifications. To learn
    -- more about these events, see
    -- <https://docs.aws.amazon.com/systems-manager/latest/userguide/monitoring-sns-notifications.html Monitoring Systems Manager status changes using Amazon SNS notifications>
    -- in the /Amazon Web Services Systems Manager User Guide/.
    NotificationConfig -> Maybe [NotificationEvent]
notificationEvents :: Prelude.Maybe [NotificationEvent],
    -- | The type of notification.
    --
    -- -   @Command@: Receive notification when the status of a command
    --     changes.
    --
    -- -   @Invocation@: For commands sent to multiple instances, receive
    --     notification on a per-instance basis when the status of a command
    --     changes.
    NotificationConfig -> Maybe NotificationType
notificationType :: Prelude.Maybe NotificationType,
    -- | An Amazon Resource Name (ARN) for an Amazon Simple Notification Service
    -- (Amazon SNS) topic. Run Command pushes notifications about command
    -- status changes to this topic.
    NotificationConfig -> Maybe Text
notificationArn :: Prelude.Maybe Prelude.Text
  }
  deriving (NotificationConfig -> NotificationConfig -> Bool
(NotificationConfig -> NotificationConfig -> Bool)
-> (NotificationConfig -> NotificationConfig -> Bool)
-> Eq NotificationConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NotificationConfig -> NotificationConfig -> Bool
$c/= :: NotificationConfig -> NotificationConfig -> Bool
== :: NotificationConfig -> NotificationConfig -> Bool
$c== :: NotificationConfig -> NotificationConfig -> Bool
Prelude.Eq, ReadPrec [NotificationConfig]
ReadPrec NotificationConfig
Int -> ReadS NotificationConfig
ReadS [NotificationConfig]
(Int -> ReadS NotificationConfig)
-> ReadS [NotificationConfig]
-> ReadPrec NotificationConfig
-> ReadPrec [NotificationConfig]
-> Read NotificationConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NotificationConfig]
$creadListPrec :: ReadPrec [NotificationConfig]
readPrec :: ReadPrec NotificationConfig
$creadPrec :: ReadPrec NotificationConfig
readList :: ReadS [NotificationConfig]
$creadList :: ReadS [NotificationConfig]
readsPrec :: Int -> ReadS NotificationConfig
$creadsPrec :: Int -> ReadS NotificationConfig
Prelude.Read, Int -> NotificationConfig -> ShowS
[NotificationConfig] -> ShowS
NotificationConfig -> String
(Int -> NotificationConfig -> ShowS)
-> (NotificationConfig -> String)
-> ([NotificationConfig] -> ShowS)
-> Show NotificationConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NotificationConfig] -> ShowS
$cshowList :: [NotificationConfig] -> ShowS
show :: NotificationConfig -> String
$cshow :: NotificationConfig -> String
showsPrec :: Int -> NotificationConfig -> ShowS
$cshowsPrec :: Int -> NotificationConfig -> ShowS
Prelude.Show, (forall x. NotificationConfig -> Rep NotificationConfig x)
-> (forall x. Rep NotificationConfig x -> NotificationConfig)
-> Generic NotificationConfig
forall x. Rep NotificationConfig x -> NotificationConfig
forall x. NotificationConfig -> Rep NotificationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NotificationConfig x -> NotificationConfig
$cfrom :: forall x. NotificationConfig -> Rep NotificationConfig x
Prelude.Generic)

-- |
-- Create a value of 'NotificationConfig' 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:
--
-- 'notificationEvents', 'notificationConfig_notificationEvents' - The different events for which you can receive notifications. To learn
-- more about these events, see
-- <https://docs.aws.amazon.com/systems-manager/latest/userguide/monitoring-sns-notifications.html Monitoring Systems Manager status changes using Amazon SNS notifications>
-- in the /Amazon Web Services Systems Manager User Guide/.
--
-- 'notificationType', 'notificationConfig_notificationType' - The type of notification.
--
-- -   @Command@: Receive notification when the status of a command
--     changes.
--
-- -   @Invocation@: For commands sent to multiple instances, receive
--     notification on a per-instance basis when the status of a command
--     changes.
--
-- 'notificationArn', 'notificationConfig_notificationArn' - An Amazon Resource Name (ARN) for an Amazon Simple Notification Service
-- (Amazon SNS) topic. Run Command pushes notifications about command
-- status changes to this topic.
newNotificationConfig ::
  NotificationConfig
newNotificationConfig :: NotificationConfig
newNotificationConfig =
  NotificationConfig' :: Maybe [NotificationEvent]
-> Maybe NotificationType -> Maybe Text -> NotificationConfig
NotificationConfig'
    { $sel:notificationEvents:NotificationConfig' :: Maybe [NotificationEvent]
notificationEvents =
        Maybe [NotificationEvent]
forall a. Maybe a
Prelude.Nothing,
      $sel:notificationType:NotificationConfig' :: Maybe NotificationType
notificationType = Maybe NotificationType
forall a. Maybe a
Prelude.Nothing,
      $sel:notificationArn:NotificationConfig' :: Maybe Text
notificationArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The different events for which you can receive notifications. To learn
-- more about these events, see
-- <https://docs.aws.amazon.com/systems-manager/latest/userguide/monitoring-sns-notifications.html Monitoring Systems Manager status changes using Amazon SNS notifications>
-- in the /Amazon Web Services Systems Manager User Guide/.
notificationConfig_notificationEvents :: Lens.Lens' NotificationConfig (Prelude.Maybe [NotificationEvent])
notificationConfig_notificationEvents :: (Maybe [NotificationEvent] -> f (Maybe [NotificationEvent]))
-> NotificationConfig -> f NotificationConfig
notificationConfig_notificationEvents = (NotificationConfig -> Maybe [NotificationEvent])
-> (NotificationConfig
    -> Maybe [NotificationEvent] -> NotificationConfig)
-> Lens
     NotificationConfig
     NotificationConfig
     (Maybe [NotificationEvent])
     (Maybe [NotificationEvent])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfig' {Maybe [NotificationEvent]
notificationEvents :: Maybe [NotificationEvent]
$sel:notificationEvents:NotificationConfig' :: NotificationConfig -> Maybe [NotificationEvent]
notificationEvents} -> Maybe [NotificationEvent]
notificationEvents) (\s :: NotificationConfig
s@NotificationConfig' {} Maybe [NotificationEvent]
a -> NotificationConfig
s {$sel:notificationEvents:NotificationConfig' :: Maybe [NotificationEvent]
notificationEvents = Maybe [NotificationEvent]
a} :: NotificationConfig) ((Maybe [NotificationEvent] -> f (Maybe [NotificationEvent]))
 -> NotificationConfig -> f NotificationConfig)
-> ((Maybe [NotificationEvent] -> f (Maybe [NotificationEvent]))
    -> Maybe [NotificationEvent] -> f (Maybe [NotificationEvent]))
-> (Maybe [NotificationEvent] -> f (Maybe [NotificationEvent]))
-> NotificationConfig
-> f NotificationConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [NotificationEvent]
  [NotificationEvent]
  [NotificationEvent]
  [NotificationEvent]
-> Iso
     (Maybe [NotificationEvent])
     (Maybe [NotificationEvent])
     (Maybe [NotificationEvent])
     (Maybe [NotificationEvent])
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
  [NotificationEvent]
  [NotificationEvent]
  [NotificationEvent]
  [NotificationEvent]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The type of notification.
--
-- -   @Command@: Receive notification when the status of a command
--     changes.
--
-- -   @Invocation@: For commands sent to multiple instances, receive
--     notification on a per-instance basis when the status of a command
--     changes.
notificationConfig_notificationType :: Lens.Lens' NotificationConfig (Prelude.Maybe NotificationType)
notificationConfig_notificationType :: (Maybe NotificationType -> f (Maybe NotificationType))
-> NotificationConfig -> f NotificationConfig
notificationConfig_notificationType = (NotificationConfig -> Maybe NotificationType)
-> (NotificationConfig
    -> Maybe NotificationType -> NotificationConfig)
-> Lens
     NotificationConfig
     NotificationConfig
     (Maybe NotificationType)
     (Maybe NotificationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfig' {Maybe NotificationType
notificationType :: Maybe NotificationType
$sel:notificationType:NotificationConfig' :: NotificationConfig -> Maybe NotificationType
notificationType} -> Maybe NotificationType
notificationType) (\s :: NotificationConfig
s@NotificationConfig' {} Maybe NotificationType
a -> NotificationConfig
s {$sel:notificationType:NotificationConfig' :: Maybe NotificationType
notificationType = Maybe NotificationType
a} :: NotificationConfig)

-- | An Amazon Resource Name (ARN) for an Amazon Simple Notification Service
-- (Amazon SNS) topic. Run Command pushes notifications about command
-- status changes to this topic.
notificationConfig_notificationArn :: Lens.Lens' NotificationConfig (Prelude.Maybe Prelude.Text)
notificationConfig_notificationArn :: (Maybe Text -> f (Maybe Text))
-> NotificationConfig -> f NotificationConfig
notificationConfig_notificationArn = (NotificationConfig -> Maybe Text)
-> (NotificationConfig -> Maybe Text -> NotificationConfig)
-> Lens
     NotificationConfig NotificationConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationConfig' {Maybe Text
notificationArn :: Maybe Text
$sel:notificationArn:NotificationConfig' :: NotificationConfig -> Maybe Text
notificationArn} -> Maybe Text
notificationArn) (\s :: NotificationConfig
s@NotificationConfig' {} Maybe Text
a -> NotificationConfig
s {$sel:notificationArn:NotificationConfig' :: Maybe Text
notificationArn = Maybe Text
a} :: NotificationConfig)

instance Core.FromJSON NotificationConfig where
  parseJSON :: Value -> Parser NotificationConfig
parseJSON =
    String
-> (Object -> Parser NotificationConfig)
-> Value
-> Parser NotificationConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NotificationConfig"
      ( \Object
x ->
          Maybe [NotificationEvent]
-> Maybe NotificationType -> Maybe Text -> NotificationConfig
NotificationConfig'
            (Maybe [NotificationEvent]
 -> Maybe NotificationType -> Maybe Text -> NotificationConfig)
-> Parser (Maybe [NotificationEvent])
-> Parser
     (Maybe NotificationType -> Maybe Text -> NotificationConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [NotificationEvent]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NotificationEvents"
                            Parser (Maybe (Maybe [NotificationEvent]))
-> Maybe [NotificationEvent] -> Parser (Maybe [NotificationEvent])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [NotificationEvent]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe NotificationType -> Maybe Text -> NotificationConfig)
-> Parser (Maybe NotificationType)
-> Parser (Maybe Text -> NotificationConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe NotificationType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NotificationType")
            Parser (Maybe Text -> NotificationConfig)
-> Parser (Maybe Text) -> Parser NotificationConfig
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
"NotificationArn")
      )

instance Prelude.Hashable NotificationConfig

instance Prelude.NFData NotificationConfig

instance Core.ToJSON NotificationConfig where
  toJSON :: NotificationConfig -> Value
toJSON NotificationConfig' {Maybe [NotificationEvent]
Maybe Text
Maybe NotificationType
notificationArn :: Maybe Text
notificationType :: Maybe NotificationType
notificationEvents :: Maybe [NotificationEvent]
$sel:notificationArn:NotificationConfig' :: NotificationConfig -> Maybe Text
$sel:notificationType:NotificationConfig' :: NotificationConfig -> Maybe NotificationType
$sel:notificationEvents:NotificationConfig' :: NotificationConfig -> Maybe [NotificationEvent]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NotificationEvents" Text -> [NotificationEvent] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([NotificationEvent] -> Pair)
-> Maybe [NotificationEvent] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [NotificationEvent]
notificationEvents,
            (Text
"NotificationType" Text -> NotificationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NotificationType -> Pair) -> Maybe NotificationType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe NotificationType
notificationType,
            (Text
"NotificationArn" 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
notificationArn
          ]
      )