{-# 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.MacieV2.Types.SimpleScopeTerm
-- 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.MacieV2.Types.SimpleScopeTerm where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MacieV2.Types.JobComparator
import Amazonka.MacieV2.Types.ScopeFilterKey
import qualified Amazonka.Prelude as Prelude

-- | Specifies a property-based condition that determines whether an S3
-- object is included or excluded from a classification job.
--
-- /See:/ 'newSimpleScopeTerm' smart constructor.
data SimpleScopeTerm = SimpleScopeTerm'
  { -- | An array that lists the values to use in the condition. If the value for
    -- the key property is OBJECT_EXTENSION or OBJECT_KEY, this array can
    -- specify multiple values and Amazon Macie uses OR logic to join the
    -- values. Otherwise, this array can specify only one value.
    --
    -- Valid values for each supported property (key) are:
    --
    -- -   OBJECT_EXTENSION - A string that represents the file name extension
    --     of an object. For example: docx or pdf
    --
    -- -   OBJECT_KEY - A string that represents the key prefix (folder name or
    --     path) of an object. For example: logs or awslogs\/eventlogs. This
    --     value applies a condition to objects whose keys (names) begin with
    --     the specified value.
    --
    -- -   OBJECT_LAST_MODIFIED_DATE - The date and time (in UTC and extended
    --     ISO 8601 format) when an object was created or last changed,
    --     whichever is latest. For example: 2020-09-28T14:31:13Z
    --
    -- -   OBJECT_SIZE - An integer that represents the storage size (in bytes)
    --     of an object.
    --
    -- Macie doesn\'t support use of wildcard characters in these values. Also,
    -- string values are case sensitive.
    SimpleScopeTerm -> Maybe [Text]
values :: Prelude.Maybe [Prelude.Text],
    -- | The object property to use in the condition.
    SimpleScopeTerm -> Maybe ScopeFilterKey
key :: Prelude.Maybe ScopeFilterKey,
    -- | The operator to use in the condition. Valid values for each supported
    -- property (key) are:
    --
    -- -   OBJECT_EXTENSION - EQ (equals) or NE (not equals)
    --
    -- -   OBJECT_KEY - STARTS_WITH
    --
    -- -   OBJECT_LAST_MODIFIED_DATE - Any operator except CONTAINS
    --
    -- -   OBJECT_SIZE - Any operator except CONTAINS
    SimpleScopeTerm -> Maybe JobComparator
comparator :: Prelude.Maybe JobComparator
  }
  deriving (SimpleScopeTerm -> SimpleScopeTerm -> Bool
(SimpleScopeTerm -> SimpleScopeTerm -> Bool)
-> (SimpleScopeTerm -> SimpleScopeTerm -> Bool)
-> Eq SimpleScopeTerm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleScopeTerm -> SimpleScopeTerm -> Bool
$c/= :: SimpleScopeTerm -> SimpleScopeTerm -> Bool
== :: SimpleScopeTerm -> SimpleScopeTerm -> Bool
$c== :: SimpleScopeTerm -> SimpleScopeTerm -> Bool
Prelude.Eq, ReadPrec [SimpleScopeTerm]
ReadPrec SimpleScopeTerm
Int -> ReadS SimpleScopeTerm
ReadS [SimpleScopeTerm]
(Int -> ReadS SimpleScopeTerm)
-> ReadS [SimpleScopeTerm]
-> ReadPrec SimpleScopeTerm
-> ReadPrec [SimpleScopeTerm]
-> Read SimpleScopeTerm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SimpleScopeTerm]
$creadListPrec :: ReadPrec [SimpleScopeTerm]
readPrec :: ReadPrec SimpleScopeTerm
$creadPrec :: ReadPrec SimpleScopeTerm
readList :: ReadS [SimpleScopeTerm]
$creadList :: ReadS [SimpleScopeTerm]
readsPrec :: Int -> ReadS SimpleScopeTerm
$creadsPrec :: Int -> ReadS SimpleScopeTerm
Prelude.Read, Int -> SimpleScopeTerm -> ShowS
[SimpleScopeTerm] -> ShowS
SimpleScopeTerm -> String
(Int -> SimpleScopeTerm -> ShowS)
-> (SimpleScopeTerm -> String)
-> ([SimpleScopeTerm] -> ShowS)
-> Show SimpleScopeTerm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleScopeTerm] -> ShowS
$cshowList :: [SimpleScopeTerm] -> ShowS
show :: SimpleScopeTerm -> String
$cshow :: SimpleScopeTerm -> String
showsPrec :: Int -> SimpleScopeTerm -> ShowS
$cshowsPrec :: Int -> SimpleScopeTerm -> ShowS
Prelude.Show, (forall x. SimpleScopeTerm -> Rep SimpleScopeTerm x)
-> (forall x. Rep SimpleScopeTerm x -> SimpleScopeTerm)
-> Generic SimpleScopeTerm
forall x. Rep SimpleScopeTerm x -> SimpleScopeTerm
forall x. SimpleScopeTerm -> Rep SimpleScopeTerm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SimpleScopeTerm x -> SimpleScopeTerm
$cfrom :: forall x. SimpleScopeTerm -> Rep SimpleScopeTerm x
Prelude.Generic)

