{-# 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.Subscriber
-- 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.Subscriber where

import Amazonka.Budgets.Types.SubscriptionType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The subscriber to a budget notification. The subscriber consists of a
-- subscription type and either an Amazon SNS topic or an email address.
--
-- For example, an email subscriber would have the following parameters:
--
-- -   A @subscriptionType@ of @EMAIL@
--
-- -   An @address@ of @example\@example.com@
--
-- /See:/ 'newSubscriber' smart constructor.
data Subscriber = Subscriber'
  { -- | The type of notification that AWS sends to a subscriber.
    Subscriber -> SubscriptionType
subscriptionType :: SubscriptionType,
    -- | The address that AWS sends budget notifications to, either an SNS topic
    -- or an email.
    --
    -- When you create a subscriber, the value of @Address@ can\'t contain line
    -- breaks.
    Subscriber -> Sensitive Text
address :: Core.Sensitive Prelude.Text
  }
  deriving (Subscriber -> Subscriber -> Bool
(Subscriber -> Subscriber -> Bool)
-> (Subscriber -> Subscriber -> Bool) -> Eq Subscriber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Subscriber -> Subscriber -> Bool
$c/= :: Subscriber -> Subscriber -> Bool
== :: Subscriber -> Subscriber -> Bool
$c== :: Subscriber -> Subscriber -> Bool
Prelude.Eq, Int -> Subscriber -> ShowS
[Subscriber] -> ShowS
Subscriber -> String
(Int -> Subscriber -> ShowS)
-> (Subscriber -> String)
-> ([Subscriber] -> ShowS)
-> Show Subscriber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Subscriber] -> ShowS
$cshowList :: [Subscriber] -> ShowS
show :: Subscriber -> String
$cshow :: Subscriber -> String
showsPrec :: Int -> Subscriber -> ShowS
$cshowsPrec :: Int -> Subscriber -> ShowS
Prelude.Show, (forall x. Subscriber -> Rep Subscriber x)
-> (forall x. Rep Subscriber x -> Subscriber) -> Generic Subscriber
forall x. Rep Subscriber x -> Subscriber
forall x. Subscriber -> Rep Subscriber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Subscriber x -> Subscriber
$cfrom :: forall x. Subscriber -> Rep Subscriber x
Prelude.Generic)

-- |
-- Create a value of 'Subscriber' 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:
--
-- 'subscriptionType', 'subscriber_subscriptionType' - The type of notification that AWS sends to a subscriber.
--
-- 'address', 'subscriber_address' - The address that AWS sends budget notifications to, either an SNS topic
-- or an email.
--
-- When you create a subscriber, the value of @Address@ can\'t contain line
-- breaks.
newSubscriber ::
  -- | 'subscriptionType'
  SubscriptionType ->
  -- | 'address'
  Prelude.Text ->
  Subscriber
newSubscriber :: SubscriptionType -> Text -> Subscriber
newSubscriber SubscriptionType
pSubscriptionType_ Text
pAddress_ =
  Subscriber' :: SubscriptionType -> Sensitive Text -> Subscriber
Subscriber'
    { $sel:subscriptionType:Subscriber' :: SubscriptionType
subscriptionType = SubscriptionType
pSubscriptionType_,
      $sel:address:Subscriber' :: Sensitive Text
address = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pAddress_
    }

-- | The type of notification that AWS sends to a subscriber.
subscriber_subscriptionType :: Lens.Lens' Subscriber SubscriptionType
subscriber_subscriptionType :: (SubscriptionType -> f SubscriptionType)
-> Subscriber -> f Subscriber
subscriber_subscriptionType = (Subscriber -> SubscriptionType)
-> (Subscriber -> SubscriptionType -> Subscriber)
-> Lens Subscriber Subscriber SubscriptionType SubscriptionType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscriber' {SubscriptionType
subscriptionType :: SubscriptionType
$sel:subscriptionType:Subscriber' :: Subscriber -> SubscriptionType
subscriptionType} -> SubscriptionType
subscriptionType) (\s :: Subscriber
s@Subscriber' {} SubscriptionType
a -> Subscriber
s {$sel:subscriptionType:Subscriber' :: SubscriptionType
subscriptionType = SubscriptionType
a} :: Subscriber)

-- | The address that AWS sends budget notifications to, either an SNS topic
-- or an email.
--
-- When you create a subscriber, the value of @Address@ can\'t contain line
-- breaks.
subscriber_address :: Lens.Lens' Subscriber Prelude.Text
subscriber_address :: (Text -> f Text) -> Subscriber -> f Subscriber
subscriber_address = (Subscriber -> Sensitive Text)
-> (Subscriber -> Sensitive Text -> Subscriber)
-> Lens Subscriber Subscriber (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscriber' {Sensitive Text
address :: Sensitive Text
$sel:address:Subscriber' :: Subscriber -> Sensitive Text
address} -> Sensitive Text
address) (\s :: Subscriber
s@Subscriber' {} Sensitive Text
a -> Subscriber
s {$sel:address:Subscriber' :: Sensitive Text
address = Sensitive Text
a} :: Subscriber) ((Sensitive Text -> f (Sensitive Text))
 -> Subscriber -> f Subscriber)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> Subscriber
-> f Subscriber
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.FromJSON Subscriber where
  parseJSON :: Value -> Parser Subscriber
parseJSON =
    String
-> (Object -> Parser Subscriber) -> Value -> Parser Subscriber
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Subscriber"
      ( \Object
x ->
          SubscriptionType -> Sensitive Text -> Subscriber
Subscriber'
            (SubscriptionType -> Sensitive Text -> Subscriber)
-> Parser SubscriptionType -> Parser (Sensitive Text -> Subscriber)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser SubscriptionType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SubscriptionType")
            Parser (Sensitive Text -> Subscriber)
-> Parser (Sensitive Text) -> Parser Subscriber
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Sensitive Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Address")
      )

instance Prelude.Hashable Subscriber

instance Prelude.NFData Subscriber

instance Core.ToJSON Subscriber where
  toJSON :: Subscriber -> Value
toJSON Subscriber' {Sensitive Text
SubscriptionType
address :: Sensitive Text
subscriptionType :: SubscriptionType
$sel:address:Subscriber' :: Subscriber -> Sensitive Text
$sel:subscriptionType:Subscriber' :: Subscriber -> SubscriptionType
..} =
    [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
"SubscriptionType" Text -> SubscriptionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SubscriptionType
subscriptionType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Address" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
address)
          ]
      )