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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Inspector2.Types.MapComparison
import qualified Amazonka.Prelude as Prelude

-- | An object that describes details of a map filter.
--
-- /See:/ 'newMapFilter' smart constructor.
data MapFilter = MapFilter'
  { -- | The tag value used in the filter.
    MapFilter -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The operator to use when comparing values in the filter.
    MapFilter -> MapComparison
comparison :: MapComparison,
    -- | The tag key used in the filter.
    MapFilter -> Text
key :: Prelude.Text
  }
  deriving (MapFilter -> MapFilter -> Bool
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]
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
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. 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 tag value used in the filter.
--
-- 'comparison', 'mapFilter_comparison' - The operator to use when comparing values in the filter.
--
-- 'key', 'mapFilter_key' - The tag key used in the filter.
newMapFilter ::
  -- | 'comparison'
  MapComparison ->
  -- | 'key'
  Prelude.Text ->
  MapFilter
newMapFilter :: MapComparison -> Text -> MapFilter
newMapFilter MapComparison
pComparison_ Text
pKey_ =
  MapFilter'
    { $sel:value:MapFilter' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing,
      $sel:comparison:MapFilter' :: MapComparison
comparison = MapComparison
pComparison_,
      $sel:key:MapFilter' :: Text
key = Text
pKey_
    }

-- | The tag value used in the filter.
mapFilter_value :: Lens.Lens' MapFilter (Prelude.Maybe Prelude.Text)
mapFilter_value :: Lens' MapFilter (Maybe Text)
mapFilter_value = 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 operator to use when comparing values in the filter.
mapFilter_comparison :: Lens.Lens' MapFilter MapComparison
mapFilter_comparison :: Lens' MapFilter MapComparison
mapFilter_comparison = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MapFilter' {MapComparison
comparison :: MapComparison
$sel:comparison:MapFilter' :: MapFilter -> MapComparison
comparison} -> MapComparison
comparison) (\s :: MapFilter
s@MapFilter' {} MapComparison
a -> MapFilter
s {$sel:comparison:MapFilter' :: MapComparison
comparison = MapComparison
a} :: MapFilter)

-- | The tag key used in the filter.
mapFilter_key :: Lens.Lens' MapFilter Prelude.Text
mapFilter_key :: Lens' MapFilter Text
mapFilter_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MapFilter' {Text
key :: Text
$sel:key:MapFilter' :: MapFilter -> Text
key} -> Text
key) (\s :: MapFilter
s@MapFilter' {} Text
a -> MapFilter
s {$sel:key:MapFilter' :: Text
key = Text
a} :: MapFilter)

instance Data.FromJSON MapFilter where
  parseJSON :: Value -> Parser MapFilter
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MapFilter"
      ( \Object
x ->
          Maybe Text -> MapComparison -> Text -> MapFilter
MapFilter'
            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
"value")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"comparison")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"key")
      )

instance Prelude.Hashable MapFilter where
  hashWithSalt :: Int -> MapFilter -> Int
hashWithSalt Int
_salt MapFilter' {Maybe Text
Text
MapComparison
key :: Text
comparison :: MapComparison
value :: Maybe Text
$sel:key:MapFilter' :: MapFilter -> Text
$sel:comparison:MapFilter' :: MapFilter -> MapComparison
$sel:value:MapFilter' :: MapFilter -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MapComparison
comparison
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key

instance Prelude.NFData MapFilter where
  rnf :: MapFilter -> ()
rnf MapFilter' {Maybe Text
Text
MapComparison
key :: Text
comparison :: MapComparison
value :: Maybe Text
$sel:key:MapFilter' :: MapFilter -> Text
$sel:comparison:MapFilter' :: MapFilter -> MapComparison
$sel:value:MapFilter' :: MapFilter -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MapComparison
comparison
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key

instance Data.ToJSON MapFilter where
  toJSON :: MapFilter -> Value
toJSON MapFilter' {Maybe Text
Text
MapComparison
key :: Text
comparison :: MapComparison
value :: Maybe Text
$sel:key:MapFilter' :: MapFilter -> Text
$sel:comparison:MapFilter' :: MapFilter -> MapComparison
$sel:value:MapFilter' :: MapFilter -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"value" 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 Text
value,
            forall a. a -> Maybe a
Prelude.Just (Key
"comparison" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= MapComparison
comparison),
            forall a. a -> Maybe a
Prelude.Just (Key
"key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key)
          ]
      )