{-# 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.SecurityHub.Types.MapFilter
-- 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.SecurityHub.Types.MapFilter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SecurityHub.Types.MapFilterComparison

-- | A map filter for querying findings. Each map filter provides the field
-- to check, the value to look for, and the comparison operator.
--
-- /See:/ 'newMapFilter' smart constructor.
data MapFilter = MapFilter'
  { -- | The value for the key in the map filter. Filter values are case
    -- sensitive. For example, one of the values for a tag called @Department@
    -- might be @Security@. If you provide @security@ as the filter value, then
    -- there is no match.
    MapFilter -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The condition to apply to the key value when querying for findings with
    -- a map filter.
    --
    -- To search for values that exactly match the filter value, use @EQUALS@.
    -- For example, for the @ResourceTags@ field, the filter
    -- @Department EQUALS Security@ matches findings that have the value
    -- @Security@ for the tag @Department@.
    --
    -- To search for values other than the filter value, use @NOT_EQUALS@. For
    -- example, for the @ResourceTags@ field, the filter
    -- @Department NOT_EQUALS Finance@ matches findings that do not have the
    -- value @Finance@ for the tag @Department@.
    --
    -- @EQUALS@ filters on the same field are joined by @OR@. A finding matches
    -- if it matches any one of those filters.
    --
    -- @NOT_EQUALS@ filters on the same field are joined by @AND@. A finding
    -- matches only if it matches all of those filters.
    --
    -- You cannot have both an @EQUALS@ filter and a @NOT_EQUALS@ filter on the
    -- same field.
    MapFilter -> Maybe MapFilterComparison
comparison :: Prelude.Maybe MapFilterComparison,
    -- | The key of the map filter. For example, for @ResourceTags@, @Key@
    -- identifies the name of the tag. For @UserDefinedFields@, @Key@ is the
    -- name of the field.
    MapFilter -> Maybe Text
key :: Prelude.Maybe Prelude.Text
  }
  deriving (MapFilter -> MapFilter -> Bool
(MapFilter -> MapFilter -> Bool)
-> (MapFilter -> MapFilter -> Bool) -> Eq MapFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MapFilter -> MapFilter -> Bool
$c/= :: MapFilter -> MapFilter -> Bool
== :: MapFilter -> MapFilter -> Bool
$c== :: MapFilter -> MapFilter -> Bool
Prelude.Eq, ReadPrec [MapFilter]
ReadPrec MapFilter
Int -> ReadS MapFilter
ReadS [MapFilter]
(Int -> ReadS MapFilter)
-> ReadS [MapFilter]
-> ReadPrec MapFilter
-> ReadPrec [MapFilter]
-> Read MapFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MapFilter]
$creadListPrec :: ReadPrec [MapFilter]
readPrec :: ReadPrec MapFilter
$creadPrec :: ReadPrec MapFilter
readList :: ReadS [MapFilter]
$creadList :: ReadS [MapFilter]
readsPrec :: Int -> ReadS MapFilter
$creadsPrec :: Int -> ReadS MapFilter
Prelude.Read, Int -> MapFilter -> ShowS
[MapFilter] -> ShowS
MapFilter -> String
(Int -> MapFilter -> ShowS)
-> (MapFilter -> String)
-> ([MapFilter] -> ShowS)
-> Show MapFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MapFilter] -> ShowS
$cshowList :: [MapFilter] -> ShowS
show :: MapFilter -> String
$cshow :: MapFilter -> String
showsPrec :: Int -> MapFilter -> ShowS
$cshowsPrec :: Int -> MapFilter -> ShowS
Prelude.Show, (forall x. MapFilter -> Rep MapFilter x)
-> (forall x. Rep MapFilter x -> MapFilter) -> Generic MapFilter
forall x. Rep MapFilter x -> MapFilter
forall x. MapFilter -> Rep MapFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MapFilter x -> MapFilter
$cfrom :: forall x. MapFilter -> Rep MapFilter x
Prelude.Generic)

-- |
-- Create a value of 'MapFilter' 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:
--
-- 'value', 'mapFilter_value' - The value for the key in the map filter. Filter values are case
-- sensitive. For example, one of the values for a tag called @Department@
-- might be @Security@. If you provide @security@ as the filter value, then
-- there is no match.
--
-- 'comparison', 'mapFilter_comparison' - The condition to apply to the key value when querying for findings with
-- a map filter.
--
-- To search for values that exactly match the filter value, use @EQUALS@.
-- For example, for the @ResourceTags@ field, the filter
-- @Department EQUALS Security@ matches findings that have the value
-- @Security@ for the tag @Department@.
--
-- To search for values other than the filter value, use @NOT_EQUALS@. For
-- example, for the @ResourceTags@ field, the filter
-- @Department NOT_EQUALS Finance@ matches findings that do not have the
-- value @Finance@ for the tag @Department@.
--
-- @EQUALS@ filters on the same field are joined by @OR@. A finding matches
-- if it matches any one of those filters.
--
-- @NOT_EQUALS@ filters on the same field are joined by @AND@. A finding
-- matches only if it matches all of those filters.
--
-- You cannot have both an @EQUALS@ filter and a @NOT_EQUALS@ filter on the
-- same field.
--
-- 'key', 'mapFilter_key' - The key of the map filter. For example, for @ResourceTags@, @Key@
-- identifies the name of the tag. For @UserDefinedFields@, @Key@ is the
-- name of the field.
newMapFilter ::
  MapFilter
newMapFilter :: MapFilter
newMapFilter =
  MapFilter' :: Maybe Text -> Maybe MapFilterComparison -> Maybe Text -> MapFilter
