{-# 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.AlexaBusiness.Types.PhoneNumber
-- 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.AlexaBusiness.Types.PhoneNumber where

import Amazonka.AlexaBusiness.Types.PhoneNumberType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The phone number for the contact containing the raw number and phone
-- number type.
--
-- /See:/ 'newPhoneNumber' smart constructor.
data PhoneNumber = PhoneNumber'
  { -- | The raw value of the phone number.
    PhoneNumber -> Sensitive Text
number :: Core.Sensitive Prelude.Text,
    -- | The type of the phone number.
    PhoneNumber -> Sensitive PhoneNumberType
type' :: Core.Sensitive PhoneNumberType
  }
  deriving (PhoneNumber -> PhoneNumber -> Bool
(PhoneNumber -> PhoneNumber -> Bool)
-> (PhoneNumber -> PhoneNumber -> Bool) -> Eq PhoneNumber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PhoneNumber -> PhoneNumber -> Bool
$c/= :: PhoneNumber -> PhoneNumber -> Bool
== :: PhoneNumber -> PhoneNumber -> Bool
$c== :: PhoneNumber -> PhoneNumber -> Bool
Prelude.Eq, Int -> PhoneNumber -> ShowS
[PhoneNumber] -> ShowS
PhoneNumber -> String
(Int -> PhoneNumber -> ShowS)
-> (PhoneNumber -> String)
-> ([PhoneNumber] -> ShowS)
-> Show PhoneNumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PhoneNumber] -> ShowS
$cshowList :: [PhoneNumber] -> ShowS
show :: PhoneNumber -> String
$cshow :: PhoneNumber -> String
showsPrec :: Int -> PhoneNumber -> ShowS
$cshowsPrec :: Int -> PhoneNumber -> ShowS
Prelude.Show, (forall x. PhoneNumber -> Rep PhoneNumber x)
-> (forall x. Rep PhoneNumber x -> PhoneNumber)
-> Generic PhoneNumber
forall x. Rep PhoneNumber x -> PhoneNumber
forall x. PhoneNumber -> Rep PhoneNumber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PhoneNumber x -> PhoneNumber
$cfrom :: forall x. PhoneNumber -> Rep PhoneNumber x
Prelude.Generic)

-- |
-- Create a value of 'PhoneNumber' 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:
--
-- 'number', 'phoneNumber_number' - The raw value of the phone number.
--
-- 'type'', 'phoneNumber_type' - The type of the phone number.
newPhoneNumber ::
  -- | 'number'
  Prelude.Text ->
  -- | 'type''
  PhoneNumberType ->
  PhoneNumber
newPhoneNumber :: Text -> PhoneNumberType -> PhoneNumber
newPhoneNumber Text
pNumber_ PhoneNumberType
pType_ =
  PhoneNumber' :: Sensitive Text -> Sensitive PhoneNumberType -> PhoneNumber
PhoneNumber'
    { $sel:number:PhoneNumber' :: Sensitive Text
number =
        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
pNumber_,
      $sel:type':PhoneNumber' :: Sensitive PhoneNumberType
type' = Tagged PhoneNumberType (Identity PhoneNumberType)
-> Tagged
     (Sensitive PhoneNumberType) (Identity (Sensitive PhoneNumberType))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged PhoneNumberType (Identity PhoneNumberType)
 -> Tagged
      (Sensitive PhoneNumberType) (Identity (Sensitive PhoneNumberType)))
-> PhoneNumberType -> Sensitive PhoneNumberType
forall t b. AReview t b -> b -> t
Lens.# PhoneNumberType
pType_
    }

-- | The raw value of the phone number.
phoneNumber_number :: Lens.Lens' PhoneNumber Prelude.Text
phoneNumber_number :: (Text -> f Text) -> PhoneNumber -> f PhoneNumber
phoneNumber_number = (PhoneNumber -> Sensitive Text)
-> (PhoneNumber -> Sensitive Text -> PhoneNumber)
-> Lens PhoneNumber PhoneNumber (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PhoneNumber' {Sensitive Text
number :: Sensitive Text
$sel:number:PhoneNumber' :: PhoneNumber -> Sensitive Text
number} -> Sensitive Text
number) (\s :: PhoneNumber
s@PhoneNumber' {} Sensitive Text
a -> PhoneNumber
s {$sel:number:PhoneNumber' :: Sensitive Text
number = Sensitive Text
a} :: PhoneNumber) ((Sensitive Text -> f (Sensitive Text))
 -> PhoneNumber -> f PhoneNumber)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> PhoneNumber
-> f PhoneNumber
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

-- | The type of the phone number.
phoneNumber_type :: Lens.Lens' PhoneNumber PhoneNumberType
phoneNumber_type :: (PhoneNumberType -> f PhoneNumberType)
-> PhoneNumber -> f PhoneNumber
phoneNumber_type = (PhoneNumber -> Sensitive PhoneNumberType)
-> (PhoneNumber -> Sensitive PhoneNumberType -> PhoneNumber)
-> Lens
     PhoneNumber
     PhoneNumber
     (Sensitive PhoneNumberType)
     (Sensitive PhoneNumberType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PhoneNumber' {Sensitive PhoneNumberType
type' :: Sensitive PhoneNumberType
$sel:type':PhoneNumber' :: PhoneNumber -> Sensitive PhoneNumberType
type'} -> Sensitive PhoneNumberType
type') (\s :: PhoneNumber
s@PhoneNumber' {} Sensitive PhoneNumberType
a -> PhoneNumber
s {$sel:type':PhoneNumber' :: Sensitive PhoneNumberType
type' = Sensitive PhoneNumberType
a} :: PhoneNumber) ((Sensitive PhoneNumberType -> f (Sensitive PhoneNumberType))
 -> PhoneNumber -> f PhoneNumber)
-> ((PhoneNumberType -> f PhoneNumberType)
    -> Sensitive PhoneNumberType -> f (Sensitive PhoneNumberType))
-> (PhoneNumberType -> f PhoneNumberType)
-> PhoneNumber
-> f PhoneNumber
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (PhoneNumberType -> f PhoneNumberType)
-> Sensitive PhoneNumberType -> f (Sensitive PhoneNumberType)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.FromJSON PhoneNumber where
  parseJSON :: Value -> Parser PhoneNumber
parseJSON =
    String
-> (Object -> Parser PhoneNumber) -> Value -> Parser PhoneNumber
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PhoneNumber"
      ( \Object
x ->
          Sensitive Text -> Sensitive PhoneNumberType -> PhoneNumber
PhoneNumber'
            (Sensitive Text -> Sensitive PhoneNumberType -> PhoneNumber)
-> Parser (Sensitive Text)
-> Parser (Sensitive PhoneNumberType -> PhoneNumber)
forall (f :: * -> *) a b. Functor 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
"Number") Parser (Sensitive PhoneNumberType -> PhoneNumber)
-> Parser (Sensitive PhoneNumberType) -> Parser PhoneNumber
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Sensitive PhoneNumberType)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
      )

instance Prelude.Hashable PhoneNumber

instance Prelude.NFData PhoneNumber

instance Core.ToJSON PhoneNumber where
  toJSON :: PhoneNumber -> Value
toJSON PhoneNumber' {Sensitive Text
Sensitive PhoneNumberType
type' :: Sensitive PhoneNumberType
number :: Sensitive Text
$sel:type':PhoneNumber' :: PhoneNumber -> Sensitive PhoneNumberType
$sel:number:PhoneNumber' :: PhoneNumber -> Sensitive Text
..} =
    [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
"Number" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
number),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> Sensitive PhoneNumberType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive PhoneNumberType
type')
          ]
      )