-- |
-- Create a value of 'SimpleScopeTerm' 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:
--
-- 'values', 'simpleScopeTerm_values' - An array that lists the values to use in the condition. If the value for
-- the key property is OBJECT_EXTENSION or OBJECT_KEY, this array can
-- specify multiple values and Amazon Macie uses OR logic to join the
-- values. Otherwise, this array can specify only one value.
--
-- Valid values for each supported property (key) are:
--
-- -   OBJECT_EXTENSION - A string that represents the file name extension
--     of an object. For example: docx or pdf
--
-- -   OBJECT_KEY - A string that represents the key prefix (folder name or
--     path) of an object. For example: logs or awslogs\/eventlogs. This
--     value applies a condition to objects whose keys (names) begin with
--     the specified value.
--
-- -   OBJECT_LAST_MODIFIED_DATE - The date and time (in UTC and extended
--     ISO 8601 format) when an object was created or last changed,
--     whichever is latest. For example: 2020-09-28T14:31:13Z
--
-- -   OBJECT_SIZE - An integer that represents the storage size (in bytes)
--     of an object.
--
-- Macie doesn\'t support use of wildcard characters in these values. Also,
-- string values are case sensitive.
--
-- 'key', 'simpleScopeTerm_key' - The object property to use in the condition.
--
-- 'comparator', 'simpleScopeTerm_comparator' - The operator to use in the condition. Valid values for each supported
-- property (key) are:
--
-- -   OBJECT_EXTENSION - EQ (equals) or NE (not equals)
--
-- -   OBJECT_KEY - STARTS_WITH
--
-- -   OBJECT_LAST_MODIFIED_DATE - Any operator except CONTAINS
--
-- -   OBJECT_SIZE - Any operator except CONTAINS
newSimpleScopeTerm ::
  SimpleScopeTerm
newSimpleScopeTerm :: SimpleScopeTerm
newSimpleScopeTerm =
  SimpleScopeTerm' :: Maybe [Text]
-> Maybe ScopeFilterKey -> Maybe JobComparator -> SimpleScopeTerm
SimpleScopeTerm'
    { $sel:values:SimpleScopeTerm' :: Maybe [Text]
values = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:key:SimpleScopeTerm' :: Maybe ScopeFilterKey
key = Maybe ScopeFilterKey
forall a. Maybe a
Prelude.Nothing,
      $sel:comparator:SimpleScopeTerm' :: Maybe JobComparator
comparator = Maybe JobComparator
forall a. Maybe a
Prelude.Nothing
    }

-- | An array that lists the values to use in the condition. If the value for
-- the key property is OBJECT_EXTENSION or OBJECT_KEY, this array can
-- specify multiple values and Amazon Macie uses OR logic to join the
-- values. Otherwise, this array can specify only one value.
--
-- Valid values for each supported property (key) are:
--
-- -   OBJECT_EXTENSION - A string that represents the file name extension
--     of an object. For example: docx or pdf
--
-- -   OBJECT_KEY - A string that represents the key prefix (folder name or
--     path) of an object. For example: logs or awslogs\/eventlogs. This
--     value applies a condition to objects whose keys (names) begin with
--     the specified value.
--
-- -   OBJECT_LAST_MODIFIED_DATE - The date and time (in UTC and extended
--     ISO 8601 format) when an object was created or last changed,
--     whichever is latest. For example: 2020-09-28T14:31:13Z
--
-- -   OBJECT_SIZE - An integer that represents the storage size (in bytes)
--     of an object.
--
-- Macie doesn\'t support use of wildcard characters in these values. Also,
-- string values are case sensitive.
simpleScopeTerm_values :: Lens.Lens' SimpleScopeTerm (Prelude.Maybe [Prelude.Text])
simpleScopeTerm_values :: (Maybe [Text] -> f (Maybe [Text]))
-> SimpleScopeTerm -> f SimpleScopeTerm
simpleScopeTerm_values = (SimpleScopeTerm -> Maybe [Text])
-> (SimpleScopeTerm -> Maybe [Text] -> SimpleScopeTerm)
-> Lens
     SimpleScopeTerm SimpleScopeTerm (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleScopeTerm' {Maybe [Text]
values :: Maybe [Text]
$sel:values:SimpleScopeTerm' :: SimpleScopeTerm -> Maybe [Text]
values} -> Maybe [Text]
values) (\s :: SimpleScopeTerm
s@SimpleScopeTerm' {} Maybe [Text]
a -> SimpleScopeTerm
s {$sel:values:SimpleScopeTerm' :: Maybe [Text]
values = Maybe [Text]
a} :: SimpleScopeTerm) ((Maybe [Text] -> f (Maybe [Text]))
 -> SimpleScopeTerm -> f SimpleScopeTerm)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> SimpleScopeTerm
