{-# 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.AccessAnalyzer.Types.InlineArchiveRule
-- 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.AccessAnalyzer.Types.InlineArchiveRule where

import Amazonka.AccessAnalyzer.Types.Criterion
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An criterion statement in an archive rule. Each archive rule may have
-- multiple criteria.
--
-- /See:/ 'newInlineArchiveRule' smart constructor.
data InlineArchiveRule = InlineArchiveRule'
  { -- | The condition and values for a criterion.
    InlineArchiveRule -> HashMap Text Criterion
filter' :: Prelude.HashMap Prelude.Text Criterion,
    -- | The name of the rule.
    InlineArchiveRule -> Text
ruleName :: Prelude.Text
  }
  deriving (InlineArchiveRule -> InlineArchiveRule -> Bool
(InlineArchiveRule -> InlineArchiveRule -> Bool)
-> (InlineArchiveRule -> InlineArchiveRule -> Bool)
-> Eq InlineArchiveRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InlineArchiveRule -> InlineArchiveRule -> Bool
$c/= :: InlineArchiveRule -> InlineArchiveRule -> Bool
== :: InlineArchiveRule -> InlineArchiveRule -> Bool
$c== :: InlineArchiveRule -> InlineArchiveRule -> Bool
Prelude.Eq, ReadPrec [InlineArchiveRule]
ReadPrec InlineArchiveRule
Int -> ReadS InlineArchiveRule
ReadS [InlineArchiveRule]
(Int -> ReadS InlineArchiveRule)
-> ReadS [InlineArchiveRule]
-> ReadPrec InlineArchiveRule
-> ReadPrec [InlineArchiveRule]
-> Read InlineArchiveRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InlineArchiveRule]
$creadListPrec :: ReadPrec [InlineArchiveRule]
readPrec :: ReadPrec InlineArchiveRule
$creadPrec :: ReadPrec InlineArchiveRule
readList :: ReadS [InlineArchiveRule]
$creadList :: ReadS [InlineArchiveRule]
readsPrec :: Int -> ReadS InlineArchiveRule
$creadsPrec :: Int -> ReadS InlineArchiveRule
Prelude.Read, Int -> InlineArchiveRule -> ShowS
[InlineArchiveRule] -> ShowS
InlineArchiveRule -> String
(Int -> InlineArchiveRule -> ShowS)
-> (InlineArchiveRule -> String)
-> ([InlineArchiveRule] -> ShowS)
-> Show InlineArchiveRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InlineArchiveRule] -> ShowS
$cshowList :: [InlineArchiveRule] -> ShowS
show :: InlineArchiveRule -> String
$cshow :: InlineArchiveRule -> String
showsPrec :: Int -> InlineArchiveRule -> ShowS
$cshowsPrec :: Int -> InlineArchiveRule -> ShowS
Prelude.Show, (forall x. InlineArchiveRule -> Rep InlineArchiveRule x)
-> (forall x. Rep InlineArchiveRule x -> InlineArchiveRule)
-> Generic InlineArchiveRule
forall x. Rep InlineArchiveRule x -> InlineArchiveRule
forall x. InlineArchiveRule -> Rep InlineArchiveRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InlineArchiveRule x -> InlineArchiveRule
$cfrom :: forall x. InlineArchiveRule -> Rep InlineArchiveRule x
Prelude.Generic)

-- |
-- Create a value of 'InlineArchiveRule' 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:
--
-- 'filter'', 'inlineArchiveRule_filter' - The condition and values for a criterion.
--
-- 'ruleName', 'inlineArchiveRule_ruleName' - The name of the rule.
newInlineArchiveRule ::
  -- | 'ruleName'
  Prelude.Text ->
  InlineArchiveRule
newInlineArchiveRule :: Text -> InlineArchiveRule
newInlineArchiveRule Text
pRuleName_ =
  InlineArchiveRule' :: HashMap Text Criterion -> Text -> InlineArchiveRule
InlineArchiveRule'
    { $sel:filter':InlineArchiveRule' :: HashMap Text Criterion
filter' = HashMap Text Criterion
forall a. Monoid a => a
Prelude.mempty,
      $sel:ruleName:InlineArchiveRule' :: Text
ruleName = Text
pRuleName_
    }

-- | The condition and values for a criterion.
inlineArchiveRule_filter :: Lens.Lens' InlineArchiveRule (Prelude.HashMap Prelude.Text Criterion)
inlineArchiveRule_filter :: (HashMap Text Criterion -> f (HashMap Text Criterion))
-> InlineArchiveRule -> f InlineArchiveRule
inlineArchiveRule_filter = (InlineArchiveRule -> HashMap Text Criterion)
-> (InlineArchiveRule
    -> HashMap Text Criterion -> InlineArchiveRule)
-> Lens
     InlineArchiveRule
     InlineArchiveRule
     (HashMap Text Criterion)
     (HashMap Text Criterion)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InlineArchiveRule' {HashMap Text Criterion
filter' :: HashMap Text Criterion
$sel:filter':InlineArchiveRule' :: InlineArchiveRule -> HashMap Text Criterion
filter'} -> HashMap Text Criterion
filter') (\s :: InlineArchiveRule
s@InlineArchiveRule' {} HashMap Text Criterion
a -> InlineArchiveRule
s {$sel:filter':InlineArchiveRule' :: HashMap Text Criterion
filter' = HashMap Text Criterion
a} :: InlineArchiveRule) ((HashMap Text Criterion -> f (HashMap Text Criterion))
 -> InlineArchiveRule -> f InlineArchiveRule)
-> ((HashMap Text Criterion -> f (HashMap Text Criterion))
    -> HashMap Text Criterion -> f (HashMap Text Criterion))
-> (HashMap Text Criterion -> f (HashMap Text Criterion))
-> InlineArchiveRule
-> f InlineArchiveRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Criterion -> f (HashMap Text Criterion))
-> HashMap Text Criterion -> f (HashMap Text Criterion)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the rule.
inlineArchiveRule_ruleName :: Lens.Lens' InlineArchiveRule Prelude.Text
inlineArchiveRule_ruleName :: (Text -> f Text) -> InlineArchiveRule -> f InlineArchiveRule
inlineArchiveRule_ruleName = (InlineArchiveRule -> Text)
-> (InlineArchiveRule -> Text -> InlineArchiveRule)
-> Lens InlineArchiveRule InlineArchiveRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InlineArchiveRule' {Text
ruleName :: Text
$sel:ruleName:InlineArchiveRule' :: InlineArchiveRule -> Text
ruleName} -> Text
ruleName) (\s :: InlineArchiveRule
s@InlineArchiveRule' {} Text
a -> InlineArchiveRule
s {$sel:ruleName:InlineArchiveRule' :: Text
ruleName = Text
a} :: InlineArchiveRule)

instance Prelude.Hashable InlineArchiveRule

instance Prelude.NFData InlineArchiveRule

instance Core.ToJSON InlineArchiveRule where
  toJSON :: InlineArchiveRule -> Value
toJSON InlineArchiveRule' {Text
HashMap Text Criterion
ruleName :: Text
filter' :: HashMap Text Criterion
$sel:ruleName:InlineArchiveRule' :: InlineArchiveRule -> Text
$sel:filter':InlineArchiveRule' :: InlineArchiveRule -> HashMap Text Criterion
..} =
    [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
"filter" Text -> HashMap Text Criterion -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Criterion
filter'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ruleName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ruleName)
          ]
      )