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

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.SubscriberStatus
import Amazonka.CostExplorer.Types.SubscriberType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The recipient of @AnomalySubscription@ notifications.
--
-- /See:/ 'newSubscriber' smart constructor.
data Subscriber = Subscriber'
  { -- | Indicates if the subscriber accepts the notifications.
    Subscriber -> Maybe SubscriberStatus
status :: Prelude.Maybe SubscriberStatus,
    -- | The email address or SNS Amazon Resource Name (ARN). This depends on the
    -- @Type@.
    Subscriber -> Maybe Text
address :: Prelude.Maybe Prelude.Text,
    -- | The notification delivery channel.
    Subscriber -> Maybe SubscriberType
type' :: Prelude.Maybe SubscriberType
  }
  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, ReadPrec [Subscriber]
ReadPrec Subscriber
Int -> ReadS Subscriber
ReadS [Subscriber]
(Int -> ReadS Subscriber)
-> ReadS [Subscriber]
-> ReadPrec Subscriber
-> ReadPrec [Subscriber]
-> Read Subscriber
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Subscriber]
$creadListPrec :: ReadPrec [Subscriber]
readPrec :: ReadPrec Subscriber
$creadPrec :: ReadPrec Subscriber
readList :: ReadS [Subscriber]
$creadList :: ReadS [Subscriber]
readsPrec :: Int -> ReadS Subscriber
$creadsPrec :: Int -> ReadS Subscriber
Prelude.Read, 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:
--
-- 'status', 'subscriber_status' - Indicates if the subscriber accepts the notifications.
--
-- 'address', 'subscriber_address' - The email address or SNS Amazon Resource Name (ARN). This depends on the
-- @Type@.
--
-- 'type'', 'subscriber_type' - The notification delivery channel.
newSubscriber ::
  Subscriber
newSubscriber :: Subscriber
newSubscriber =
  Subscriber' :: Maybe SubscriberStatus
-> Maybe Text -> Maybe SubscriberType -> Subscriber
Subscriber'
    { $sel:status:Subscriber' :: Maybe SubscriberStatus
status = Maybe SubscriberStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:address:Subscriber' :: Maybe Text
address = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Subscriber' :: Maybe SubscriberType
type' = Maybe SubscriberType
forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates if the subscriber accepts the notifications.
subscriber_status :: Lens.Lens' Subscriber (Prelude.Maybe SubscriberStatus)
subscriber_status :: (Maybe SubscriberStatus -> f (Maybe SubscriberStatus))
-> Subscriber -> f Subscriber
subscriber_status = (Subscriber -> Maybe SubscriberStatus)
-> (Subscriber -> Maybe SubscriberStatus -> Subscriber)
-> Lens
     Subscriber
     Subscriber
     (Maybe SubscriberStatus)
     (Maybe SubscriberStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscriber' {Maybe SubscriberStatus
status :: Maybe SubscriberStatus
$sel:status:Subscriber' :: Subscriber -> Maybe SubscriberStatus
status} -> Maybe SubscriberStatus
status) (\s :: Subscriber
s@Subscriber' {} Maybe SubscriberStatus
a -> Subscriber
s {$sel:status:Subscriber' :: Maybe SubscriberStatus
status = Maybe SubscriberStatus
a} :: Subscriber)

-- | The email address or SNS Amazon Resource Name (ARN). This depends on the
-- @Type@.
subscriber_address :: Lens.Lens' Subscriber (Prelude.Maybe Prelude.Text)
subscriber_address :: (Maybe Text -> f (Maybe Text)) -> Subscriber -> f Subscriber
subscriber_address = (Subscriber -> Maybe Text)
-> (Subscriber -> Maybe Text -> Subscriber)
-> Lens Subscriber Subscriber (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscriber' {Maybe Text
address :: Maybe Text
$sel:address:Subscriber' :: Subscriber -> Maybe Text
address} -> Maybe Text
address) (\s :: Subscriber
s@Subscriber' {} Maybe Text
a -> Subscriber
s {$sel:address:Subscriber' :: Maybe Text
address = Maybe Text
a} :: Subscriber)

-- | The notification delivery channel.
subscriber_type :: Lens.Lens' Subscriber (Prelude.Maybe SubscriberType)
subscriber_type :: (Maybe SubscriberType -> f (Maybe SubscriberType))
-> Subscriber -> f Subscriber
subscriber_type = (Subscriber -> Maybe SubscriberType)
-> (Subscriber -> Maybe SubscriberType -> Subscriber)
-> Lens
     Subscriber Subscriber (Maybe SubscriberType) (Maybe SubscriberType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscriber' {Maybe SubscriberType
type' :: Maybe SubscriberType
$sel:type':Subscriber' :: Subscriber -> Maybe SubscriberType
type'} -> Maybe SubscriberType
type') (\s :: Subscriber
s@Subscriber' {} Maybe SubscriberType
a -> Subscriber
s {$sel:type':Subscriber' :: Maybe SubscriberType
type' = Maybe SubscriberType
a} :: Subscriber)

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 ->
          Maybe SubscriberStatus
-> Maybe Text -> Maybe SubscriberType -> Subscriber
Subscriber'
            (Maybe SubscriberStatus
 -> Maybe Text -> Maybe SubscriberType -> Subscriber)
-> Parser (Maybe SubscriberStatus)
-> Parser (Maybe Text -> Maybe SubscriberType -> Subscriber)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe SubscriberStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Status")
            Parser (Maybe Text -> Maybe SubscriberType -> Subscriber)
-> Parser (Maybe Text)
-> Parser (Maybe SubscriberType -> Subscriber)
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
"Address")
            Parser (Maybe SubscriberType -> Subscriber)
-> Parser (Maybe SubscriberType) -> Parser Subscriber
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SubscriberType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
      )

instance Prelude.Hashable Subscriber

instance Prelude.NFData Subscriber

instance Core.ToJSON Subscriber where
  toJSON :: Subscriber -> Value
toJSON Subscriber' {Maybe Text
Maybe SubscriberStatus
Maybe SubscriberType
type' :: Maybe SubscriberType
address :: Maybe Text
status :: Maybe SubscriberStatus
$sel:type':Subscriber' :: Subscriber -> Maybe SubscriberType
$sel:address:Subscriber' :: Subscriber -> Maybe Text
$sel:status:Subscriber' :: Subscriber -> Maybe SubscriberStatus
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Status" Text -> SubscriberStatus -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SubscriberStatus -> Pair) -> Maybe SubscriberStatus -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SubscriberStatus
status,
            (Text
"Address" 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
address,
            (Text
"Type" Text -> SubscriberType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SubscriberType -> Pair) -> Maybe SubscriberType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SubscriberType
type'
          ]
      )