{-# 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.CloudTrail.Types.AdvancedEventSelector
-- 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.CloudTrail.Types.AdvancedEventSelector where

import Amazonka.CloudTrail.Types.AdvancedFieldSelector
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Advanced event selectors let you create fine-grained selectors for the
-- following CloudTrail event record fields. They help you control costs by
-- logging only those events that are important to you. For more
-- information about advanced event selectors, see
-- <https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html Logging data events for trails>
-- in the /CloudTrail User Guide/.
--
-- -   @readOnly@
--
-- -   @eventSource@
--
-- -   @eventName@
--
-- -   @eventCategory@
--
-- -   @resources.type@
--
-- -   @resources.ARN@
--
-- You cannot apply both event selectors and advanced event selectors to a
-- trail.
--
-- /See:/ 'newAdvancedEventSelector' smart constructor.
data AdvancedEventSelector = AdvancedEventSelector'
  { -- | An optional, descriptive name for an advanced event selector, such as
    -- \"Log data events for only two S3 buckets\".
    AdvancedEventSelector -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | Contains all selector statements in an advanced event selector.
    AdvancedEventSelector -> NonEmpty AdvancedFieldSelector
fieldSelectors :: Prelude.NonEmpty AdvancedFieldSelector
  }
  deriving (AdvancedEventSelector -> AdvancedEventSelector -> Bool
(AdvancedEventSelector -> AdvancedEventSelector -> Bool)
-> (AdvancedEventSelector -> AdvancedEventSelector -> Bool)
-> Eq AdvancedEventSelector
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AdvancedEventSelector -> AdvancedEventSelector -> Bool
$c/= :: AdvancedEventSelector -> AdvancedEventSelector -> Bool
== :: AdvancedEventSelector -> AdvancedEventSelector -> Bool
$c== :: AdvancedEventSelector -> AdvancedEventSelector -> Bool
Prelude.Eq, ReadPrec [AdvancedEventSelector]
ReadPrec AdvancedEventSelector
Int -> ReadS AdvancedEventSelector
ReadS [AdvancedEventSelector]
(Int -> ReadS AdvancedEventSelector)
-> ReadS [AdvancedEventSelector]
-> ReadPrec AdvancedEventSelector
-> ReadPrec [AdvancedEventSelector]
-> Read AdvancedEventSelector
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AdvancedEventSelector]
$creadListPrec :: ReadPrec [AdvancedEventSelector]
readPrec :: ReadPrec AdvancedEventSelector
$creadPrec :: ReadPrec AdvancedEventSelector
readList :: ReadS [AdvancedEventSelector]
$creadList :: ReadS [AdvancedEventSelector]
readsPrec :: Int -> ReadS AdvancedEventSelector
$creadsPrec :: Int -> ReadS AdvancedEventSelector
Prelude.Read, Int -> AdvancedEventSelector -> ShowS
[AdvancedEventSelector] -> ShowS
AdvancedEventSelector -> String
(Int -> AdvancedEventSelector -> ShowS)
-> (AdvancedEventSelector -> String)
-> ([AdvancedEventSelector] -> ShowS)
-> Show AdvancedEventSelector
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AdvancedEventSelector] -> ShowS
$cshowList :: [AdvancedEventSelector] -> ShowS
show :: AdvancedEventSelector -> String
$cshow :: AdvancedEventSelector -> String
showsPrec :: Int -> AdvancedEventSelector -> ShowS
$cshowsPrec :: Int -> AdvancedEventSelector -> ShowS
Prelude.Show, (forall x. AdvancedEventSelector -> Rep AdvancedEventSelector x)
-> (forall x. Rep AdvancedEventSelector x -> AdvancedEventSelector)
-> Generic AdvancedEventSelector
forall x. Rep AdvancedEventSelector x -> AdvancedEventSelector
forall x. AdvancedEventSelector -> Rep AdvancedEventSelector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AdvancedEventSelector x -> AdvancedEventSelector
$cfrom :: forall x. AdvancedEventSelector -> Rep AdvancedEventSelector x
Prelude.Generic)

-- |
-- Create a value of 'AdvancedEventSelector' 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:
--
-- 'name', 'advancedEventSelector_name' - An optional, descriptive name for an advanced event selector, such as
-- \"Log data events for only two S3 buckets\".
--
-- 'fieldSelectors', 'advancedEventSelector_fieldSelectors' - Contains all selector statements in an advanced event selector.
newAdvancedEventSelector ::
  -- | 'fieldSelectors'
  Prelude.NonEmpty AdvancedFieldSelector ->
  AdvancedEventSelector
newAdvancedEventSelector :: NonEmpty AdvancedFieldSelector -> AdvancedEventSelector
newAdvancedEventSelector NonEmpty AdvancedFieldSelector
pFieldSelectors_ =
  AdvancedEventSelector' :: Maybe Text
-> NonEmpty AdvancedFieldSelector -> AdvancedEventSelector
AdvancedEventSelector'
    { $sel:name:AdvancedEventSelector' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:fieldSelectors:AdvancedEventSelector' :: NonEmpty AdvancedFieldSelector
fieldSelectors =
        Tagged
  (NonEmpty AdvancedFieldSelector)
  (Identity (NonEmpty AdvancedFieldSelector))
-> Tagged
     (NonEmpty AdvancedFieldSelector)
     (Identity (NonEmpty AdvancedFieldSelector))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty AdvancedFieldSelector)
   (Identity (NonEmpty AdvancedFieldSelector))
 -> Tagged
      (NonEmpty AdvancedFieldSelector)
      (Identity (NonEmpty AdvancedFieldSelector)))
