{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' MappingRule Text
mappingRule_claim = 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 :: Lens' MappingRule MappingRuleMatchType
mappingRule_matchType = 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 :: Lens' MappingRule Text
mappingRule_value = 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 :: Lens' MappingRule Text
mappingRule_roleARN = 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 Data.FromJSON MappingRule where
  parseJSON :: Value -> Parser MappingRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MappingRule"
      ( \Object
x ->
          Text -> MappingRuleMatchType -> Text -> Text -> MappingRule
MappingRule'
            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
"Claim")
            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
"MatchType")
            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
"Value")
            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
"RoleARN")
      )

instance Prelude.Hashable MappingRule where
  hashWithSalt :: Int -> MappingRule -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
claim
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MappingRuleMatchType
matchType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleARN

instance Prelude.NFData MappingRule where
  rnf :: MappingRule -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
claim
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MappingRuleMatchType
matchType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleARN

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Claim" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
claim),
            forall a. a -> Maybe a
Prelude.Just (Key
"MatchType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= MappingRuleMatchType
matchType),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value),
            forall a. a -> Maybe a
Prelude.Just (Key
"RoleARN" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleARN)
          ]
      )