{-# 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.S3JobDefinition
-- 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.S3JobDefinition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MacieV2.Types.S3BucketCriteriaForJob
import Amazonka.MacieV2.Types.S3BucketDefinitionForJob
import Amazonka.MacieV2.Types.Scoping
import qualified Amazonka.Prelude as Prelude

-- | Specifies which S3 buckets contain the objects that a classification job
-- analyzes, and the scope of that analysis. The bucket specification can
-- be static (bucketDefinitions) or dynamic (bucketCriteria). If it\'s
-- static, the job analyzes objects in the same predefined set of buckets
-- each time the job runs. If it\'s dynamic, the job analyzes objects in
-- any buckets that match the specified criteria each time the job starts
-- to run.
--
-- /See:/ 'newS3JobDefinition' smart constructor.
data S3JobDefinition = S3JobDefinition'
  { -- | The property- and tag-based conditions that determine which S3 objects
    -- to include or exclude from the analysis. Each time the job runs, the job
    -- uses these criteria to determine which objects to analyze.
    S3JobDefinition -> Maybe Scoping
scoping :: Prelude.Maybe Scoping,
    -- | The property- and tag-based conditions that determine which S3 buckets
    -- to include or exclude from the analysis. Each time the job runs, the job
    -- uses these criteria to determine which buckets contain objects to
    -- analyze. A job\'s definition can contain a bucketCriteria object or a
    -- bucketDefinitions array, not both.
    S3JobDefinition -> Maybe S3BucketCriteriaForJob
bucketCriteria :: Prelude.Maybe S3BucketCriteriaForJob,
    -- | An array of objects, one for each Amazon Web Services account that owns
    -- specific S3 buckets to analyze. Each object specifies the account ID for
    -- an account and one or more buckets to analyze for that account. A job\'s
    -- definition can contain a bucketDefinitions array or a bucketCriteria
    -- object, not both.
    S3JobDefinition -> Maybe [S3BucketDefinitionForJob]
bucketDefinitions :: Prelude.Maybe [S3BucketDefinitionForJob]
  }
  deriving (S3JobDefinition -> S3JobDefinition -> Bool
(S3JobDefinition -> S3JobDefinition -> Bool)
-> (S3JobDefinition -> S3JobDefinition -> Bool)
-> Eq S3JobDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3JobDefinition -> S3JobDefinition -> Bool
$c/= :: S3JobDefinition -> S3JobDefinition -> Bool
== :: S3JobDefinition -> S3JobDefinition -> Bool
$c== :: S3JobDefinition -> S3JobDefinition -> Bool
Prelude.Eq, ReadPrec [S3JobDefinition]
ReadPrec S3JobDefinition
Int -> ReadS S3JobDefinition
ReadS [S3JobDefinition]
(Int -> ReadS S3JobDefinition)
-> ReadS [S3JobDefinition]
-> ReadPrec S3JobDefinition
-> ReadPrec [S3JobDefinition]
-> Read S3JobDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3JobDefinition]
$creadListPrec :: ReadPrec [S3JobDefinition]
readPrec :: ReadPrec S3JobDefinition
$creadPrec :: ReadPrec S3JobDefinition
readList :: ReadS [S3JobDefinition]
$creadList :: ReadS [S3JobDefinition]
readsPrec :: Int -> ReadS S3JobDefinition
$creadsPrec :: Int -> ReadS S3JobDefinition
Prelude.Read, Int -> S3JobDefinition -> ShowS
[S3JobDefinition] -> ShowS
S3JobDefinition -> String
(Int -> S3JobDefinition -> ShowS)
-> (S3JobDefinition -> String)
-> ([S3JobDefinition] -> ShowS)
-> Show S3JobDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3JobDefinition] -> ShowS
$cshowList :: [S3JobDefinition] -> ShowS
show :: S3JobDefinition -> String
$cshow :: S3JobDefinition -> String
showsPrec :: Int -> S3JobDefinition -> ShowS
$cshowsPrec :: Int -> S3JobDefinition -> ShowS
Prelude.Show, (forall x. S3JobDefinition -> Rep S3JobDefinition x)
-> (forall x. Rep S3JobDefinition x -> S3JobDefinition)
-> Generic S3JobDefinition
forall x. Rep S3JobDefinition x -> S3JobDefinition
forall x. S3JobDefinition -> Rep S3JobDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep S3JobDefinition x -> S3JobDefinition
$cfrom :: forall x. S3JobDefinition -> Rep S3JobDefinition x
Prelude.Generic)

