{-# 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.StringFilter
-- 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.StringFilter 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.StringComparison
import qualified Amazonka.Prelude as Prelude

-- | An object that describes the details of a string filter.
--
-- /See:/ 'newStringFilter' smart constructor.
data StringFilter = StringFilter'
  { -- | The operator to use when comparing values in the filter.
    StringFilter -> StringComparison
comparison :: StringComparison,
    -- | The value to filter on.
    StringFilter -> Text
value :: Prelude.Text
  }
  deriving (StringFilter -> StringFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StringFilter -> StringFilter -> Bool
$c/= :: StringFilter -> StringFilter -> Bool
== :: StringFilter -> StringFilter -> Bool
$c== :: StringFilter -> StringFilter -> Bool
Prelude.Eq, ReadPrec [StringFilter]
ReadPrec StringFilter
Int -> ReadS StringFilter
ReadS [StringFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StringFilter]
$creadListPrec :: ReadPrec [StringFilter]
readPrec :: ReadPrec StringFilter
$creadPrec :: ReadPrec StringFilter
readList :: ReadS [StringFilter]
$creadList :: ReadS [StringFilter]
readsPrec :: Int -> ReadS StringFilter
$creadsPrec :: Int -> ReadS StringFilter
Prelude.Read, Int -> StringFilter -> ShowS
[StringFilter] -> ShowS
StringFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StringFilter] -> ShowS
$cshowList :: [StringFilter] -> ShowS
show :: StringFilter -> String
$cshow :: StringFilter -> String
showsPrec :: Int -> StringFilter -> ShowS
$cshowsPrec :: Int -> StringFilter -> ShowS
Prelude.Show, forall x. Rep StringFilter x -> StringFilter
forall x. StringFilter -> Rep StringFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StringFilter x -> StringFilter
$cfrom :: forall x. StringFilter -> Rep StringFilter x
Prelude.Generic)

-- |
-- Create a value of 'StringFilter' 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:
--
-- 'comparison', 'stringFilter_comparison' - The operator to use when comparing values in the filter.
--
-- 'value', 'stringFilter_value' - The value to filter on.
newStringFilter ::
  -- | 'comparison'
  StringComparison ->
  -- | 'value'
  Prelude.Text ->
  StringFilter
newStringFilter :: StringComparison -> Text -> StringFilter
newStringFilter StringComparison
pComparison_ Text
pValue_ =
  StringFilter'
    { $sel:comparison:StringFilter' :: StringComparison
comparison = StringComparison
pComparison_,
      $sel:value:StringFilter' :: Text
value = Text
pValue_
    }

-- | The operator to use when comparing values in the filter.
stringFilter_comparison :: Lens.Lens' StringFilter StringComparison
stringFilter_comparison :: Lens' StringFilter StringComparison
stringFilter_comparison = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StringFilter' {StringComparison
comparison :: StringComparison
$sel:comparison:StringFilter' :: StringFilter -> StringComparison
comparison} -> StringComparison
comparison) (\s :: StringFilter
s@StringFilter' {} StringComparison
a -> StringFilter
s {$sel:comparison:StringFilter' :: StringComparison
comparison = StringComparison
a} :: StringFilter)

-- | The value to filter on.
stringFilter_value :: Lens.Lens' StringFilter Prelude.Text
stringFilter_value :: Lens' StringFilter Text
stringFilter_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StringFilter' {Text
value :: Text
$sel:value:StringFilter' :: StringFilter -> Text
value} -> Text
value) (\s :: StringFilter
s@StringFilter' {} Text
a -> StringFilter
s {$sel:value:StringFilter' :: Text
value = Text
a} :: StringFilter)

instance Data.FromJSON StringFilter where
  parseJSON :: Value -> Parser StringFilter
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"StringFilter"
      ( \Object
x ->
          StringComparison -> Text -> StringFilter
StringFilter'
            forall (f :: * -> *) a b. Functor 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
"value")
      )

instance Prelude.Hashable StringFilter where
  hashWithSalt :: Int -> StringFilter -> Int
hashWithSalt Int
_salt StringFilter' {Text
StringComparison
value :: Text
comparison :: StringComparison
$sel:value:StringFilter' :: StringFilter -> Text
$sel:comparison:StringFilter' :: StringFilter -> StringComparison
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` StringComparison
comparison
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

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

instance Data.ToJSON StringFilter where
  toJSON :: StringFilter -> Value
toJSON StringFilter' {Text
StringComparison
value :: Text
comparison :: StringComparison
$sel:value:StringFilter' :: StringFilter -> Text
$sel:comparison:StringFilter' :: StringFilter -> StringComparison
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"comparison" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= StringComparison
comparison),
            forall a. a -> Maybe a
Prelude.Just (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value)
          ]
      )