{-# 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.ExternalId
-- 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.ExternalId 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 identifier issued to this resource by an external identity provider.
--
-- /See:/ 'newExternalId' smart constructor.
data ExternalId = ExternalId'
  { -- | The issuer for an external identifier.
    ExternalId -> Sensitive Text
issuer :: Data.Sensitive Prelude.Text,
    -- | The identifier issued to this resource by an external identity provider.
    ExternalId -> Sensitive Text
id :: Data.Sensitive Prelude.Text
  }
  deriving (ExternalId -> ExternalId -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExternalId -> ExternalId -> Bool
$c/= :: ExternalId -> ExternalId -> Bool
== :: ExternalId -> ExternalId -> Bool
$c== :: ExternalId -> ExternalId -> Bool
Prelude.Eq, Int -> ExternalId -> ShowS
[ExternalId] -> ShowS
ExternalId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExternalId] -> ShowS
$cshowList :: [ExternalId] -> ShowS
show :: ExternalId -> String
$cshow :: ExternalId -> String
showsPrec :: Int -> ExternalId -> ShowS
$cshowsPrec :: Int -> ExternalId -> ShowS
Prelude.Show, forall x. Rep ExternalId x -> ExternalId
forall x. ExternalId -> Rep ExternalId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExternalId x -> ExternalId
$cfrom :: forall x. ExternalId -> Rep ExternalId x
Prelude.Generic)

-- |
-- Create a value of 'ExternalId' 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:
--
-- 'issuer', 'externalId_issuer' - The issuer for an external identifier.
--
-- 'id', 'externalId_id' - The identifier issued to this resource by an external identity provider.
newExternalId ::
  -- | 'issuer'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  ExternalId
newExternalId :: Text -> Text -> ExternalId
newExternalId Text
pIssuer_ Text
pId_ =
  ExternalId'
    { $sel:issuer:ExternalId' :: Sensitive Text
issuer =
        forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pIssuer_,
      $sel:id:ExternalId' :: Sensitive Text
id = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pId_
    }

-- | The issuer for an external identifier.
externalId_issuer :: Lens.Lens' ExternalId Prelude.Text
externalId_issuer :: Lens' ExternalId Text
externalId_issuer = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExternalId' {Sensitive Text
issuer :: Sensitive Text
$sel:issuer:ExternalId' :: ExternalId -> Sensitive Text
issuer} -> Sensitive Text
issuer) (\s :: ExternalId
s@ExternalId' {} Sensitive Text
a -> ExternalId
s {$sel:issuer:ExternalId' :: Sensitive Text
issuer = Sensitive Text
a} :: ExternalId) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The identifier issued to this resource by an external identity provider.
externalId_id :: Lens.Lens' ExternalId Prelude.Text
externalId_id :: Lens' ExternalId Text
externalId_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExternalId' {Sensitive Text
id :: Sensitive Text
$sel:id:ExternalId' :: ExternalId -> Sensitive Text
id} -> Sensitive Text
id) (\s :: ExternalId
s@ExternalId' {} Sensitive Text
a -> ExternalId
s {$sel:id:ExternalId' :: Sensitive Text
id = Sensitive Text
a} :: ExternalId) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Data.FromJSON ExternalId where
  parseJSON :: Value -> Parser ExternalId
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ExternalId"
      ( \Object
x ->
          Sensitive Text -> Sensitive Text -> ExternalId
ExternalId'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Issuer")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Id")
      )

instance Prelude.Hashable ExternalId where
  hashWithSalt :: Int -> ExternalId -> Int
hashWithSalt Int
_salt ExternalId' {Sensitive Text
id :: Sensitive Text
issuer :: Sensitive Text
$sel:id:ExternalId' :: ExternalId -> Sensitive Text
$sel:issuer:ExternalId' :: ExternalId -> Sensitive Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
issuer
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
id

instance Prelude.NFData ExternalId where
  rnf :: ExternalId -> ()
rnf ExternalId' {Sensitive Text
id :: Sensitive Text
issuer :: Sensitive Text
$sel:id:ExternalId' :: ExternalId -> Sensitive Text
$sel:issuer:ExternalId' :: ExternalId -> Sensitive Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
issuer seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
id

instance Data.ToJSON ExternalId where
  toJSON :: ExternalId -> Value
toJSON ExternalId' {Sensitive Text
id :: Sensitive Text
issuer :: Sensitive Text
$sel:id:ExternalId' :: ExternalId -> Sensitive Text
$sel:issuer:ExternalId' :: ExternalId -> Sensitive Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Issuer" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
issuer),
            forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
id)
          ]
      )