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

import Amazonka.CognitoIdentity.Types.MappingRule
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(RulesConfigurationType -> RulesConfigurationType -> Bool)
-> (RulesConfigurationType -> RulesConfigurationType -> Bool)
-> Eq RulesConfigurationType
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]
(Int -> ReadS RulesConfigurationType)
-> ReadS [RulesConfigurationType]
-> ReadPrec RulesConfigurationType
-> ReadPrec [RulesConfigurationType]
-> Read 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
(Int -> RulesConfigurationType -> ShowS)
-> (RulesConfigurationType -> String)
-> ([RulesConfigurationType] -> ShowS)
-> Show RulesConfigurationType
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. RulesConfigurationType -> Rep RulesConfigurationType x)
-> (forall x.
    Rep RulesConfigurationType x -> RulesConfigurationType)
-> Generic RulesConfigurationType
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' :: NonEmpty MappingRule -> RulesConfigurationType
RulesConfigurationType'
    { $sel:rules:RulesConfigurationType' :: NonEmpty MappingRule
rules =
        Tagged (NonEmpty MappingRule) (Identity (NonEmpty MappingRule))
-> Tagged (NonEmpty MappingRule) (Identity (NonEmpty MappingRule))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty MappingRule) (Identity (NonEmpty MappingRule))
 -> Tagged (NonEmpty MappingRule) (Identity (NonEmpty MappingRule)))
-> NonEmpty MappingRule -> NonEmpty MappingRule
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 :: (NonEmpty MappingRule -> f (NonEmpty MappingRule))
-> RulesConfigurationType -> f RulesConfigurationType
rulesConfigurationType_rules = (RulesConfigurationType -> NonEmpty MappingRule)
-> (RulesConfigurationType
    -> NonEmpty MappingRule -> RulesConfigurationType)
-> Lens
     RulesConfigurationType
     RulesConfigurationType
     (NonEmpty MappingRule)
     (NonEmpty MappingRule)
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) ((NonEmpty MappingRule -> f (NonEmpty MappingRule))
 -> RulesConfigurationType -> f RulesConfigurationType)
-> ((NonEmpty MappingRule -> f (NonEmpty MappingRule))
    -> NonEmpty MappingRule -> f (NonEmpty MappingRule))
-> (NonEmpty MappingRule -> f (NonEmpty MappingRule))
-> RulesConfigurationType
-> f RulesConfigurationType
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty MappingRule -> f (NonEmpty MappingRule))
-> NonEmpty MappingRule -> f (NonEmpty MappingRule)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON RulesConfigurationType where
  parseJSON :: Value -> Parser RulesConfigurationType
parseJSON =
    String
-> (Object -> Parser RulesConfigurationType)
-> Value
-> Parser RulesConfigurationType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RulesConfigurationType"
      ( \Object
x ->
          NonEmpty MappingRule -> RulesConfigurationType
RulesConfigurationType'
            (NonEmpty MappingRule -> RulesConfigurationType)
-> Parser (NonEmpty MappingRule) -> Parser RulesConfigurationType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty MappingRule)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Rules")
      )

instance Prelude.Hashable RulesConfigurationType

instance Prelude.NFData RulesConfigurationType

instance Core.ToJSON RulesConfigurationType where
  toJSON :: RulesConfigurationType -> Value
toJSON RulesConfigurationType' {NonEmpty MappingRule
rules :: NonEmpty MappingRule
$sel:rules:RulesConfigurationType' :: RulesConfigurationType -> NonEmpty MappingRule
..} =
    [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
"Rules" Text -> NonEmpty MappingRule -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty MappingRule
rules)]
      )