{-# 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.CognitoIdentity.Types.MappingRule
-- 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.CognitoIdentity.Types.MappingRule where

import Amazonka.CognitoIdentity.Types.MappingRuleMatchType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A rule that maps a claim name, a claim value, and a match type to a role
-- ARN.
--
-- /See:/ 'newMappingRule' smart constructor.
data MappingRule = MappingRule'
  { -- | The claim name that must be present in the token, for example,
    -- \"isAdmin\" or \"paid\".
    MappingRule -> Text
claim :: Prelude.Text,
    -- | The match condition that specifies how closely the claim value in the
    -- IdP token must match @Value@.
    MappingRule -> MappingRuleMatchType
matchType :: MappingRuleMatchType,
    -- | A brief string that the claim must match, for example, \"paid\" or
    -- \"yes\".
    MappingRule -> Text
value :: Prelude.Text,
    -- | The role ARN.
    MappingRule -> Text
roleARN :: Prelude.Text
  }
  deriving (MappingRule -> MappingRule -> Bool
(MappingRule -> MappingRule -> Bool)
-> (MappingRule -> MappingRule -> Bool) -> Eq MappingRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MappingRule -> MappingRule -> Bool
$c/= :: MappingRule -> MappingRule -> Bool
== :: MappingRule -> MappingRule -> Bool
$c== :: MappingRule -> MappingRule -> Bool
Prelude.Eq, ReadPrec [MappingRule]
ReadPrec MappingRule
Int -> ReadS MappingRule
ReadS [MappingRule]
(Int -> ReadS MappingRule)
-> ReadS [MappingRule]
-> ReadPrec MappingRule
-> ReadPrec [MappingRule]
-> Read MappingRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MappingRule]
$creadListPrec :: ReadPrec [MappingRule]
readPrec :: ReadPrec MappingRule
$creadPrec :: ReadPrec MappingRule
readList :: ReadS [MappingRule]
$creadList :: ReadS [MappingRule]
readsPrec :: Int -> ReadS MappingRule
$creadsPrec :: Int -> ReadS MappingRule
Prelude.Read, Int -> MappingRule -> ShowS
[MappingRule] -> ShowS
MappingRule -> String
(Int -> MappingRule -> ShowS)
-> (MappingRule -> String)
-> ([MappingRule] -> ShowS)
-> Show MappingRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MappingRule] -> ShowS
$cshowList :: [MappingRule] -> ShowS
show :: MappingRule -> String
$cshow :: MappingRule -> String
showsPrec :: Int -> MappingRule -> ShowS
$cshowsPrec :: Int -> MappingRule -> ShowS
Prelude.Show, (forall x. MappingRule -> Rep MappingRule x)
-> (forall x. Rep MappingRule x -> MappingRule)
-> Generic MappingRule
forall x. Rep MappingRule x -> MappingRule
forall x. MappingRule -> Rep MappingRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MappingRule x -> MappingRule
$cfrom :: forall x. MappingRule -> Rep MappingRule x
Prelude.Generic)

-- |
-- Create a value of 'MappingRule' 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:
--
-- 'claim', 'mappingRule_claim' - The claim name that must be present in the token, for example,
-- \"isAdmin\" or \"paid\".
--
-- 'matchType', 'mappingRule_matchType' - The match condition that specifies how closely the claim value in the
-- IdP token must match @Value@.
--
-- 'value', 'mappingRule_value' - A brief string that the claim must match, for example, \"paid\" or
-- \"yes\".
--
-- 'roleARN', 'mappingRule_roleARN' - The role ARN.
newMappingRule ::
  -- | 'claim'
  Prelude.Text ->
  -- | 'matchType'
  MappingRuleMatchType ->
  -- | 'value'
  Prelude.Text ->
  -- | 'roleARN'
  Prelude.Text ->
  MappingRule
newMappingRule :: Text -> MappingRuleMatchType -> Text -> Text -> MappingRule
newMappingRule Text
pClaim_ MappingRuleMatchType
pMatchType_ Text
pValue_ Text
pRoleARN_ =
  MappingRule' :: Text -> MappingRuleMatchType -> Text -> Text -> MappingRule
MappingRule'
    { $sel:claim:MappingRule' :: Text
claim = Text
pClaim_,
      $sel:matchType:MappingRule' :: MappingRuleMatchType
matchType = MappingRuleMatchType
pMatchType_,
      $sel:value:MappingRule' :: Text
value = Text
pValue_,
      $sel:roleARN:MappingRule' :: Text
roleARN = Text
pRoleARN_
    }

