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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The criteria to use in the filter that defines the archive rule.
--
-- /See:/ 'newCriterion' smart constructor.
data Criterion = Criterion'
  { -- | 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),
    -- | A \"contains\" operator to match for the filter used to create the rule.
    Criterion -> Maybe (NonEmpty Text)
contains :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (Criterion -> Criterion -> Bool
(Criterion -> Criterion -> Bool)
-> (Criterion -> Criterion -> Bool) -> Eq Criterion
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]
(Int -> ReadS Criterion)
-> ReadS [Criterion]
-> ReadPrec Criterion
-> ReadPrec [Criterion]
-> Read 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
(Int -> Criterion -> ShowS)
-> (Criterion -> String)
-> ([Criterion] -> ShowS)
-> Show Criterion
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. Criterion -> Rep Criterion x)
-> (forall x. Rep Criterion x -> Criterion) -> Generic Criterion
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:
--
-- '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.
--
-- 'contains', 'criterion_contains' - A \"contains\" operator to match for the filter used to create the rule.
newCriterion ::
  Criterion
newCriterion :: Criterion
newCriterion =
  Criterion' :: Maybe (NonEmpty Text)
-> Maybe Bool
-> Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Criterion
Criterion'
    { $sel:eq:Criterion' :: Maybe (NonEmpty Text)
eq = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:exists:Criterion' :: Maybe Bool
exists = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:neq:Criterion' :: Maybe (NonEmpty Text)
neq = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:contains:Criterion' :: Maybe (NonEmpty Text)
contains = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Criterion -> f Criterion
criterion_eq = (Criterion -> Maybe (NonEmpty Text))
-> (Criterion -> Maybe (NonEmpty Text) -> Criterion)
-> Lens
     Criterion Criterion (Maybe (NonEmpty Text)) (Maybe (NonEmpty Text))
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) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> Criterion -> f Criterion)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Criterion
-> f Criterion
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
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 :: (Maybe Bool -> f (Maybe Bool)) -> Criterion -> f Criterion
criterion_exists = (Criterion -> Maybe Bool)
-> (Criterion -> Maybe Bool -> Criterion)
-> Lens Criterion Criterion (Maybe Bool) (Maybe Bool)
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 :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Criterion -> f Criterion
criterion_neq = (Criterion -> Maybe (NonEmpty Text))
-> (Criterion -> Maybe (NonEmpty Text) -> Criterion)
-> Lens
     Criterion Criterion (Maybe (NonEmpty Text)) (Maybe (NonEmpty Text))
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) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> Criterion -> f Criterion)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Criterion
-> f Criterion
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Criterion -> f Criterion
criterion_contains = (Criterion -> Maybe (NonEmpty Text))
-> (Criterion -> Maybe (NonEmpty Text) -> Criterion)
-> Lens
     Criterion Criterion (Maybe (NonEmpty Text)) (Maybe (NonEmpty Text))
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) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> Criterion -> f Criterion)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> Criterion
-> f Criterion
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Criterion

instance Prelude.NFData Criterion

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