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

import Amazonka.CognitoIdentityProvider.Types.RecoveryOptionNameType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A map containing a priority as a key, and recovery method name as a
-- value.
--
-- /See:/ 'newRecoveryOptionType' smart constructor.
data RecoveryOptionType = RecoveryOptionType'
  { -- | A positive integer specifying priority of a method with 1 being the
    -- highest priority.
    RecoveryOptionType -> Natural
priority :: Prelude.Natural,
    -- | Specifies the recovery method for a user.
    RecoveryOptionType -> RecoveryOptionNameType
name :: RecoveryOptionNameType
  }
  deriving (RecoveryOptionType -> RecoveryOptionType -> Bool
(RecoveryOptionType -> RecoveryOptionType -> Bool)
-> (RecoveryOptionType -> RecoveryOptionType -> Bool)
-> Eq RecoveryOptionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecoveryOptionType -> RecoveryOptionType -> Bool
$c/= :: RecoveryOptionType -> RecoveryOptionType -> Bool
== :: RecoveryOptionType -> RecoveryOptionType -> Bool
$c== :: RecoveryOptionType -> RecoveryOptionType -> Bool
Prelude.Eq, ReadPrec [RecoveryOptionType]
ReadPrec RecoveryOptionType
Int -> ReadS RecoveryOptionType
ReadS [RecoveryOptionType]
(Int -> ReadS RecoveryOptionType)
-> ReadS [RecoveryOptionType]
-> ReadPrec RecoveryOptionType
-> ReadPrec [RecoveryOptionType]
-> Read RecoveryOptionType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecoveryOptionType]
$creadListPrec :: ReadPrec [RecoveryOptionType]
readPrec :: ReadPrec RecoveryOptionType
$creadPrec :: ReadPrec RecoveryOptionType
readList :: ReadS [RecoveryOptionType]
$creadList :: ReadS [RecoveryOptionType]
readsPrec :: Int -> ReadS RecoveryOptionType
$creadsPrec :: Int -> ReadS RecoveryOptionType
Prelude.Read, Int -> RecoveryOptionType -> ShowS
[RecoveryOptionType] -> ShowS
RecoveryOptionType -> String
(Int -> RecoveryOptionType -> ShowS)
-> (RecoveryOptionType -> String)
-> ([RecoveryOptionType] -> ShowS)
-> Show RecoveryOptionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecoveryOptionType] -> ShowS
$cshowList :: [RecoveryOptionType] -> ShowS
show :: RecoveryOptionType -> String
$cshow :: RecoveryOptionType -> String
showsPrec :: Int -> RecoveryOptionType -> ShowS
$cshowsPrec :: Int -> RecoveryOptionType -> ShowS
Prelude.Show, (forall x. RecoveryOptionType -> Rep RecoveryOptionType x)
-> (forall x. Rep RecoveryOptionType x -> RecoveryOptionType)
-> Generic RecoveryOptionType
forall x. Rep RecoveryOptionType x -> RecoveryOptionType
forall x. RecoveryOptionType -> Rep RecoveryOptionType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecoveryOptionType x -> RecoveryOptionType
$cfrom :: forall x. RecoveryOptionType -> Rep RecoveryOptionType x
Prelude.Generic)

-- |
-- Create a value of 'RecoveryOptionType' 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:
--
-- 'priority', 'recoveryOptionType_priority' - A positive integer specifying priority of a method with 1 being the
-- highest priority.
--
-- 'name', 'recoveryOptionType_name' - Specifies the recovery method for a user.
newRecoveryOptionType ::
  -- | 'priority'
  Prelude.Natural ->
  -- | 'name'
  RecoveryOptionNameType ->
  RecoveryOptionType
newRecoveryOptionType :: Natural -> RecoveryOptionNameType -> RecoveryOptionType
newRecoveryOptionType Natural
pPriority_ RecoveryOptionNameType
pName_ =
  RecoveryOptionType' :: Natural -> RecoveryOptionNameType -> RecoveryOptionType
RecoveryOptionType'
    { $sel:priority:RecoveryOptionType' :: Natural
priority = Natural
pPriority_,
      $sel:name:RecoveryOptionType' :: RecoveryOptionNameType
name = RecoveryOptionNameType
pName_
    }

-- | A positive integer specifying priority of a method with 1 being the
-- highest priority.
recoveryOptionType_priority :: Lens.Lens' RecoveryOptionType Prelude.Natural
recoveryOptionType_priority :: (Natural -> f Natural)
-> RecoveryOptionType -> f RecoveryOptionType
recoveryOptionType_priority = (RecoveryOptionType -> Natural)
-> (RecoveryOptionType -> Natural -> RecoveryOptionType)
-> Lens RecoveryOptionType RecoveryOptionType Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecoveryOptionType' {Natural
priority :: Natural
$sel:priority:RecoveryOptionType' :: RecoveryOptionType -> Natural
priority} -> Natural
priority) (\s :: RecoveryOptionType
s@RecoveryOptionType' {} Natural
a -> RecoveryOptionType
s {$sel:priority:RecoveryOptionType' :: Natural
priority = Natural
a} :: RecoveryOptionType)

-- | Specifies the recovery method for a user.
recoveryOptionType_name :: Lens.Lens' RecoveryOptionType RecoveryOptionNameType
recoveryOptionType_name :: (RecoveryOptionNameType -> f RecoveryOptionNameType)
-> RecoveryOptionType -> f RecoveryOptionType
recoveryOptionType_name = (RecoveryOptionType -> RecoveryOptionNameType)
-> (RecoveryOptionType
    -> RecoveryOptionNameType -> RecoveryOptionType)
-> Lens
     RecoveryOptionType
     RecoveryOptionType
     RecoveryOptionNameType
     RecoveryOptionNameType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecoveryOptionType' {RecoveryOptionNameType
name :: RecoveryOptionNameType
$sel:name:RecoveryOptionType' :: RecoveryOptionType -> RecoveryOptionNameType
name} -> RecoveryOptionNameType
name) (\s :: RecoveryOptionType
s@RecoveryOptionType' {} RecoveryOptionNameType
a -> RecoveryOptionType
s {$sel:name:RecoveryOptionType' :: RecoveryOptionNameType
name = RecoveryOptionNameType
a} :: RecoveryOptionType)

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

instance Prelude.Hashable RecoveryOptionType

instance Prelude.NFData RecoveryOptionType

instance Core.ToJSON RecoveryOptionType where
  toJSON :: RecoveryOptionType -> Value
toJSON RecoveryOptionType' {Natural
RecoveryOptionNameType
name :: RecoveryOptionNameType
priority :: Natural
$sel:name:RecoveryOptionType' :: RecoveryOptionType -> RecoveryOptionNameType
$sel:priority:RecoveryOptionType' :: RecoveryOptionType -> Natural
..} =
    [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
"Priority" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
priority),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> RecoveryOptionNameType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RecoveryOptionNameType
name)
          ]
      )