-- | The claim name that must be present in the token, for example,
-- \"isAdmin\" or \"paid\".
mappingRule_claim :: Lens.Lens' MappingRule Prelude.Text
mappingRule_claim :: (Text -> f Text) -> MappingRule -> f MappingRule
mappingRule_claim = (MappingRule -> Text)
-> (MappingRule -> Text -> MappingRule)
-> Lens MappingRule MappingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MappingRule' {Text
claim :: Text
$sel:claim:MappingRule' :: MappingRule -> Text
claim} -> Text
claim) (\s :: MappingRule
s@MappingRule' {} Text
a -> MappingRule
s {$sel:claim:MappingRule' :: Text
claim = Text
a} :: MappingRule)

-- | The match condition that specifies how closely the claim value in the
-- IdP token must match @Value@.
mappingRule_matchType :: Lens.Lens' MappingRule MappingRuleMatchType
mappingRule_matchType :: (MappingRuleMatchType -> f MappingRuleMatchType)
-> MappingRule -> f MappingRule
mappingRule_matchType = (MappingRule -> MappingRuleMatchType)
-> (MappingRule -> MappingRuleMatchType -> MappingRule)
-> Lens
     MappingRule MappingRule MappingRuleMatchType MappingRuleMatchType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MappingRule' {MappingRuleMatchType
matchType :: MappingRuleMatchType
$sel:matchType:MappingRule' :: MappingRule -> MappingRuleMatchType
matchType} -> MappingRuleMatchType
matchType) (\s :: MappingRule
s@MappingRule' {} MappingRuleMatchType
a -> MappingRule
s {$sel:matchType:MappingRule' :: MappingRuleMatchType
matchType = MappingRuleMatchType
a} :: MappingRule)

-- | A brief string that the claim must match, for example, \"paid\" or
-- \"yes\".
mappingRule_value :: Lens.Lens' MappingRule Prelude.Text
mappingRule_value :: (Text -> f Text) -> MappingRule -> f MappingRule
mappingRule_value = (MappingRule -> Text)
-> (MappingRule -> Text -> MappingRule)
-> Lens MappingRule MappingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MappingRule' {Text
value :: Text
$sel:value:MappingRule' :: MappingRule -> Text
value} -> Text
value) (\s :: MappingRule
s@MappingRule' {} Text
a -> MappingRule
s {$sel:value:MappingRule' :: Text
value = Text
a} :: MappingRule)

-- | The role ARN.
mappingRule_roleARN :: Lens.Lens' MappingRule Prelude.Text
mappingRule_roleARN :: (Text -> f Text) -> MappingRule -> f MappingRule
mappingRule_roleARN = (MappingRule -> Text)
-> (MappingRule -> Text -> MappingRule)
-> Lens MappingRule MappingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MappingRule' {Text
roleARN :: Text
$sel:roleARN:MappingRule' :: MappingRule -> Text
roleARN} -> Text
roleARN) (\s :: MappingRule
s@MappingRule' {} Text
a -> MappingRule
s {$sel:roleARN:MappingRule' :: Text
roleARN = Text
a} :: MappingRule)

instance Core.FromJSON MappingRule where
  parseJSON :: Value -> Parser MappingRule
parseJSON =
    String
-> (Object -> Parser MappingRule) -> Value -> Parser MappingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MappingRule"
      ( \Object
x ->
          Text -> MappingRuleMatchType -> Text -> Text -> MappingRule
MappingRule'
            (Text -> MappingRuleMatchType -> Text -> Text -> MappingRule)
-> Parser Text
-> Parser (MappingRuleMatchType -> Text -> Text -> MappingRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Claim")
            Parser (MappingRuleMatchType -> Text -> Text -> MappingRule)
-> Parser MappingRuleMatchType
-> Parser (Text -> Text -> MappingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser MappingRuleMatchType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MatchType")
            Parser (Text -> Text -> MappingRule)
-> Parser Text -> Parser (Text -> MappingRule)
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
"Value")
            Parser (Text -> MappingRule) -> Parser Text -> Parser MappingRule
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
"RoleARN")
      )

instance Prelude.Hashable MappingRule

instance Prelude.NFData MappingRule

instance Core.ToJSON MappingRule where
  toJSON :: MappingRule -> Value
toJSON MappingRule' {Text
MappingRuleMatchType
roleARN :: Text
value :: Text
matchType :: MappingRuleMatchType
claim :: Text
$sel:roleARN:MappingRule' :: MappingRule -> Text
$sel:value:MappingRule' :: MappingRule -> Text
$sel:matchType:MappingRule' :: MappingRule -> MappingRuleMatchType
$sel:claim:MappingRule' :: MappingRule -> 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
"Claim" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
claim),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MatchType" Text -> MappingRuleMatchType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MappingRuleMatchType
matchType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RoleARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleARN)
          ]
      )