{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Snowball.Types.Notification where

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
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'
  { -- | The list of job states that will trigger a notification for this job.
    Notification -> Maybe [JobState]
jobStatesToNotify :: Prelude.Maybe [JobState],
    -- | 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
    -- Amazon Web Services 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
  }
  deriving (Notification -> Notification -> Bool
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]
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
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. 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:
--
-- 'jobStatesToNotify', 'notification_jobStatesToNotify' - The list of job states that will trigger a notification for this job.
--
-- '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
-- Amazon Web Services 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.
newNotification ::
  Notification
newNotification :: Notification
newNotification =
  Notification'
    { $sel:jobStatesToNotify:Notification' :: Maybe [JobState]
jobStatesToNotify = forall a. Maybe a
Prelude.Nothing,
      $sel:notifyAll:Notification' :: Maybe Bool
notifyAll = forall a. Maybe a
Prelude.Nothing,
      $sel:snsTopicARN:Notification' :: Maybe Text
snsTopicARN = forall a. Maybe a
Prelude.Nothing
    }

-- | The list of job states that will trigger a notification for this job.
notification_jobStatesToNotify :: Lens.Lens' Notification (Prelude.Maybe [JobState])
notification_jobStatesToNotify :: Lens' Notification (Maybe [JobState])
notification_jobStatesToNotify = 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) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Any change in job state will trigger a notification for this job.
notification_notifyAll :: Lens.Lens' Notification (Prelude.Maybe Prelude.Bool)
notification_notifyAll :: Lens' Notification (Maybe Bool)
notification_notifyAll = 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
-- Amazon Web Services 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 :: Lens' Notification (Maybe Text)
notification_snsTopicARN = 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)

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

instance Prelude.Hashable Notification where
  hashWithSalt :: Int -> Notification -> Int
hashWithSalt Int
_salt Notification' {Maybe Bool
Maybe [JobState]
Maybe Text
snsTopicARN :: Maybe Text
notifyAll :: Maybe Bool
jobStatesToNotify :: Maybe [JobState]
$sel:snsTopicARN:Notification' :: Notification -> Maybe Text
$sel:notifyAll:Notification' :: Notification -> Maybe Bool
$sel:jobStatesToNotify:Notification' :: Notification -> Maybe [JobState]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [JobState]
jobStatesToNotify
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
notifyAll
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
snsTopicARN

instance Prelude.NFData Notification where
  rnf :: Notification -> ()
rnf Notification' {Maybe Bool
Maybe [JobState]
Maybe Text
snsTopicARN :: Maybe Text
notifyAll :: Maybe Bool
jobStatesToNotify :: Maybe [JobState]
$sel:snsTopicARN:Notification' :: Notification -> Maybe Text
$sel:notifyAll:Notification' :: Notification -> Maybe Bool
$sel:jobStatesToNotify:Notification' :: Notification -> Maybe [JobState]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [JobState]
jobStatesToNotify
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
notifyAll
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
snsTopicARN

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