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

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

-- | The SIP address for the contact containing the URI and SIP address type.
--
-- /See:/ 'newSipAddress' smart constructor.
data SipAddress = SipAddress'
  { -- | The URI for the SIP address.
    SipAddress -> Sensitive Text
uri :: Core.Sensitive Prelude.Text,
    -- | The type of the SIP address.
    SipAddress -> Sensitive SipType
type' :: Core.Sensitive SipType
  }
  deriving (SipAddress -> SipAddress -> Bool
(SipAddress -> SipAddress -> Bool)
-> (SipAddress -> SipAddress -> Bool) -> Eq SipAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SipAddress -> SipAddress -> Bool
$c/= :: SipAddress -> SipAddress -> Bool
== :: SipAddress -> SipAddress -> Bool
$c== :: SipAddress -> SipAddress -> Bool
Prelude.Eq, Int -> SipAddress -> ShowS
[SipAddress] -> ShowS
SipAddress -> String
(Int -> SipAddress -> ShowS)
-> (SipAddress -> String)
-> ([SipAddress] -> ShowS)
-> Show SipAddress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SipAddress] -> ShowS
$cshowList :: [SipAddress] -> ShowS
show :: SipAddress -> String
$cshow :: SipAddress -> String
showsPrec :: Int -> SipAddress -> ShowS
$cshowsPrec :: Int -> SipAddress -> ShowS
Prelude.Show, (forall x. SipAddress -> Rep SipAddress x)
-> (forall x. Rep SipAddress x -> SipAddress) -> Generic SipAddress
forall x. Rep SipAddress x -> SipAddress
forall x. SipAddress -> Rep SipAddress x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SipAddress x -> SipAddress
$cfrom :: forall x. SipAddress -> Rep SipAddress x
Prelude.Generic)

-- |
-- Create a value of 'SipAddress' 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:
--
-- 'uri', 'sipAddress_uri' - The URI for the SIP address.
--
-- 'type'', 'sipAddress_type' - The type of the SIP address.
newSipAddress ::
  -- | 'uri'
  Prelude.Text ->
  -- | 'type''
  SipType ->
  SipAddress
newSipAddress :: Text -> SipType -> SipAddress
newSipAddress Text
pUri_ SipType
pType_ =
  SipAddress' :: Sensitive Text -> Sensitive SipType -> SipAddress
SipAddress'
    { $sel:uri:SipAddress' :: Sensitive Text
uri = 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
pUri_,
      $sel:type':SipAddress' :: Sensitive SipType
type' = Tagged SipType (Identity SipType)
-> Tagged (Sensitive SipType) (Identity (Sensitive SipType))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged SipType (Identity SipType)
 -> Tagged (Sensitive SipType) (Identity (Sensitive SipType)))
-> SipType -> Sensitive SipType
forall t b. AReview t b -> b -> t
Lens.# SipType
pType_
    }

-- | The URI for the SIP address.
sipAddress_uri :: Lens.Lens' SipAddress Prelude.Text
sipAddress_uri :: (Text -> f Text) -> SipAddress -> f SipAddress
sipAddress_uri = (SipAddress -> Sensitive Text)
-> (SipAddress -> Sensitive Text -> SipAddress)
-> Lens SipAddress SipAddress (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipAddress' {Sensitive Text
uri :: Sensitive Text
$sel:uri:SipAddress' :: SipAddress -> Sensitive Text
uri} -> Sensitive Text
uri) (\s :: SipAddress
s@SipAddress' {} Sensitive Text
a -> SipAddress
s {$sel:uri:SipAddress' :: Sensitive Text
uri = Sensitive Text
a} :: SipAddress) ((Sensitive Text -> f (Sensitive Text))
 -> SipAddress -> f SipAddress)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> SipAddress
-> f SipAddress
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 SIP address.
sipAddress_type :: Lens.Lens' SipAddress SipType
sipAddress_type :: (SipType -> f SipType) -> SipAddress -> f SipAddress
sipAddress_type = (SipAddress -> Sensitive SipType)
-> (SipAddress -> Sensitive SipType -> SipAddress)
-> Lens
     SipAddress SipAddress (Sensitive SipType) (Sensitive SipType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipAddress' {Sensitive SipType
type' :: Sensitive SipType
$sel:type':SipAddress' :: SipAddress -> Sensitive SipType
type'} -> Sensitive SipType
type') (\s :: SipAddress
s@SipAddress' {} Sensitive SipType
a -> SipAddress
s {$sel:type':SipAddress' :: Sensitive SipType
type' = Sensitive SipType
a} :: SipAddress) ((Sensitive SipType -> f (Sensitive SipType))
 -> SipAddress -> f SipAddress)
-> ((SipType -> f SipType)
    -> Sensitive SipType -> f (Sensitive SipType))
-> (SipType -> f SipType)
-> SipAddress
-> f SipAddress
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (SipType -> f SipType)
-> Sensitive SipType -> f (Sensitive SipType)
forall a. Iso' (Sensitive a) a
Core._Sensitive

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

instance Prelude.Hashable SipAddress

instance Prelude.NFData SipAddress

instance Core.ToJSON SipAddress where
  toJSON :: SipAddress -> Value
toJSON SipAddress' {Sensitive Text
Sensitive SipType
type' :: Sensitive SipType
uri :: Sensitive Text
$sel:type':SipAddress' :: SipAddress -> Sensitive SipType
$sel:uri:SipAddress' :: SipAddress -> 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
"Uri" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
uri),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> Sensitive SipType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive SipType
type')
          ]
      )