-- |
-- Create a value of 'S3JobDefinition' 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:
--
-- 'scoping', 's3JobDefinition_scoping' - The property- and tag-based conditions that determine which S3 objects
-- to include or exclude from the analysis. Each time the job runs, the job
-- uses these criteria to determine which objects to analyze.
--
-- 'bucketCriteria', 's3JobDefinition_bucketCriteria' - The property- and tag-based conditions that determine which S3 buckets
-- to include or exclude from the analysis. Each time the job runs, the job
-- uses these criteria to determine which buckets contain objects to
-- analyze. A job\'s definition can contain a bucketCriteria object or a
-- bucketDefinitions array, not both.
--
-- 'bucketDefinitions', 's3JobDefinition_bucketDefinitions' - An array of objects, one for each Amazon Web Services account that owns
-- specific S3 buckets to analyze. Each object specifies the account ID for
-- an account and one or more buckets to analyze for that account. A job\'s
-- definition can contain a bucketDefinitions array or a bucketCriteria
-- object, not both.
newS3JobDefinition ::
  S3JobDefinition
newS3JobDefinition :: S3JobDefinition
newS3JobDefinition =
  S3JobDefinition' :: Maybe Scoping
-> Maybe S3BucketCriteriaForJob
-> Maybe [S3BucketDefinitionForJob]
-> S3JobDefinition
S3JobDefinition'
    { $sel:scoping:S3JobDefinition' :: Maybe Scoping
scoping = Maybe Scoping
forall a. Maybe a
Prelude.Nothing,
      $sel:bucketCriteria:S3JobDefinition' :: Maybe S3BucketCriteriaForJob
bucketCriteria = Maybe S3BucketCriteriaForJob
forall a. Maybe a
Prelude.Nothing,
      $sel:bucketDefinitions:S3JobDefinition' :: Maybe [S3BucketDefinitionForJob]
bucketDefinitions = Maybe [S3BucketDefinitionForJob]
forall a. Maybe a
Prelude.Nothing
    }

-- | The property- and tag-based conditions that determine which S3 objects
-- to include or exclude from the analysis. Each time the job runs, the job
-- uses these criteria to determine which objects to analyze.
s3JobDefinition_scoping :: Lens.Lens' S3JobDefinition (Prelude.Maybe Scoping)
s3JobDefinition_scoping :: (Maybe Scoping -> f (Maybe Scoping))
-> S3JobDefinition -> f S3JobDefinition
s3JobDefinition_scoping = (S3JobDefinition -> Maybe Scoping)
-> (S3JobDefinition -> Maybe Scoping -> S3JobDefinition)
-> Lens
     S3JobDefinition S3JobDefinition (Maybe Scoping) (Maybe Scoping)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3JobDefinition' {Maybe Scoping
scoping :: Maybe Scoping
$sel:scoping:S3JobDefinition' :: S3JobDefinition -> Maybe Scoping
scoping} -> Maybe Scoping
scoping) (\s :: S3JobDefinition
s@S3JobDefinition' {} Maybe Scoping
a -> S3JobDefinition
s {$sel:scoping:S3JobDefinition' :: Maybe Scoping
scoping = Maybe Scoping
a} :: S3JobDefinition)