MapFilter'
    { $sel:value:MapFilter' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:comparison:MapFilter' :: Maybe MapFilterComparison
comparison = Maybe MapFilterComparison
forall a. Maybe a
Prelude.Nothing,
      $sel:key:MapFilter' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The value for the key in the map filter. Filter values are case
-- sensitive. For example, one of the values for a tag called @Department@
-- might be @Security@. If you provide @security@ as the filter value, then
-- there is no match.
mapFilter_value :: Lens.Lens' MapFilter (Prelude.Maybe Prelude.Text)
mapFilter_value :: (Maybe Text -> f (Maybe Text)) -> MapFilter -> f MapFilter
mapFilter_value = (MapFilter -> Maybe Text)
-> (MapFilter -> Maybe Text -> MapFilter)
-> Lens MapFilter MapFilter (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MapFilter' {Maybe Text
value :: Maybe Text
$sel:value:MapFilter' :: MapFilter -> Maybe Text
value} -> Maybe Text
value) (\s :: MapFilter
s@MapFilter' {} Maybe Text
a -> MapFilter
s {$sel:value:MapFilter' :: Maybe Text
value = Maybe Text
a} :: MapFilter)

-- | The condition to apply to the key value when querying for findings with
-- a map filter.
--
-- To search for values that exactly match the filter value, use @EQUALS@.
-- For example, for the @ResourceTags@ field, the filter
-- @Department EQUALS Security@ matches findings that have the value
-- @Security@ for the tag @Department@.
--
-- To search for values other than the filter value, use @NOT_EQUALS@. For
-- example, for the @ResourceTags@ field, the filter
-- @Department NOT_EQUALS Finance@ matches findings that do not have the
-- value @Finance@ for the tag @Department@.
--
-- @EQUALS@ filters on the same field are joined by @OR@. A finding matches
-- if it matches any one of those filters.
--
-- @NOT_EQUALS@ filters on the same field are joined by @AND@. A finding
-- matches only if it matches all of those filters.
--
-- You cannot have both an @EQUALS@ filter and a @NOT_EQUALS@ filter on the
-- same field.
mapFilter_comparison :: Lens.Lens' MapFilter (Prelude.Maybe MapFilterComparison)
mapFilter_comparison :: (Maybe MapFilterComparison -> f (Maybe MapFilterComparison))
-> MapFilter -> f MapFilter
mapFilter_comparison = (MapFilter -> Maybe MapFilterComparison)
-> (MapFilter -> Maybe MapFilterComparison -> MapFilter)
-> Lens
     MapFilter
     MapFilter
     (Maybe MapFilterComparison)
     (Maybe MapFilterComparison)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MapFilter' {Maybe MapFilterComparison
comparison :: Maybe MapFilterComparison
$sel:comparison:MapFilter' :: MapFilter -> Maybe MapFilterComparison
comparison} -> Maybe MapFilterComparison
comparison) (\s :: MapFilter
s@MapFilter' {} Maybe MapFilterComparison
a -> MapFilter
s {$sel:comparison:MapFilter' :: Maybe MapFilterComparison
comparison = Maybe MapFilterComparison
a} :: MapFilter)

-- | The key of the map filter. For example, for @ResourceTags@, @Key@
-- identifies the name of the tag. For @UserDefinedFields@, @Key@ is the
-- name of the field.
mapFilter_key :: Lens.Lens' MapFilter (Prelude.Maybe Prelude.Text)
mapFilter_key :: (Maybe Text -> f (Maybe Text)) -> MapFilter -> f MapFilter
mapFilter_key = (MapFilter -> Maybe Text)
-> (MapFilter -> Maybe Text -> MapFilter)
-> Lens MapFilter MapFilter (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MapFilter' {Maybe Text
key :: Maybe Text
$sel:key:MapFilter' :: MapFilter -> Maybe Text
key} -> Maybe Text
key) (\s :: MapFilter
s@MapFilter' {} Maybe Text
a -> MapFilter
s {$sel:key:MapFilter' :: Maybe Text
key = Maybe Text
a} :: MapFilter)

instance Core.FromJSON MapFilter where
  parseJSON :: Value -> Parser MapFilter
parseJSON =
    String -> (Object -> Parser MapFilter) -> Value -> Parser MapFilter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MapFilter"
      ( \Object
x ->
          Maybe Text -> Maybe MapFilterComparison -> Maybe Text -> MapFilter
MapFilter'
            (Maybe Text
 -> Maybe MapFilterComparison -> Maybe Text -> MapFilter)
-> Parser (Maybe Text)
-> Parser (Maybe MapFilterComparison -> Maybe Text -> MapFilter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Value")
            Parser (Maybe MapFilterComparison -> Maybe Text -> MapFilter)
-> Parser (Maybe MapFilterComparison)
-> Parser (Maybe Text -> MapFilter)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe MapFilterComparison)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Comparison")
            Parser (Maybe Text -> MapFilter)
-> Parser (Maybe Text) -> Parser MapFilter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Key")
      )

instance Prelude.Hashable MapFilter

instance Prelude.NFData MapFilter

instance Core.ToJSON MapFilter where
  toJSON :: MapFilter -> Value
toJSON MapFilter' {Maybe Text
Maybe MapFilterComparison
key :: Maybe Text
comparison :: Maybe MapFilterComparison
value :: Maybe Text
$sel:key:MapFilter' :: MapFilter -> Maybe Text
$sel:comparison:MapFilter' :: MapFilter -> Maybe MapFilterComparison
$sel:value:MapFilter' :: MapFilter -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            (Text
"Comparison" Text -> MapFilterComparison -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (MapFilterComparison -> Pair)
-> Maybe MapFilterComparison -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MapFilterComparison
comparison,
            (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
key
          ]
      )