{-# 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.IdentityStore.Types.Email
-- 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.IdentityStore.Types.Email 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

-- | The email address associated with the user.
--
-- /See:/ 'newEmail' smart constructor.
data Email = Email'
  { -- | A Boolean value representing whether this is the primary email address
    -- for the associated resource.
    Email -> Maybe (Sensitive Bool)
primary :: Prelude.Maybe (Data.Sensitive Prelude.Bool),
    -- | A string representing the type of address. For example, \"Work.\"
    Email -> Maybe (Sensitive Text)
type' :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | A string containing an email address. For example,
    -- \"johndoe\@amazon.com.\"
    Email -> Maybe (Sensitive Text)
value :: Prelude.Maybe (Data.Sensitive Prelude.Text)
  }
  deriving (Email -> Email -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Email -> Email -> Bool
$c/= :: Email -> Email -> Bool
== :: Email -> Email -> Bool
$c== :: Email -> Email -> Bool
Prelude.Eq, Int -> Email -> ShowS
[Email] -> ShowS
Email -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Email] -> ShowS
$cshowList :: [Email] -> ShowS
show :: Email -> String
$cshow :: Email -> String
showsPrec :: Int -> Email -> ShowS
$cshowsPrec :: Int -> Email -> ShowS
Prelude.Show, forall x. Rep Email x -> Email
forall x. Email -> Rep Email x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Email x -> Email
$cfrom :: forall x. Email -> Rep Email x
Prelude.Generic)

-- |
-- Create a value of 'Email' 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:
--
-- 'primary', 'email_primary' - A Boolean value representing whether this is the primary email address
-- for the associated resource.
--
-- 'type'', 'email_type' - A string representing the type of address. For example, \"Work.\"
--
-- 'value', 'email_value' - A string containing an email address. For example,
-- \"johndoe\@amazon.com.\"
newEmail ::
  Email
newEmail :: Email
newEmail =
  Email'
    { $sel:primary:Email' :: Maybe (Sensitive Bool)
primary = forall a. Maybe a
Prelude.Nothing,
      $sel:type':Email' :: Maybe (Sensitive Text)
type' = forall a. Maybe a
Prelude.Nothing,
      $sel:value:Email' :: Maybe (Sensitive Text)
value = forall a. Maybe a
Prelude.Nothing
    }

-- | A Boolean value representing whether this is the primary email address
-- for the associated resource.
email_primary :: Lens.Lens' Email (Prelude.Maybe Prelude.Bool)
email_primary :: Lens' Email (Maybe Bool)
email_primary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Email' {Maybe (Sensitive Bool)
primary :: Maybe (Sensitive Bool)
$sel:primary:Email' :: Email -> Maybe (Sensitive Bool)
primary} -> Maybe (Sensitive Bool)
primary) (\s :: Email
s@Email' {} Maybe (Sensitive Bool)
a -> Email
s {$sel:primary:Email' :: Maybe (Sensitive Bool)
primary = Maybe (Sensitive Bool)
a} :: Email) 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 a. Iso' (Sensitive a) a
Data._Sensitive

-- | A string representing the type of address. For example, \"Work.\"
email_type :: Lens.Lens' Email (Prelude.Maybe Prelude.Text)
email_type :: Lens' Email (Maybe Text)
email_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Email' {Maybe (Sensitive Text)
type' :: Maybe (Sensitive Text)
$sel:type':Email' :: Email -> Maybe (Sensitive Text)
type'} -> Maybe (Sensitive Text)
type') (\s :: Email
s@Email' {} Maybe (Sensitive Text)
a -> Email
s {$sel:type':Email' :: Maybe (Sensitive Text)
type' = Maybe (Sensitive Text)
a} :: Email) 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 a. Iso' (Sensitive a) a
Data._Sensitive

-- | A string containing an email address. For example,
-- \"johndoe\@amazon.com.\"
email_value :: Lens.Lens' Email (Prelude.Maybe Prelude.Text)
email_value :: Lens' Email (Maybe Text)
email_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Email' {Maybe (Sensitive Text)
value :: Maybe (Sensitive Text)
$sel:value:Email' :: Email -> Maybe (Sensitive Text)
value} -> Maybe (Sensitive Text)
value) (\s :: Email
s@Email' {} Maybe (Sensitive Text)
a -> Email
s {$sel:value:Email' :: Maybe (Sensitive Text)
value = Maybe (Sensitive Text)
a} :: Email) 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 a. Iso' (Sensitive a) a
Data._Sensitive

instance Data.FromJSON Email where
  parseJSON :: Value -> Parser Email
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Email"
      ( \Object
x ->
          Maybe (Sensitive Bool)
-> Maybe (Sensitive Text) -> Maybe (Sensitive Text) -> Email
Email'
            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
"Primary")
            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")
            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
"Value")
      )

instance Prelude.Hashable Email where
  hashWithSalt :: Int -> Email -> Int
hashWithSalt Int
_salt Email' {Maybe (Sensitive Bool)
Maybe (Sensitive Text)
value :: Maybe (Sensitive Text)
type' :: Maybe (Sensitive Text)
primary :: Maybe (Sensitive Bool)
$sel:value:Email' :: Email -> Maybe (Sensitive Text)
$sel:type':Email' :: Email -> Maybe (Sensitive Text)
$sel:primary:Email' :: Email -> Maybe (Sensitive Bool)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Bool)
primary
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
value

instance Prelude.NFData Email where
  rnf :: Email -> ()
rnf Email' {Maybe (Sensitive Bool)
Maybe (Sensitive Text)
value :: Maybe (Sensitive Text)
type' :: Maybe (Sensitive Text)
primary :: Maybe (Sensitive Bool)
$sel:value:Email' :: Email -> Maybe (Sensitive Text)
$sel:type':Email' :: Email -> Maybe (Sensitive Text)
$sel:primary:Email' :: Email -> Maybe (Sensitive Bool)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Bool)
primary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
value

instance Data.ToJSON Email where
  toJSON :: Email -> Value
toJSON Email' {Maybe (Sensitive Bool)
Maybe (Sensitive Text)
value :: Maybe (Sensitive Text)
type' :: Maybe (Sensitive Text)
primary :: Maybe (Sensitive Bool)
$sel:value:Email' :: Email -> Maybe (Sensitive Text)
$sel:type':Email' :: Email -> Maybe (Sensitive Text)
$sel:primary:Email' :: Email -> Maybe (Sensitive Bool)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Primary" 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 (Sensitive Bool)
primary,
            (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 (Sensitive Text)
type',
            (Key
"Value" 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 (Sensitive Text)
value
          ]
      )