{-# 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.CognitoIdentityProvider.Types.AttributeType
-- 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.CognitoIdentityProvider.Types.AttributeType where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies whether the attribute is standard or custom.
--
-- /See:/ 'newAttributeType' smart constructor.
data AttributeType = AttributeType'
  { -- | The value of the attribute.
    AttributeType -> Maybe (Sensitive Text)
value :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The name of the attribute.
    AttributeType -> Text
name :: Prelude.Text
  }
  deriving (AttributeType -> AttributeType -> Bool
(AttributeType -> AttributeType -> Bool)
-> (AttributeType -> AttributeType -> Bool) -> Eq AttributeType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeType -> AttributeType -> Bool
$c/= :: AttributeType -> AttributeType -> Bool
== :: AttributeType -> AttributeType -> Bool
$c== :: AttributeType -> AttributeType -> Bool
Prelude.Eq, Int -> AttributeType -> ShowS
[AttributeType] -> ShowS
AttributeType -> String
(Int -> AttributeType -> ShowS)
-> (AttributeType -> String)
-> ([AttributeType] -> ShowS)
-> Show AttributeType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttributeType] -> ShowS
$cshowList :: [AttributeType] -> ShowS
show :: AttributeType -> String
$cshow :: AttributeType -> String
showsPrec :: Int -> AttributeType -> ShowS
$cshowsPrec :: Int -> AttributeType -> ShowS
Prelude.Show, (forall x. AttributeType -> Rep AttributeType x)
-> (forall x. Rep AttributeType x -> AttributeType)
-> Generic AttributeType
forall x. Rep AttributeType x -> AttributeType
forall x. AttributeType -> Rep AttributeType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeType x -> AttributeType
$cfrom :: forall x. AttributeType -> Rep AttributeType x
Prelude.Generic)

-- |
-- Create a value of 'AttributeType' 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:
--
-- 'value', 'attributeType_value' - The value of the attribute.
--
-- 'name', 'attributeType_name' - The name of the attribute.
newAttributeType ::
  -- | 'name'
  Prelude.Text ->
  AttributeType
newAttributeType :: Text -> AttributeType
newAttributeType Text
pName_ =
  AttributeType' :: Maybe (Sensitive Text) -> Text -> AttributeType
AttributeType'
    { $sel:value:AttributeType' :: Maybe (Sensitive Text)
value = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:name:AttributeType' :: Text
name = Text
pName_
    }

-- | The value of the attribute.
attributeType_value :: Lens.Lens' AttributeType (Prelude.Maybe Prelude.Text)
attributeType_value :: (Maybe Text -> f (Maybe Text)) -> AttributeType -> f AttributeType
attributeType_value = (AttributeType -> Maybe (Sensitive Text))
-> (AttributeType -> Maybe (Sensitive Text) -> AttributeType)
-> Lens
     AttributeType
     AttributeType
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeType' {Maybe (Sensitive Text)
value :: Maybe (Sensitive Text)
$sel:value:AttributeType' :: AttributeType -> Maybe (Sensitive Text)
value} -> Maybe (Sensitive Text)
value) (\s :: AttributeType
s@AttributeType' {} Maybe (Sensitive Text)
a -> AttributeType
s {$sel:value:AttributeType' :: Maybe (Sensitive Text)
value = Maybe (Sensitive Text)
a} :: AttributeType) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> AttributeType -> f AttributeType)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> AttributeType
-> f AttributeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe Text)
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 AnIso (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The name of the attribute.
attributeType_name :: Lens.Lens' AttributeType Prelude.Text
attributeType_name :: (Text -> f Text) -> AttributeType -> f AttributeType
attributeType_name = (AttributeType -> Text)
-> (AttributeType -> Text -> AttributeType)
-> Lens AttributeType AttributeType Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeType' {Text
name :: Text
$sel:name:AttributeType' :: AttributeType -> Text
name} -> Text
name) (\s :: AttributeType
s@AttributeType' {} Text
a -> AttributeType
s {$sel:name:AttributeType' :: Text
name = Text
a} :: AttributeType)

instance Core.FromJSON AttributeType where
  parseJSON :: Value -> Parser AttributeType
parseJSON =
    String
-> (Object -> Parser AttributeType)
-> Value
-> Parser AttributeType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AttributeType"
      ( \Object
x ->
          Maybe (Sensitive Text) -> Text -> AttributeType
AttributeType'
            (Maybe (Sensitive Text) -> Text -> AttributeType)
-> Parser (Maybe (Sensitive Text))
-> Parser (Text -> AttributeType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Sensitive Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Value") Parser (Text -> AttributeType)
-> Parser Text -> Parser AttributeType
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
      )

instance Prelude.Hashable AttributeType

instance Prelude.NFData AttributeType

instance Core.ToJSON AttributeType where
  toJSON :: AttributeType -> Value
toJSON AttributeType' {Maybe (Sensitive Text)
Text
name :: Text
value :: Maybe (Sensitive Text)
$sel:name:AttributeType' :: AttributeType -> Text
$sel:value:AttributeType' :: AttributeType -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Value" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Sensitive Text -> Pair) -> Maybe (Sensitive Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
value,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )