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

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

-- | The criteria to use in the filter that defines the archive rule. For
-- more information on available filter keys, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-reference-filter-keys.html IAM Access Analyzer filter keys>.
--
-- /See:/ 'newCriterion' smart constructor.
data Criterion = Criterion'
  { -- | A \"contains\" operator to match for the filter used to create the rule.
    Criterion -> Maybe (NonEmpty Text)
contains :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | An \"equals\" operator to match for the filter used to create the rule.
    Criterion -> Maybe (NonEmpty Text)
eq :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | An \"exists\" operator to match for the filter used to create the rule.
    Criterion -> Maybe Bool
exists :: Prelude.Maybe Prelude.Bool,
    -- | A \"not equals\" operator to match for the filter used to create the
    -- rule.
    Criterion -> Maybe (NonEmpty Text)
neq :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (Criterion -> Criterion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Criterion -> Criterion -> Bool
$c/= :: Criterion -> Criterion -> Bool
== :: Criterion -> Criterion -> Bool
$c== :: Criterion -> Criterion -> Bool
Prelude.Eq, ReadPrec [Criterion]
ReadPrec Criterion
Int -> ReadS Criterion
ReadS [Criterion]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Criterion]
$creadListPrec :: ReadPrec [Criterion]
readPrec :: ReadPrec Criterion
$creadPrec :: ReadPrec Criterion
readList :: ReadS [Criterion]
$creadList :: ReadS [Criterion]
readsPrec :: Int -> ReadS Criterion
$creadsPrec :: Int -> ReadS Criterion
Prelude.Read, Int -> Criterion -> ShowS
[Criterion] -> ShowS
Criterion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Criterion] -> ShowS
$cshowList :: [Criterion] -> ShowS
show :: Criterion -> String
$cshow :: Criterion -> String
showsPrec :: Int -> Criterion -> ShowS
$cshowsPrec :: Int -> Criterion -> ShowS
Prelude.Show, forall x. Rep Criterion x -> Criterion
forall x. Criterion -> Rep Criterion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Criterion x -> Criterion
$cfrom :: forall x. Criterion -> Rep Criterion x
Prelude.Generic)

-- |
-- Create a value of 'Criterion' 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:
--
-- 'contains', 'criterion_contains' - A \"contains\" operator to match for the filter used to create the rule.
--
-- 'eq', 'criterion_eq' - An \"equals\" operator to match for the filter used to create the rule.
--
-- 'exists', 'criterion_exists' - An \"exists\" operator to match for the filter used to create the rule.
--
-- 'neq', 'criterion_neq' - A \"not equals\" operator to match for the filter used to create the
-- rule.
newCriterion ::
  Criterion
newCriterion :: Criterion
newCriterion =
  Criterion'
    { $sel:contains:Criterion' :: Maybe (NonEmpty Text)
contains = forall a. Maybe a
Prelude.Nothing,
      $sel:eq:Criterion' :: Maybe (NonEmpty Text)
eq = forall a. Maybe a
Prelude.Nothing,
      $sel:exists:Criterion' :: Maybe Bool
exists = forall a. Maybe a
Prelude.Nothing,
      $sel:neq:Criterion' :: Maybe (NonEmpty Text)
neq = forall a. Maybe a
Prelude.Nothing
    }

