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

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

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

-- | 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 :: Lens' Subscriber (Maybe Text)
subscriber_address = 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)

-- | Indicates if the subscriber accepts the notifications.
subscriber_status :: Lens.Lens' Subscriber (Prelude.Maybe SubscriberStatus)
subscriber_status :: Lens' Subscriber (Maybe SubscriberStatus)
subscriber_status = 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 notification delivery channel.
subscriber_type :: Lens.Lens' Subscriber (Prelude.Maybe SubscriberType)
subscriber_type :: Lens' Subscriber (Maybe SubscriberType)
subscriber_type = 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 Data.FromJSON Subscriber where
  parseJSON :: Value -> Parser Subscriber
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Subscriber"
      ( \Object
x ->
          Maybe Text
-> Maybe SubscriberStatus -> Maybe SubscriberType -> Subscriber
Subscriber'
            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
"Address")
            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
"Status")
            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
"Type")
      )

instance Prelude.Hashable Subscriber where
  hashWithSalt :: Int -> Subscriber -> Int
hashWithSalt Int
_salt Subscriber' {Maybe Text
Maybe SubscriberStatus
Maybe SubscriberType
type' :: Maybe SubscriberType
status :: Maybe SubscriberStatus
address :: Maybe Text
$sel:type':Subscriber' :: Subscriber -> Maybe SubscriberType
$sel:status:Subscriber' :: Subscriber -> Maybe SubscriberStatus
$sel:address:Subscriber' :: Subscriber -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
address
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SubscriberStatus
status
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SubscriberType
type'

instance Prelude.NFData Subscriber where
  rnf :: Subscriber -> ()
rnf Subscriber' {Maybe Text
Maybe SubscriberStatus
Maybe SubscriberType
type' :: Maybe SubscriberType
status :: Maybe SubscriberStatus
address :: Maybe Text
$sel:type':Subscriber' :: Subscriber -> Maybe SubscriberType
$sel:status:Subscriber' :: Subscriber -> Maybe SubscriberStatus
$sel:address:Subscriber' :: Subscriber -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
address
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SubscriberStatus
status
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SubscriberType
type'

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