-> NonEmpty AdvancedFieldSelector -> NonEmpty AdvancedFieldSelector
forall t b. AReview t b -> b -> t
Lens.# NonEmpty AdvancedFieldSelector
pFieldSelectors_
    }

-- | An optional, descriptive name for an advanced event selector, such as
-- \"Log data events for only two S3 buckets\".
advancedEventSelector_name :: Lens.Lens' AdvancedEventSelector (Prelude.Maybe Prelude.Text)
advancedEventSelector_name :: (Maybe Text -> f (Maybe Text))
-> AdvancedEventSelector -> f AdvancedEventSelector
advancedEventSelector_name = (AdvancedEventSelector -> Maybe Text)
-> (AdvancedEventSelector -> Maybe Text -> AdvancedEventSelector)
-> Lens
     AdvancedEventSelector
     AdvancedEventSelector
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AdvancedEventSelector' {Maybe Text
name :: Maybe Text
$sel:name:AdvancedEventSelector' :: AdvancedEventSelector -> Maybe Text
name} -> Maybe Text
name) (\s :: AdvancedEventSelector
s@AdvancedEventSelector' {} Maybe Text
a -> AdvancedEventSelector
s {$sel:name:AdvancedEventSelector' :: Maybe Text
name = Maybe Text
a} :: AdvancedEventSelector)

-- | Contains all selector statements in an advanced event selector.
advancedEventSelector_fieldSelectors :: Lens.Lens' AdvancedEventSelector (Prelude.NonEmpty AdvancedFieldSelector)
advancedEventSelector_fieldSelectors :: (NonEmpty AdvancedFieldSelector
 -> f (NonEmpty AdvancedFieldSelector))
-> AdvancedEventSelector -> f AdvancedEventSelector
advancedEventSelector_fieldSelectors = (AdvancedEventSelector -> NonEmpty AdvancedFieldSelector)
-> (AdvancedEventSelector
    -> NonEmpty AdvancedFieldSelector -> AdvancedEventSelector)
-> Lens
     AdvancedEventSelector
     AdvancedEventSelector
     (NonEmpty AdvancedFieldSelector)
     (NonEmpty AdvancedFieldSelector)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AdvancedEventSelector' {NonEmpty AdvancedFieldSelector
fieldSelectors :: NonEmpty AdvancedFieldSelector
$sel:fieldSelectors:AdvancedEventSelector' :: AdvancedEventSelector -> NonEmpty AdvancedFieldSelector
fieldSelectors} -> NonEmpty AdvancedFieldSelector
fieldSelectors) (\s :: AdvancedEventSelector
s@AdvancedEventSelector' {} NonEmpty AdvancedFieldSelector
a -> AdvancedEventSelector
s {$sel:fieldSelectors:AdvancedEventSelector' :: NonEmpty AdvancedFieldSelector
fieldSelectors = NonEmpty AdvancedFieldSelector
a} :: AdvancedEventSelector) ((NonEmpty AdvancedFieldSelector
  -> f (NonEmpty AdvancedFieldSelector))
 -> AdvancedEventSelector -> f AdvancedEventSelector)
-> ((NonEmpty AdvancedFieldSelector
     -> f (NonEmpty AdvancedFieldSelector))
    -> NonEmpty AdvancedFieldSelector
    -> f (NonEmpty AdvancedFieldSelector))
-> (NonEmpty AdvancedFieldSelector
    -> f (NonEmpty AdvancedFieldSelector))
-> AdvancedEventSelector
-> f AdvancedEventSelector
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty AdvancedFieldSelector
 -> f (NonEmpty AdvancedFieldSelector))
-> NonEmpty AdvancedFieldSelector
-> f (NonEmpty AdvancedFieldSelector)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON AdvancedEventSelector where
  parseJSON :: Value -> Parser AdvancedEventSelector
parseJSON =
    String
-> (Object -> Parser AdvancedEventSelector)
-> Value
-> Parser AdvancedEventSelector
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AdvancedEventSelector"
      ( \Object
x ->
          Maybe Text
-> NonEmpty AdvancedFieldSelector -> AdvancedEventSelector
AdvancedEventSelector'
            (Maybe Text
 -> NonEmpty AdvancedFieldSelector -> AdvancedEventSelector)
-> Parser (Maybe Text)
-> Parser (NonEmpty AdvancedFieldSelector -> AdvancedEventSelector)
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
"Name")
            Parser (NonEmpty AdvancedFieldSelector -> AdvancedEventSelector)
-> Parser (NonEmpty AdvancedFieldSelector)
-> Parser AdvancedEventSelector
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty AdvancedFieldSelector)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"FieldSelectors")
      )

instance Prelude.Hashable AdvancedEventSelector

instance Prelude.NFData AdvancedEventSelector

instance Core.ToJSON AdvancedEventSelector where
  toJSON :: AdvancedEventSelector -> Value
toJSON AdvancedEventSelector' {Maybe Text
NonEmpty AdvancedFieldSelector
fieldSelectors :: NonEmpty AdvancedFieldSelector
name :: Maybe Text
$sel:fieldSelectors:AdvancedEventSelector' :: AdvancedEventSelector -> NonEmpty AdvancedFieldSelector
$sel:name:AdvancedEventSelector' :: AdvancedEventSelector -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Name" 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
name,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"FieldSelectors" Text -> NonEmpty AdvancedFieldSelector -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty AdvancedFieldSelector
fieldSelectors)
          ]
      )