{-# 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.Snowball.Types.Notification
-- 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.Snowball.Types.Notification where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Snowball.Types.JobState

-- | The Amazon Simple Notification Service (Amazon SNS) notification
-- settings associated with a specific job. The @Notification@ object is
-- returned as a part of the response syntax of the @DescribeJob@ action in
-- the @JobMetadata@ data type.
--
-- When the notification settings are defined during job creation, you can
-- choose to notify based on a specific set of job states using the
-- @JobStatesToNotify@ array of strings, or you can specify that you want
-- to have Amazon SNS notifications sent out for all job states with
-- @NotifyAll@ set to true.
--
-- /See:/ 'newNotification' smart constructor.
data Notification = Notification'
  { -- | Any change in job state will trigger a notification for this job.
    Notification -> Maybe Bool
notifyAll :: Prelude.Maybe Prelude.Bool,
    -- | The new SNS @TopicArn@ that you want to associate with this job. You can
    -- create Amazon Resource Names (ARNs) for topics by using the
    -- <https://docs.aws.amazon.com/sns/latest/api/API_CreateTopic.html CreateTopic>
    -- Amazon SNS API action.
    --
    -- You can subscribe email addresses to an Amazon SNS topic through the AWS
    -- Management Console, or by using the
    -- <https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html Subscribe>
    -- Amazon Simple Notification Service (Amazon SNS) API action.
    Notification -> Maybe Text
snsTopicARN :: Prelude.Maybe Prelude.Text,
    -- | The list of job states that will trigger a notification for this job.
    Notification -> Maybe [JobState]
jobStatesToNotify :: Prelude.Maybe [JobState]
  }
  deriving (Notification -> Notification -> Bool
(Notification -> Notification -> Bool)
-> (Notification -> Notification -> Bool) -> Eq Notification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Notification -> Notification -> Bool
$c/= :: Notification -> Notification -> Bool
== :: Notification -> Notification -> Bool
$c== :: Notification -> Notification -> Bool
Prelude.Eq, ReadPrec [Notification]
ReadPrec Notification
Int -> ReadS Notification
ReadS [Notification]
(Int -> ReadS Notification)
-> ReadS [Notification]
-> ReadPrec Notification
-> ReadPrec [Notification]
-> Read Notification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Notification]
$creadListPrec :: ReadPrec [Notification]
readPrec :: ReadPrec Notification
$creadPrec :: ReadPrec Notification
readList :: ReadS [Notification]
$creadList :: ReadS [Notification]
readsPrec :: Int -> ReadS Notification
$creadsPrec :: Int -> ReadS Notification
Prelude.Read, Int -> Notification -> ShowS
[Notification] -> ShowS
Notification -> String
(Int -> Notification -> ShowS)
-> (Notification -> String)
-> ([Notification] -> ShowS)
-> Show Notification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Notification] -> ShowS
$cshowList :: [Notification] -> ShowS
show :: Notification -> String
$cshow :: Notification -> String
showsPrec :: Int -> Notification -> ShowS
$cshowsPrec :: Int -> Notification -> ShowS
Prelude.Show, (forall x. Notification -> Rep Notification x)
-> (forall x. Rep Notification x -> Notification)
-> Generic Notification
forall x. Rep Notification x -> Notification
forall x. Notification -> Rep Notification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Notification x -> Notification
$cfrom :: forall x. Notification -> Rep Notification x
Prelude.Generic)

-- |
-- Create a value of 'Notification' 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:
--
-- 'notifyAll', 'notification_notifyAll' - Any change in job state will trigger a notification for this job.
--
-- 'snsTopicARN', 'notification_snsTopicARN' - The new SNS @TopicArn@ that you want to associate with this job. You can
-- create Amazon Resource Names (ARNs) for topics by using the
-- <https://docs.aws.amazon.com/sns/latest/api/API_CreateTopic.html CreateTopic>
-- Amazon SNS API action.
--
-- You can subscribe email addresses to an Amazon SNS topic through the AWS
-- Management Console, or by using the
-- <https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html Subscribe>
-- Amazon Simple Notification Service (Amazon SNS) API action.
--
-- 'jobStatesToNotify', 'notification_jobStatesToNotify' - The list of job states that will trigger a notification for this job.
newNotification ::
  Notification
newNotification :: Notification
newNotification =
  Notification' :: Maybe Bool -> Maybe Text -> Maybe [JobState] -> Notification
Notification'
    { $sel:notifyAll:Notification' :: Maybe Bool
notifyAll = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:snsTopicARN:Notification' :: Maybe Text
snsTopicARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:jobStatesToNotify:Notification' :: Maybe [JobState]
jobStatesToNotify = Maybe [JobState]
forall a. Maybe a
Prelude.Nothing
    }