-- | A \"contains\" operator to match for the filter used to create the rule.
criterion_contains :: Lens.Lens' Criterion (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
criterion_contains :: Lens' Criterion (Maybe (NonEmpty Text))
criterion_contains = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Criterion' {Maybe (NonEmpty Text)
contains :: Maybe (NonEmpty Text)
$sel:contains:Criterion' :: Criterion -> Maybe (NonEmpty Text)
contains} -> Maybe (NonEmpty Text)
contains) (\s :: Criterion
s@Criterion' {} Maybe (NonEmpty Text)
a -> Criterion
s {$sel:contains:Criterion' :: Maybe (NonEmpty Text)
contains = Maybe (NonEmpty Text)
a} :: Criterion) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An \"equals\" operator to match for the filter used to create the rule.
criterion_eq :: Lens.Lens' Criterion (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
criterion_eq :: Lens' Criterion (Maybe (NonEmpty Text))
criterion_eq = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Criterion' {Maybe (NonEmpty Text)
eq :: Maybe (NonEmpty Text)
$sel:eq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
eq} -> Maybe (NonEmpty Text)
eq) (\s :: Criterion
s@Criterion' {} Maybe (NonEmpty Text)
a -> Criterion
s {$sel:eq:Criterion' :: Maybe (NonEmpty Text)
eq = Maybe (NonEmpty Text)
a} :: Criterion) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An \"exists\" operator to match for the filter used to create the rule.
criterion_exists :: Lens.Lens' Criterion (Prelude.Maybe Prelude.Bool)
criterion_exists :: Lens' Criterion (Maybe Bool)
criterion_exists = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Criterion' {Maybe Bool
exists :: Maybe Bool
$sel:exists:Criterion' :: Criterion -> Maybe Bool
exists} -> Maybe Bool
exists) (\s :: Criterion
s@Criterion' {} Maybe Bool
a -> Criterion
s {$sel:exists:Criterion' :: Maybe Bool
exists = Maybe Bool
a} :: Criterion)

-- | A \"not equals\" operator to match for the filter used to create the
-- rule.
criterion_neq :: Lens.Lens' Criterion (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
criterion_neq :: Lens' Criterion (Maybe (NonEmpty Text))
criterion_neq = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Criterion' {Maybe (NonEmpty Text)
neq :: Maybe (NonEmpty Text)
$sel:neq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
neq} -> Maybe (NonEmpty Text)
neq) (\s :: Criterion
s@Criterion' {} Maybe (NonEmpty Text)
a -> Criterion
s {$sel:neq:Criterion' :: Maybe (NonEmpty Text)
neq = Maybe (NonEmpty Text)
a} :: Criterion) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON Criterion where
  parseJSON :: Value -> Parser Criterion
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Criterion"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Maybe Bool
-> Maybe (NonEmpty Text)
-> Criterion
Criterion'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"contains")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"eq")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"exists")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"neq")
      )

instance Prelude.Hashable Criterion where
  hashWithSalt :: Int -> Criterion -> Int
hashWithSalt Int
_salt Criterion' {Maybe Bool
Maybe (NonEmpty Text)
neq :: Maybe (NonEmpty Text)
exists :: Maybe Bool
eq :: Maybe (NonEmpty Text)
contains :: Maybe (NonEmpty Text)
$sel:neq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
$sel:exists:Criterion' :: Criterion -> Maybe Bool
$sel:eq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
$sel:contains:Criterion' :: Criterion -> Maybe (NonEmpty Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
contains
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
eq
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
exists
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
neq

instance Prelude.NFData Criterion where
  rnf :: Criterion -> ()
rnf Criterion' {Maybe Bool
Maybe (NonEmpty Text)
neq :: Maybe (NonEmpty Text)
exists :: Maybe Bool
eq :: Maybe (NonEmpty Text)
contains :: Maybe (NonEmpty Text)
$sel:neq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
$sel:exists:Criterion' :: Criterion -> Maybe Bool
$sel:eq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
$sel:contains:Criterion' :: Criterion -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
contains
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
eq
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
exists
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
neq

instance Data.ToJSON Criterion where
  toJSON :: Criterion -> Value
toJSON Criterion' {Maybe Bool
Maybe (NonEmpty Text)
neq :: Maybe (NonEmpty Text)
exists :: Maybe Bool
eq :: Maybe (NonEmpty Text)
contains :: Maybe (NonEmpty Text)
$sel:neq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
$sel:exists:Criterion' :: Criterion -> Maybe Bool
$sel:eq:Criterion' :: Criterion -> Maybe (NonEmpty Text)
$sel:contains:Criterion' :: Criterion -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"contains" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
contains,
            (Key
"eq" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
eq,
            (Key
"exists" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
exists,
            (Key
"neq" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
neq
          ]
      )