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

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

-- | A JSON string that contains a list of insight types that are logged on a
-- trail.
--
-- /See:/ 'newInsightSelector' smart constructor.
data InsightSelector = InsightSelector'
  { -- | The type of Insights events to log on a trail. The valid Insights type
    -- in this release is @ApiCallRateInsight@.
    InsightSelector -> Maybe InsightType
insightType :: Prelude.Maybe InsightType
  }
  deriving (InsightSelector -> InsightSelector -> Bool
(InsightSelector -> InsightSelector -> Bool)
-> (InsightSelector -> InsightSelector -> Bool)
-> Eq InsightSelector
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InsightSelector -> InsightSelector -> Bool
$c/= :: InsightSelector -> InsightSelector -> Bool
== :: InsightSelector -> InsightSelector -> Bool
$c== :: InsightSelector -> InsightSelector -> Bool
Prelude.Eq, ReadPrec [InsightSelector]
ReadPrec InsightSelector
Int -> ReadS InsightSelector
ReadS [InsightSelector]
(Int -> ReadS InsightSelector)
-> ReadS [InsightSelector]
-> ReadPrec InsightSelector
-> ReadPrec [InsightSelector]
-> Read InsightSelector
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InsightSelector]
$creadListPrec :: ReadPrec [InsightSelector]
readPrec :: ReadPrec InsightSelector
$creadPrec :: ReadPrec InsightSelector
readList :: ReadS [InsightSelector]
$creadList :: ReadS [InsightSelector]
readsPrec :: Int -> ReadS InsightSelector
$creadsPrec :: Int -> ReadS InsightSelector
Prelude.Read, Int -> InsightSelector -> ShowS
[InsightSelector] -> ShowS
InsightSelector -> String
(Int -> InsightSelector -> ShowS)
-> (InsightSelector -> String)
-> ([InsightSelector] -> ShowS)
-> Show InsightSelector
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InsightSelector] -> ShowS
$cshowList :: [InsightSelector] -> ShowS
show :: InsightSelector -> String
$cshow :: InsightSelector -> String
showsPrec :: Int -> InsightSelector -> ShowS
$cshowsPrec :: Int -> InsightSelector -> ShowS
Prelude.Show, (forall x. InsightSelector -> Rep InsightSelector x)
-> (forall x. Rep InsightSelector x -> InsightSelector)
-> Generic InsightSelector
forall x. Rep InsightSelector x -> InsightSelector
forall x. InsightSelector -> Rep InsightSelector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InsightSelector x -> InsightSelector
$cfrom :: forall x. InsightSelector -> Rep InsightSelector x
Prelude.Generic)

-- |
-- Create a value of 'InsightSelector' 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:
--
-- 'insightType', 'insightSelector_insightType' - The type of Insights events to log on a trail. The valid Insights type
-- in this release is @ApiCallRateInsight@.
newInsightSelector ::
  InsightSelector
newInsightSelector :: InsightSelector
newInsightSelector =
  InsightSelector' :: Maybe InsightType -> InsightSelector
InsightSelector' {$sel:insightType:InsightSelector' :: Maybe InsightType
insightType = Maybe InsightType
forall a. Maybe a
Prelude.Nothing}

-- | The type of Insights events to log on a trail. The valid Insights type
-- in this release is @ApiCallRateInsight@.
insightSelector_insightType :: Lens.Lens' InsightSelector (Prelude.Maybe InsightType)
insightSelector_insightType :: (Maybe InsightType -> f (Maybe InsightType))
-> InsightSelector -> f InsightSelector
insightSelector_insightType = (InsightSelector -> Maybe InsightType)
-> (InsightSelector -> Maybe InsightType -> InsightSelector)
-> Lens
     InsightSelector
     InsightSelector
     (Maybe InsightType)
     (Maybe InsightType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightSelector' {Maybe InsightType
insightType :: Maybe InsightType
$sel:insightType:InsightSelector' :: InsightSelector -> Maybe InsightType
insightType} -> Maybe InsightType
insightType) (\s :: InsightSelector
s@InsightSelector' {} Maybe InsightType
a -> InsightSelector
s {$sel:insightType:InsightSelector' :: Maybe InsightType
insightType = Maybe InsightType
a} :: InsightSelector)

instance Core.FromJSON InsightSelector where
  parseJSON :: Value -> Parser InsightSelector
parseJSON =
    String
-> (Object -> Parser InsightSelector)
-> Value
-> Parser InsightSelector
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InsightSelector"
      ( \Object
x ->
          Maybe InsightType -> InsightSelector
InsightSelector'
            (Maybe InsightType -> InsightSelector)
-> Parser (Maybe InsightType) -> Parser InsightSelector
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe InsightType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InsightType")
      )

instance Prelude.Hashable InsightSelector

instance Prelude.NFData InsightSelector

instance Core.ToJSON InsightSelector where
  toJSON :: InsightSelector -> Value
toJSON InsightSelector' {Maybe InsightType
insightType :: Maybe InsightType
$sel:insightType:InsightSelector' :: InsightSelector -> Maybe InsightType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"InsightType" Text -> InsightType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (InsightType -> Pair) -> Maybe InsightType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe InsightType
insightType]
      )