-- | Any change in job state will trigger a notification for this job.
notification_notifyAll :: Lens.Lens' Notification (Prelude.Maybe Prelude.Bool)
notification_notifyAll :: (Maybe Bool -> f (Maybe Bool)) -> Notification -> f Notification
notification_notifyAll = (Notification -> Maybe Bool)
-> (Notification -> Maybe Bool -> Notification)
-> Lens Notification Notification (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {Maybe Bool
notifyAll :: Maybe Bool
$sel:notifyAll:Notification' :: Notification -> Maybe Bool
notifyAll} -> Maybe Bool
notifyAll) (\s :: Notification
s@Notification' {} Maybe Bool
a -> Notification
s {$sel:notifyAll:Notification' :: Maybe Bool
notifyAll = Maybe Bool
a} :: Notification)

-- | The new SNS @TopicArn@ that you want to associate with this job. You can
-- create Amazon Resource Names (ARNs) for topics by using the
-- <https://docs.aws.amazon.com/sns/latest/api/API_CreateTopic.html CreateTopic>
-- Amazon SNS API action.
--
-- You can subscribe email addresses to an Amazon SNS topic through the AWS
-- Management Console, or by using the
-- <https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html Subscribe>
-- Amazon Simple Notification Service (Amazon SNS) API action.
notification_snsTopicARN :: Lens.Lens' Notification (Prelude.Maybe Prelude.Text)
notification_snsTopicARN :: (Maybe Text -> f (Maybe Text)) -> Notification -> f Notification
notification_snsTopicARN = (Notification -> Maybe Text)
-> (Notification -> Maybe Text -> Notification)
-> Lens Notification Notification (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {Maybe Text
snsTopicARN :: Maybe Text
$sel:snsTopicARN:Notification' :: Notification -> Maybe Text
snsTopicARN} -> Maybe Text
snsTopicARN) (\s :: Notification
s@Notification' {} Maybe Text
a -> Notification
s {$sel:snsTopicARN:Notification' :: Maybe Text
snsTopicARN = Maybe Text
a} :: Notification)

-- | The list of job states that will trigger a notification for this job.
notification_jobStatesToNotify :: Lens.Lens' Notification (Prelude.Maybe [JobState])
notification_jobStatesToNotify :: (Maybe [JobState] -> f (Maybe [JobState]))
-> Notification -> f Notification
notification_jobStatesToNotify = (Notification -> Maybe [JobState])
-> (Notification -> Maybe [JobState] -> Notification)
-> Lens
     Notification Notification (Maybe [JobState]) (Maybe [JobState])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Notification' {Maybe [JobState]
jobStatesToNotify :: Maybe [JobState]
$sel:jobStatesToNotify:Notification' :: Notification -> Maybe [JobState]
jobStatesToNotify} -> Maybe [JobState]
jobStatesToNotify) (\s :: Notification
s@Notification' {} Maybe [JobState]
a -> Notification
s {$sel:jobStatesToNotify:Notification' :: Maybe [JobState]
jobStatesToNotify = Maybe [JobState]
a} :: Notification) ((Maybe [JobState] -> f (Maybe [JobState]))
 -> Notification -> f Notification)
-> ((Maybe [JobState] -> f (Maybe [JobState]))
    -> Maybe [JobState] -> f (Maybe [JobState]))
-> (Maybe [JobState] -> f (Maybe [JobState]))
-> Notification
-> f Notification
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [JobState] [JobState] [JobState] [JobState]
-> Iso
     (Maybe [JobState])
     (Maybe [JobState])
     (Maybe [JobState])
     (Maybe [JobState])
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 [JobState] [JobState] [JobState] [JobState]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Notification

instance Prelude.NFData Notification

instance Core.ToJSON Notification where
  toJSON :: Notification -> Value
toJSON Notification' {Maybe Bool
Maybe [JobState]
Maybe Text
jobStatesToNotify :: Maybe [JobState]
snsTopicARN :: Maybe Text
notifyAll :: Maybe Bool
$sel:jobStatesToNotify:Notification' :: Notification -> Maybe [JobState]
$sel:snsTopicARN:Notification' :: Notification -> Maybe Text
$sel:notifyAll:Notification' :: Notification -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NotifyAll" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
notifyAll,
            (Text
"SnsTopicARN" 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
snsTopicARN,
            (Text
"JobStatesToNotify" Text -> [JobState] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([JobState] -> Pair) -> Maybe [JobState] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [JobState]
jobStatesToNotify
          ]
      )