{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 name of the rule.
    InlineArchiveRule -> Text
ruleName :: Prelude.Text,
    -- | The condition and values for a criterion.
    InlineArchiveRule -> HashMap Text Criterion
filter' :: Prelude.HashMap Prelude.Text Criterion
  }
  deriving (InlineArchiveRule -> InlineArchiveRule -> Bool
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]
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
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. 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:
--
-- 'ruleName', 'inlineArchiveRule_ruleName' - The name of the rule.
--
-- 'filter'', 'inlineArchiveRule_filter' - The condition and values for a criterion.
newInlineArchiveRule ::
  -- | 'ruleName'
  Prelude.Text ->
  InlineArchiveRule
newInlineArchiveRule :: Text -> InlineArchiveRule
newInlineArchiveRule Text
pRuleName_ =
  InlineArchiveRule'
    { $sel:ruleName:InlineArchiveRule' :: Text
ruleName = Text
pRuleName_,
      $sel:filter':InlineArchiveRule' :: HashMap Text Criterion
filter' = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the rule.
inlineArchiveRule_ruleName :: Lens.Lens' InlineArchiveRule Prelude.Text
inlineArchiveRule_ruleName :: Lens' InlineArchiveRule Text
inlineArchiveRule_ruleName = 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)

-- | The condition and values for a criterion.
inlineArchiveRule_filter :: Lens.Lens' InlineArchiveRule (Prelude.HashMap Prelude.Text Criterion)
inlineArchiveRule_filter :: Lens' InlineArchiveRule (HashMap Text Criterion)
inlineArchiveRule_filter = 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) 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 Prelude.Hashable InlineArchiveRule where
  hashWithSalt :: Int -> InlineArchiveRule -> Int
hashWithSalt Int
_salt InlineArchiveRule' {Text
HashMap Text Criterion
filter' :: HashMap Text Criterion
ruleName :: Text
$sel:filter':InlineArchiveRule' :: InlineArchiveRule -> HashMap Text Criterion
$sel:ruleName:InlineArchiveRule' :: InlineArchiveRule -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
ruleName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Criterion
filter'

instance Prelude.NFData InlineArchiveRule where
  rnf :: InlineArchiveRule -> ()
rnf InlineArchiveRule' {Text
HashMap Text Criterion
filter' :: HashMap Text Criterion
ruleName :: Text
$sel:filter':InlineArchiveRule' :: InlineArchiveRule -> HashMap Text Criterion
$sel:ruleName:InlineArchiveRule' :: InlineArchiveRule -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
ruleName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text Criterion
filter'

instance Data.ToJSON InlineArchiveRule where
  toJSON :: InlineArchiveRule -> Value
toJSON InlineArchiveRule' {Text
HashMap Text Criterion
filter' :: HashMap Text Criterion
ruleName :: Text
$sel:filter':InlineArchiveRule' :: InlineArchiveRule -> HashMap Text Criterion
$sel:ruleName:InlineArchiveRule' :: InlineArchiveRule -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ruleName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
ruleName),
            forall a. a -> Maybe a
Prelude.Just (Key
"filter" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Criterion
filter')
          ]
      )