-- | The property- and tag-based conditions that determine which S3 buckets
-- to include or exclude from the analysis. Each time the job runs, the job
-- uses these criteria to determine which buckets contain objects to
-- analyze. A job\'s definition can contain a bucketCriteria object or a
-- bucketDefinitions array, not both.
s3JobDefinition_bucketCriteria :: Lens.Lens' S3JobDefinition (Prelude.Maybe S3BucketCriteriaForJob)
s3JobDefinition_bucketCriteria :: (Maybe S3BucketCriteriaForJob -> f (Maybe S3BucketCriteriaForJob))
-> S3JobDefinition -> f S3JobDefinition
s3JobDefinition_bucketCriteria = (S3JobDefinition -> Maybe S3BucketCriteriaForJob)
-> (S3JobDefinition
    -> Maybe S3BucketCriteriaForJob -> S3JobDefinition)
-> Lens
     S3JobDefinition
     S3JobDefinition
     (Maybe S3BucketCriteriaForJob)
     (Maybe S3BucketCriteriaForJob)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3JobDefinition' {Maybe S3BucketCriteriaForJob
bucketCriteria :: Maybe S3BucketCriteriaForJob
$sel:bucketCriteria:S3JobDefinition' :: S3JobDefinition -> Maybe S3BucketCriteriaForJob
bucketCriteria} -> Maybe S3BucketCriteriaForJob
bucketCriteria) (\s :: S3JobDefinition
s@S3JobDefinition' {} Maybe S3BucketCriteriaForJob
a -> S3JobDefinition
s {$sel:bucketCriteria:S3JobDefinition' :: Maybe S3BucketCriteriaForJob
bucketCriteria = Maybe S3BucketCriteriaForJob
a} :: S3JobDefinition)

-- | An array of objects, one for each Amazon Web Services account that owns
-- specific S3 buckets to analyze. Each object specifies the account ID for
-- an account and one or more buckets to analyze for that account. A job\'s
-- definition can contain a bucketDefinitions array or a bucketCriteria
-- object, not both.
s3JobDefinition_bucketDefinitions :: Lens.Lens' S3JobDefinition (Prelude.Maybe [S3BucketDefinitionForJob])
s3JobDefinition_bucketDefinitions :: (Maybe [S3BucketDefinitionForJob]
 -> f (Maybe [S3BucketDefinitionForJob]))
-> S3JobDefinition -> f S3JobDefinition
s3JobDefinition_bucketDefinitions = (S3JobDefinition -> Maybe [S3BucketDefinitionForJob])
-> (S3JobDefinition
    -> Maybe [S3BucketDefinitionForJob] -> S3JobDefinition)
-> Lens
     S3JobDefinition
     S3JobDefinition
     (Maybe [S3BucketDefinitionForJob])
     (Maybe [S3BucketDefinitionForJob])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3JobDefinition' {Maybe [S3BucketDefinitionForJob]
bucketDefinitions :: Maybe [S3BucketDefinitionForJob]
$sel:bucketDefinitions:S3JobDefinition' :: S3JobDefinition -> Maybe [S3BucketDefinitionForJob]
bucketDefinitions} -> Maybe [S3BucketDefinitionForJob]
bucketDefinitions) (\s :: S3JobDefinition
s@S3JobDefinition' {} Maybe [S3BucketDefinitionForJob]
a -> S3JobDefinition
s {$sel:bucketDefinitions:S3JobDefinition' :: Maybe [S3BucketDefinitionForJob]
bucketDefinitions = Maybe [S3BucketDefinitionForJob]
a} :: S3JobDefinition) ((Maybe [S3BucketDefinitionForJob]
  -> f (Maybe [S3BucketDefinitionForJob]))
 -> S3JobDefinition -> f S3JobDefinition)
-> ((Maybe [S3BucketDefinitionForJob]
     -> f (Maybe [S3BucketDefinitionForJob]))
    -> Maybe [S3BucketDefinitionForJob]
    -> f (Maybe [S3BucketDefinitionForJob]))
