{-# 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.GuardDuty.Types.FindingCriteria
-- 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.GuardDuty.Types.FindingCriteria where

import qualified Amazonka.Core as Core
import Amazonka.GuardDuty.Types.Condition
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about the criteria used for querying findings.
--
-- /See:/ 'newFindingCriteria' smart constructor.
data FindingCriteria = FindingCriteria'
  { -- | Represents a map of finding properties that match specified conditions
    -- and values when querying findings.
    FindingCriteria -> Maybe (HashMap Text Condition)
criterion :: Prelude.Maybe (Prelude.HashMap Prelude.Text Condition)
  }
  deriving (FindingCriteria -> FindingCriteria -> Bool
(FindingCriteria -> FindingCriteria -> Bool)
-> (FindingCriteria -> FindingCriteria -> Bool)
-> Eq FindingCriteria
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FindingCriteria -> FindingCriteria -> Bool
$c/= :: FindingCriteria -> FindingCriteria -> Bool
== :: FindingCriteria -> FindingCriteria -> Bool
$c== :: FindingCriteria -> FindingCriteria -> Bool
Prelude.Eq, ReadPrec [FindingCriteria]
ReadPrec FindingCriteria
Int -> ReadS FindingCriteria
ReadS [FindingCriteria]
(Int -> ReadS FindingCriteria)
-> ReadS [FindingCriteria]
-> ReadPrec FindingCriteria
-> ReadPrec [FindingCriteria]
-> Read FindingCriteria
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FindingCriteria]
$creadListPrec :: ReadPrec [FindingCriteria]
readPrec :: ReadPrec FindingCriteria
$creadPrec :: ReadPrec FindingCriteria
readList :: ReadS [FindingCriteria]
$creadList :: ReadS [FindingCriteria]
readsPrec :: Int -> ReadS FindingCriteria
$creadsPrec :: Int -> ReadS FindingCriteria
Prelude.Read, Int -> FindingCriteria -> ShowS
[FindingCriteria] -> ShowS
FindingCriteria -> String
(Int -> FindingCriteria -> ShowS)
-> (FindingCriteria -> String)
-> ([FindingCriteria] -> ShowS)
-> Show FindingCriteria
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FindingCriteria] -> ShowS
$cshowList :: [FindingCriteria] -> ShowS
show :: FindingCriteria -> String
$cshow :: FindingCriteria -> String
showsPrec :: Int -> FindingCriteria -> ShowS
$cshowsPrec :: Int -> FindingCriteria -> ShowS
Prelude.Show, (forall x. FindingCriteria -> Rep FindingCriteria x)
-> (forall x. Rep FindingCriteria x -> FindingCriteria)
-> Generic FindingCriteria
forall x. Rep FindingCriteria x -> FindingCriteria
forall x. FindingCriteria -> Rep FindingCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FindingCriteria x -> FindingCriteria
$cfrom :: forall x. FindingCriteria -> Rep FindingCriteria x
Prelude.Generic)

-- |
-- Create a value of 'FindingCriteria' 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:
--
-- 'criterion', 'findingCriteria_criterion' - Represents a map of finding properties that match specified conditions
-- and values when querying findings.
newFindingCriteria ::
  FindingCriteria
newFindingCriteria :: FindingCriteria
newFindingCriteria =
  FindingCriteria' :: Maybe (HashMap Text Condition) -> FindingCriteria
FindingCriteria' {$sel:criterion:FindingCriteria' :: Maybe (HashMap Text Condition)
criterion = Maybe (HashMap Text Condition)
forall a. Maybe a
Prelude.Nothing}

-- | Represents a map of finding properties that match specified conditions
-- and values when querying findings.
findingCriteria_criterion :: Lens.Lens' FindingCriteria (Prelude.Maybe (Prelude.HashMap Prelude.Text Condition))
findingCriteria_criterion :: (Maybe (HashMap Text Condition)
 -> f (Maybe (HashMap Text Condition)))
-> FindingCriteria -> f FindingCriteria
findingCriteria_criterion = (FindingCriteria -> Maybe (HashMap Text Condition))
-> (FindingCriteria
    -> Maybe (HashMap Text Condition) -> FindingCriteria)
-> Lens
     FindingCriteria
     FindingCriteria
     (Maybe (HashMap Text Condition))
     (Maybe (HashMap Text Condition))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FindingCriteria' {Maybe (HashMap Text Condition)
criterion :: Maybe (HashMap Text Condition)
$sel:criterion:FindingCriteria' :: FindingCriteria -> Maybe (HashMap Text Condition)
criterion} -> Maybe (HashMap Text Condition)
criterion) (\s :: FindingCriteria
s@FindingCriteria' {} Maybe (HashMap Text Condition)
a -> FindingCriteria
s {$sel:criterion:FindingCriteria' :: Maybe (HashMap Text Condition)
criterion = Maybe (HashMap Text Condition)
a} :: FindingCriteria) ((Maybe (HashMap Text Condition)
  -> f (Maybe (HashMap Text Condition)))
 -> FindingCriteria -> f FindingCriteria)
-> ((Maybe (HashMap Text Condition)
     -> f (Maybe (HashMap Text Condition)))
    -> Maybe (HashMap Text Condition)
    -> f (Maybe (HashMap Text Condition)))
-> (Maybe (HashMap Text Condition)
    -> f (Maybe (HashMap Text Condition)))
-> FindingCriteria
-> f FindingCriteria
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Condition)
  (HashMap Text Condition)
  (HashMap Text Condition)
  (HashMap Text Condition)
-> Iso
     (Maybe (HashMap Text Condition))
     (Maybe (HashMap Text Condition))
     (Maybe (HashMap Text Condition))
     (Maybe (HashMap Text Condition))
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
  (HashMap Text Condition)
  (HashMap Text Condition)
  (HashMap Text Condition)
  (HashMap Text Condition)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON FindingCriteria where
  parseJSON :: Value -> Parser FindingCriteria
parseJSON =
    String
-> (Object -> Parser FindingCriteria)
-> Value
-> Parser FindingCriteria
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FindingCriteria"
      ( \Object
x ->
          Maybe (HashMap Text Condition) -> FindingCriteria
FindingCriteria'
            (Maybe (HashMap Text Condition) -> FindingCriteria)
-> Parser (Maybe (HashMap Text Condition))
-> Parser FindingCriteria
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Condition)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"criterion" Parser (Maybe (Maybe (HashMap Text Condition)))
-> Maybe (HashMap Text Condition)
-> Parser (Maybe (HashMap Text Condition))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Condition)
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable FindingCriteria

instance Prelude.NFData FindingCriteria

instance Core.ToJSON FindingCriteria where
  toJSON :: FindingCriteria -> Value
toJSON FindingCriteria' {Maybe (HashMap Text Condition)
criterion :: Maybe (HashMap Text Condition)
$sel:criterion:FindingCriteria' :: FindingCriteria -> Maybe (HashMap Text Condition)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"criterion" Text -> HashMap Text Condition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Condition -> Pair)
-> Maybe (HashMap Text Condition) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Condition)
criterion]
      )