-> f SimpleScopeTerm
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The object property to use in the condition.
simpleScopeTerm_key :: Lens.Lens' SimpleScopeTerm (Prelude.Maybe ScopeFilterKey)
simpleScopeTerm_key :: (Maybe ScopeFilterKey -> f (Maybe ScopeFilterKey))
-> SimpleScopeTerm -> f SimpleScopeTerm
simpleScopeTerm_key = (SimpleScopeTerm -> Maybe ScopeFilterKey)
-> (SimpleScopeTerm -> Maybe ScopeFilterKey -> SimpleScopeTerm)
-> Lens
     SimpleScopeTerm
     SimpleScopeTerm
     (Maybe ScopeFilterKey)
     (Maybe ScopeFilterKey)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleScopeTerm' {Maybe ScopeFilterKey
key :: Maybe ScopeFilterKey
$sel:key:SimpleScopeTerm' :: SimpleScopeTerm -> Maybe ScopeFilterKey
key} -> Maybe ScopeFilterKey
key) (\s :: SimpleScopeTerm
s@SimpleScopeTerm' {} Maybe ScopeFilterKey
a -> SimpleScopeTerm
s {$sel:key:SimpleScopeTerm' :: Maybe ScopeFilterKey
key = Maybe ScopeFilterKey
a} :: SimpleScopeTerm)

-- | The operator to use in the condition. Valid values for each supported
-- property (key) are:
--
-- -   OBJECT_EXTENSION - EQ (equals) or NE (not equals)
--
-- -   OBJECT_KEY - STARTS_WITH
--
-- -   OBJECT_LAST_MODIFIED_DATE - Any operator except CONTAINS
--
-- -   OBJECT_SIZE - Any operator except CONTAINS
simpleScopeTerm_comparator :: Lens.Lens' SimpleScopeTerm (Prelude.Maybe JobComparator)
simpleScopeTerm_comparator :: (Maybe JobComparator -> f (Maybe JobComparator))
-> SimpleScopeTerm -> f SimpleScopeTerm
simpleScopeTerm_comparator = (SimpleScopeTerm -> Maybe JobComparator)
-> (SimpleScopeTerm -> Maybe JobComparator -> SimpleScopeTerm)
-> Lens
     SimpleScopeTerm
     SimpleScopeTerm
     (Maybe JobComparator)
     (Maybe JobComparator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleScopeTerm' {Maybe JobComparator
comparator :: Maybe JobComparator
$sel:comparator:SimpleScopeTerm' :: SimpleScopeTerm -> Maybe JobComparator
comparator} -> Maybe JobComparator
comparator) (\s :: SimpleScopeTerm
s@SimpleScopeTerm' {} Maybe JobComparator
a -> SimpleScopeTerm
s {$sel:comparator:SimpleScopeTerm' :: Maybe JobComparator
comparator = Maybe JobComparator
a} :: SimpleScopeTerm)

instance Core.FromJSON SimpleScopeTerm where
  parseJSON :: Value -> Parser SimpleScopeTerm
parseJSON =
    String
-> (Object -> Parser SimpleScopeTerm)
-> Value
-> Parser SimpleScopeTerm
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SimpleScopeTerm"
      ( \Object
x ->
          Maybe [Text]
-> Maybe ScopeFilterKey -> Maybe JobComparator -> SimpleScopeTerm
SimpleScopeTerm'
            (Maybe [Text]
 -> Maybe ScopeFilterKey -> Maybe JobComparator -> SimpleScopeTerm)
-> Parser (Maybe [Text])
-> Parser
     (Maybe ScopeFilterKey -> Maybe JobComparator -> SimpleScopeTerm)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"values" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe ScopeFilterKey -> Maybe JobComparator -> SimpleScopeTerm)
-> Parser (Maybe ScopeFilterKey)
-> Parser (Maybe JobComparator -> SimpleScopeTerm)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ScopeFilterKey)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"key")
            Parser (Maybe JobComparator -> SimpleScopeTerm)
-> Parser (Maybe JobComparator) -> Parser SimpleScopeTerm
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe JobComparator)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"comparator")
      )

instance Prelude.Hashable SimpleScopeTerm

instance Prelude.NFData SimpleScopeTerm

instance Core.ToJSON SimpleScopeTerm where
  toJSON :: SimpleScopeTerm -> Value
toJSON SimpleScopeTerm' {Maybe [Text]
Maybe JobComparator
Maybe ScopeFilterKey
comparator :: Maybe JobComparator
key :: Maybe ScopeFilterKey
values :: Maybe [Text]
$sel:comparator:SimpleScopeTerm' :: SimpleScopeTerm -> Maybe JobComparator
$sel:key:SimpleScopeTerm' :: SimpleScopeTerm -> Maybe ScopeFilterKey
$sel:values:SimpleScopeTerm' :: SimpleScopeTerm -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"values" 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]
values,
            (Text
"key" Text -> ScopeFilterKey -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ScopeFilterKey -> Pair) -> Maybe ScopeFilterKey -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ScopeFilterKey
key,
            (Text
"comparator" Text -> JobComparator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (JobComparator -> Pair) -> Maybe JobComparator -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe JobComparator
comparator
          ]
      )