{-# 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.Budgets.Types.NotificationWithSubscribers
-- 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.Budgets.Types.NotificationWithSubscribers where

import Amazonka.Budgets.Types.Notification
import Amazonka.Budgets.Types.Subscriber
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A notification with subscribers. A notification can have one SNS
-- subscriber and up to 10 email subscribers, for a total of 11
-- subscribers.
--
-- /See:/ 'newNotificationWithSubscribers' smart constructor.
data NotificationWithSubscribers = NotificationWithSubscribers'
  { -- | The notification that is associated with a budget.
    NotificationWithSubscribers -> Notification
notification :: Notification,
    -- | A list of subscribers who are subscribed to this notification.
    NotificationWithSubscribers -> NonEmpty Subscriber
subscribers :: Prelude.NonEmpty Subscriber
  }
  deriving (NotificationWithSubscribers -> NotificationWithSubscribers -> Bool
(NotificationWithSubscribers
 -> NotificationWithSubscribers -> Bool)
-> (NotificationWithSubscribers
    -> NotificationWithSubscribers -> Bool)
-> Eq NotificationWithSubscribers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NotificationWithSubscribers -> NotificationWithSubscribers -> Bool
$c/= :: NotificationWithSubscribers -> NotificationWithSubscribers -> Bool
== :: NotificationWithSubscribers -> NotificationWithSubscribers -> Bool
$c== :: NotificationWithSubscribers -> NotificationWithSubscribers -> Bool
Prelude.Eq, Int -> NotificationWithSubscribers -> ShowS
[NotificationWithSubscribers] -> ShowS
NotificationWithSubscribers -> String
(Int -> NotificationWithSubscribers -> ShowS)
-> (NotificationWithSubscribers -> String)
-> ([NotificationWithSubscribers] -> ShowS)
-> Show NotificationWithSubscribers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NotificationWithSubscribers] -> ShowS
$cshowList :: [NotificationWithSubscribers] -> ShowS
show :: NotificationWithSubscribers -> String
$cshow :: NotificationWithSubscribers -> String
showsPrec :: Int -> NotificationWithSubscribers -> ShowS
$cshowsPrec :: Int -> NotificationWithSubscribers -> ShowS
Prelude.Show, (forall x.
 NotificationWithSubscribers -> Rep NotificationWithSubscribers x)
-> (forall x.
    Rep NotificationWithSubscribers x -> NotificationWithSubscribers)
-> Generic NotificationWithSubscribers
forall x.
Rep NotificationWithSubscribers x -> NotificationWithSubscribers
forall x.
NotificationWithSubscribers -> Rep NotificationWithSubscribers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep NotificationWithSubscribers x -> NotificationWithSubscribers
$cfrom :: forall x.
NotificationWithSubscribers -> Rep NotificationWithSubscribers x
Prelude.Generic)

-- |
-- Create a value of 'NotificationWithSubscribers' 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:
--
-- 'notification', 'notificationWithSubscribers_notification' - The notification that is associated with a budget.
--
-- 'subscribers', 'notificationWithSubscribers_subscribers' - A list of subscribers who are subscribed to this notification.
newNotificationWithSubscribers ::
  -- | 'notification'
  Notification ->
  -- | 'subscribers'
  Prelude.NonEmpty Subscriber ->
  NotificationWithSubscribers
newNotificationWithSubscribers :: Notification -> NonEmpty Subscriber -> NotificationWithSubscribers
newNotificationWithSubscribers
  Notification
pNotification_
  NonEmpty Subscriber
pSubscribers_ =
    NotificationWithSubscribers' :: Notification -> NonEmpty Subscriber -> NotificationWithSubscribers
NotificationWithSubscribers'
      { $sel:notification:NotificationWithSubscribers' :: Notification
notification =
          Notification
pNotification_,
        $sel:subscribers:NotificationWithSubscribers' :: NonEmpty Subscriber
subscribers =
          Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber))
-> Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber))
 -> Tagged (NonEmpty Subscriber) (Identity (NonEmpty Subscriber)))
-> NonEmpty Subscriber -> NonEmpty Subscriber
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Subscriber
pSubscribers_
      }

-- | The notification that is associated with a budget.
notificationWithSubscribers_notification :: Lens.Lens' NotificationWithSubscribers Notification
notificationWithSubscribers_notification :: (Notification -> f Notification)
-> NotificationWithSubscribers -> f NotificationWithSubscribers
notificationWithSubscribers_notification = (NotificationWithSubscribers -> Notification)
-> (NotificationWithSubscribers
    -> Notification -> NotificationWithSubscribers)
-> Lens
     NotificationWithSubscribers
     NotificationWithSubscribers
     Notification
     Notification
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationWithSubscribers' {Notification
notification :: Notification
$sel:notification:NotificationWithSubscribers' :: NotificationWithSubscribers -> Notification
notification} -> Notification
notification) (\s :: NotificationWithSubscribers
s@NotificationWithSubscribers' {} Notification
a -> NotificationWithSubscribers
s {$sel:notification:NotificationWithSubscribers' :: Notification
notification = Notification
a} :: NotificationWithSubscribers)

-- | A list of subscribers who are subscribed to this notification.
notificationWithSubscribers_subscribers :: Lens.Lens' NotificationWithSubscribers (Prelude.NonEmpty Subscriber)
notificationWithSubscribers_subscribers :: (NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> NotificationWithSubscribers -> f NotificationWithSubscribers
notificationWithSubscribers_subscribers = (NotificationWithSubscribers -> NonEmpty Subscriber)
-> (NotificationWithSubscribers
    -> NonEmpty Subscriber -> NotificationWithSubscribers)
-> Lens
     NotificationWithSubscribers
     NotificationWithSubscribers
     (NonEmpty Subscriber)
     (NonEmpty Subscriber)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NotificationWithSubscribers' {NonEmpty Subscriber
subscribers :: NonEmpty Subscriber
$sel:subscribers:NotificationWithSubscribers' :: NotificationWithSubscribers -> NonEmpty Subscriber
subscribers} -> NonEmpty Subscriber
subscribers) (\s :: NotificationWithSubscribers
s@NotificationWithSubscribers' {} NonEmpty Subscriber
a -> NotificationWithSubscribers
s {$sel:subscribers:NotificationWithSubscribers' :: NonEmpty Subscriber
subscribers = NonEmpty Subscriber
a} :: NotificationWithSubscribers) ((NonEmpty Subscriber -> f (NonEmpty Subscriber))
 -> NotificationWithSubscribers -> f NotificationWithSubscribers)
-> ((NonEmpty Subscriber -> f (NonEmpty Subscriber))
    -> NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> (NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> NotificationWithSubscribers
-> f NotificationWithSubscribers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Subscriber -> f (NonEmpty Subscriber))
-> NonEmpty Subscriber -> f (NonEmpty Subscriber)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable NotificationWithSubscribers

instance Prelude.NFData NotificationWithSubscribers

instance Core.ToJSON NotificationWithSubscribers where
  toJSON :: NotificationWithSubscribers -> Value
toJSON NotificationWithSubscribers' {NonEmpty Subscriber
Notification
subscribers :: NonEmpty Subscriber
notification :: Notification
$sel:subscribers:NotificationWithSubscribers' :: NotificationWithSubscribers -> NonEmpty Subscriber
$sel:notification:NotificationWithSubscribers' :: NotificationWithSubscribers -> Notification
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Notification" Text -> Notification -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Notification
notification),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Subscribers" Text -> NonEmpty Subscriber -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Subscriber
subscribers)
          ]
      )