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

import Amazonka.CognitoIdentity.Types.MappingRule
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 container for rules.
--
-- /See:/ 'newRulesConfigurationType' smart constructor.
data RulesConfigurationType = RulesConfigurationType'
  { -- | An array of rules. You can specify up to 25 rules per identity provider.
    --
    -- Rules are evaluated in order. The first one to match specifies the role.
    RulesConfigurationType -> NonEmpty MappingRule
rules :: Prelude.NonEmpty MappingRule
  }
  deriving (RulesConfigurationType -> RulesConfigurationType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RulesConfigurationType -> RulesConfigurationType -> Bool
$c/= :: RulesConfigurationType -> RulesConfigurationType -> Bool
== :: RulesConfigurationType -> RulesConfigurationType -> Bool
$c== :: RulesConfigurationType -> RulesConfigurationType -> Bool
Prelude.Eq, ReadPrec [RulesConfigurationType]
ReadPrec RulesConfigurationType
Int -> ReadS RulesConfigurationType
ReadS [RulesConfigurationType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RulesConfigurationType]
$creadListPrec :: ReadPrec [RulesConfigurationType]
readPrec :: ReadPrec RulesConfigurationType
$creadPrec :: ReadPrec RulesConfigurationType
readList :: ReadS [RulesConfigurationType]
$creadList :: ReadS [RulesConfigurationType]
readsPrec :: Int -> ReadS RulesConfigurationType
$creadsPrec :: Int -> ReadS RulesConfigurationType
Prelude.Read, Int -> RulesConfigurationType -> ShowS
[RulesConfigurationType] -> ShowS
RulesConfigurationType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RulesConfigurationType] -> ShowS
$cshowList :: [RulesConfigurationType] -> ShowS
show :: RulesConfigurationType -> String
$cshow :: RulesConfigurationType -> String
showsPrec :: Int -> RulesConfigurationType -> ShowS
$cshowsPrec :: Int -> RulesConfigurationType -> ShowS
Prelude.Show, forall x. Rep RulesConfigurationType x -> RulesConfigurationType
forall x. RulesConfigurationType -> Rep RulesConfigurationType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RulesConfigurationType x -> RulesConfigurationType
$cfrom :: forall x. RulesConfigurationType -> Rep RulesConfigurationType x
Prelude.Generic)

-- |
-- Create a value of 'RulesConfigurationType' 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:
--
-- 'rules', 'rulesConfigurationType_rules' - An array of rules. You can specify up to 25 rules per identity provider.
--
-- Rules are evaluated in order. The first one to match specifies the role.
newRulesConfigurationType ::
  -- | 'rules'
  Prelude.NonEmpty MappingRule ->
  RulesConfigurationType
newRulesConfigurationType :: NonEmpty MappingRule -> RulesConfigurationType
newRulesConfigurationType NonEmpty MappingRule
pRules_ =
  RulesConfigurationType'
    { $sel:rules:RulesConfigurationType' :: NonEmpty MappingRule
rules =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty MappingRule
pRules_
    }

-- | An array of rules. You can specify up to 25 rules per identity provider.
--
-- Rules are evaluated in order. The first one to match specifies the role.
rulesConfigurationType_rules :: Lens.Lens' RulesConfigurationType (Prelude.NonEmpty MappingRule)
rulesConfigurationType_rules :: Lens' RulesConfigurationType (NonEmpty MappingRule)
rulesConfigurationType_rules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesConfigurationType' {NonEmpty MappingRule
rules :: NonEmpty MappingRule
$sel:rules:RulesConfigurationType' :: RulesConfigurationType -> NonEmpty MappingRule
rules} -> NonEmpty MappingRule
rules) (\s :: RulesConfigurationType
s@RulesConfigurationType' {} NonEmpty MappingRule
a -> RulesConfigurationType
s {$sel:rules:RulesConfigurationType' :: NonEmpty MappingRule
rules = NonEmpty MappingRule
a} :: RulesConfigurationType) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON RulesConfigurationType where
  parseJSON :: Value -> Parser RulesConfigurationType
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RulesConfigurationType"
      ( \Object
x ->
          NonEmpty MappingRule -> RulesConfigurationType
RulesConfigurationType'
            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
"Rules")
      )

instance Prelude.Hashable RulesConfigurationType where
  hashWithSalt :: Int -> RulesConfigurationType -> Int
hashWithSalt Int
_salt RulesConfigurationType' {NonEmpty MappingRule
rules :: NonEmpty MappingRule
$sel:rules:RulesConfigurationType' :: RulesConfigurationType -> NonEmpty MappingRule
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty MappingRule
rules

instance Prelude.NFData RulesConfigurationType where
  rnf :: RulesConfigurationType -> ()
rnf RulesConfigurationType' {NonEmpty MappingRule
rules :: NonEmpty MappingRule
$sel:rules:RulesConfigurationType' :: RulesConfigurationType -> NonEmpty MappingRule
..} = forall a. NFData a => a -> ()
Prelude.rnf NonEmpty MappingRule
rules

instance Data.ToJSON RulesConfigurationType where
  toJSON :: RulesConfigurationType -> Value
toJSON RulesConfigurationType' {NonEmpty MappingRule
rules :: NonEmpty MappingRule
$sel:rules:RulesConfigurationType' :: RulesConfigurationType -> NonEmpty MappingRule
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Rules" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty MappingRule
rules)]
      )