-> (Maybe [S3BucketDefinitionForJob]
    -> f (Maybe [S3BucketDefinitionForJob]))
-> S3JobDefinition
-> f S3JobDefinition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [S3BucketDefinitionForJob]
  [S3BucketDefinitionForJob]
  [S3BucketDefinitionForJob]
  [S3BucketDefinitionForJob]
-> Iso
     (Maybe [S3BucketDefinitionForJob])
     (Maybe [S3BucketDefinitionForJob])
     (Maybe [S3BucketDefinitionForJob])
     (Maybe [S3BucketDefinitionForJob])
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
  [S3BucketDefinitionForJob]
  [S3BucketDefinitionForJob]
  [S3BucketDefinitionForJob]
  [S3BucketDefinitionForJob]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON S3JobDefinition where
  parseJSON :: Value -> Parser S3JobDefinition
parseJSON =
    String
-> (Object -> Parser S3JobDefinition)
-> Value
-> Parser S3JobDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"S3JobDefinition"
      ( \Object
x ->
          Maybe Scoping
-> Maybe S3BucketCriteriaForJob
-> Maybe [S3BucketDefinitionForJob]
-> S3JobDefinition
S3JobDefinition'
            (Maybe Scoping
 -> Maybe S3BucketCriteriaForJob
 -> Maybe [S3BucketDefinitionForJob]
 -> S3JobDefinition)
-> Parser (Maybe Scoping)
-> Parser
     (Maybe S3BucketCriteriaForJob
      -> Maybe [S3BucketDefinitionForJob] -> S3JobDefinition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Scoping)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"scoping")
            Parser
  (Maybe S3BucketCriteriaForJob
   -> Maybe [S3BucketDefinitionForJob] -> S3JobDefinition)
-> Parser (Maybe S3BucketCriteriaForJob)
-> Parser (Maybe [S3BucketDefinitionForJob] -> S3JobDefinition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe S3BucketCriteriaForJob)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"bucketCriteria")
            Parser (Maybe [S3BucketDefinitionForJob] -> S3JobDefinition)
-> Parser (Maybe [S3BucketDefinitionForJob])
-> Parser S3JobDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [S3BucketDefinitionForJob]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"bucketDefinitions"
                            Parser (Maybe (Maybe [S3BucketDefinitionForJob]))
-> Maybe [S3BucketDefinitionForJob]
-> Parser (Maybe [S3BucketDefinitionForJob])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [S3BucketDefinitionForJob]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable S3JobDefinition

instance Prelude.NFData S3JobDefinition

instance Core.ToJSON S3JobDefinition where
  toJSON :: S3JobDefinition -> Value
toJSON S3JobDefinition' {Maybe [S3BucketDefinitionForJob]
Maybe S3BucketCriteriaForJob
Maybe Scoping
bucketDefinitions :: Maybe [S3BucketDefinitionForJob]
bucketCriteria :: Maybe S3BucketCriteriaForJob
scoping :: Maybe Scoping
$sel:bucketDefinitions:S3JobDefinition' :: S3JobDefinition -> Maybe [S3BucketDefinitionForJob]
$sel:bucketCriteria:S3JobDefinition' :: S3JobDefinition -> Maybe S3BucketCriteriaForJob
$sel:scoping:S3JobDefinition' :: S3JobDefinition -> Maybe Scoping
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"scoping" Text -> Scoping -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Scoping -> Pair) -> Maybe Scoping -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Scoping
scoping,
            (Text
"bucketCriteria" Text -> S3BucketCriteriaForJob -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (S3BucketCriteriaForJob -> Pair)
-> Maybe S3BucketCriteriaForJob -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe S3BucketCriteriaForJob
bucketCriteria,
            (Text
"bucketDefinitions" Text -> [S3BucketDefinitionForJob] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([S3BucketDefinitionForJob] -> Pair)
-> Maybe [S3BucketDefinitionForJob] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [S3BucketDefinitionForJob]
bucketDefinitions
          ]
      )