{-# 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.GuardDuty.Types.UsageStatistics
-- 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.GuardDuty.Types.UsageStatistics where

import qualified Amazonka.Core as Core
import Amazonka.GuardDuty.Types.UsageAccountResult
import Amazonka.GuardDuty.Types.UsageDataSourceResult
import Amazonka.GuardDuty.Types.UsageResourceResult
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains the result of GuardDuty usage. If a UsageStatisticType is
-- provided the result for other types will be null.
--
-- /See:/ 'newUsageStatistics' smart constructor.
data UsageStatistics = UsageStatistics'
  { -- | Lists the top 50 resources that have generated the most GuardDuty usage,
    -- in order from most to least expensive.
    UsageStatistics -> Maybe [UsageResourceResult]
topResources :: Prelude.Maybe [UsageResourceResult],
    -- | The usage statistic sum organized by resource.
    UsageStatistics -> Maybe [UsageResourceResult]
sumByResource :: Prelude.Maybe [UsageResourceResult],
    -- | The usage statistic sum organized by on data source.
    UsageStatistics -> Maybe [UsageDataSourceResult]
sumByDataSource :: Prelude.Maybe [UsageDataSourceResult],
    -- | The usage statistic sum organized by account ID.
    UsageStatistics -> Maybe [UsageAccountResult]
sumByAccount :: Prelude.Maybe [UsageAccountResult]
  }
  deriving (UsageStatistics -> UsageStatistics -> Bool
(UsageStatistics -> UsageStatistics -> Bool)
-> (UsageStatistics -> UsageStatistics -> Bool)
-> Eq UsageStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UsageStatistics -> UsageStatistics -> Bool
$c/= :: UsageStatistics -> UsageStatistics -> Bool
== :: UsageStatistics -> UsageStatistics -> Bool
$c== :: UsageStatistics -> UsageStatistics -> Bool
Prelude.Eq, ReadPrec [UsageStatistics]
ReadPrec UsageStatistics
Int -> ReadS UsageStatistics
ReadS [UsageStatistics]
(Int -> ReadS UsageStatistics)
-> ReadS [UsageStatistics]
-> ReadPrec UsageStatistics
-> ReadPrec [UsageStatistics]
-> Read UsageStatistics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UsageStatistics]
$creadListPrec :: ReadPrec [UsageStatistics]
readPrec :: ReadPrec UsageStatistics
$creadPrec :: ReadPrec UsageStatistics
readList :: ReadS [UsageStatistics]
$creadList :: ReadS [UsageStatistics]
readsPrec :: Int -> ReadS UsageStatistics
$creadsPrec :: Int -> ReadS UsageStatistics
Prelude.Read, Int -> UsageStatistics -> ShowS
[UsageStatistics] -> ShowS
UsageStatistics -> String
(Int -> UsageStatistics -> ShowS)
-> (UsageStatistics -> String)
-> ([UsageStatistics] -> ShowS)
-> Show UsageStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UsageStatistics] -> ShowS
$cshowList :: [UsageStatistics] -> ShowS
show :: UsageStatistics -> String
$cshow :: UsageStatistics -> String
showsPrec :: Int -> UsageStatistics -> ShowS
$cshowsPrec :: Int -> UsageStatistics -> ShowS
Prelude.Show, (forall x. UsageStatistics -> Rep UsageStatistics x)
-> (forall x. Rep UsageStatistics x -> UsageStatistics)
-> Generic UsageStatistics
forall x. Rep UsageStatistics x -> UsageStatistics
forall x. UsageStatistics -> Rep UsageStatistics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UsageStatistics x -> UsageStatistics
$cfrom :: forall x. UsageStatistics -> Rep UsageStatistics x
Prelude.Generic)

-- |
-- Create a value of 'UsageStatistics' 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:
--
-- 'topResources', 'usageStatistics_topResources' - Lists the top 50 resources that have generated the most GuardDuty usage,
-- in order from most to least expensive.
--
-- 'sumByResource', 'usageStatistics_sumByResource' - The usage statistic sum organized by resource.
--
-- 'sumByDataSource', 'usageStatistics_sumByDataSource' - The usage statistic sum organized by on data source.
--
-- 'sumByAccount', 'usageStatistics_sumByAccount' - The usage statistic sum organized by account ID.
newUsageStatistics ::
  UsageStatistics
newUsageStatistics :: UsageStatistics
newUsageStatistics =
  UsageStatistics' :: Maybe [UsageResourceResult]
-> Maybe [UsageResourceResult]
-> Maybe [UsageDataSourceResult]
-> Maybe [UsageAccountResult]
-> UsageStatistics
UsageStatistics'
    { $sel:topResources:UsageStatistics' :: Maybe [UsageResourceResult]
topResources = Maybe [UsageResourceResult]
forall a. Maybe a
Prelude.Nothing,
      $sel:sumByResource:UsageStatistics' :: Maybe [UsageResourceResult]
sumByResource = Maybe [UsageResourceResult]
forall a. Maybe a
Prelude.Nothing,
      $sel:sumByDataSource:UsageStatistics' :: Maybe [UsageDataSourceResult]
sumByDataSource = Maybe [UsageDataSourceResult]
forall a. Maybe a
Prelude.Nothing,
      $sel:sumByAccount:UsageStatistics' :: Maybe [UsageAccountResult]
sumByAccount = Maybe [UsageAccountResult]
forall a. Maybe a
Prelude.Nothing
    }

-- | Lists the top 50 resources that have generated the most GuardDuty usage,
-- in order from most to least expensive.
usageStatistics_topResources :: Lens.Lens' UsageStatistics (Prelude.Maybe [UsageResourceResult])
usageStatistics_topResources :: (Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
-> UsageStatistics -> f UsageStatistics
usageStatistics_topResources = (UsageStatistics -> Maybe [UsageResourceResult])
-> (UsageStatistics
    -> Maybe [UsageResourceResult] -> UsageStatistics)
-> Lens
     UsageStatistics
     UsageStatistics
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageStatistics' {Maybe [UsageResourceResult]
topResources :: Maybe [UsageResourceResult]
$sel:topResources:UsageStatistics' :: UsageStatistics -> Maybe [UsageResourceResult]
topResources} -> Maybe [UsageResourceResult]
topResources) (\s :: UsageStatistics
s@UsageStatistics' {} Maybe [UsageResourceResult]
a -> UsageStatistics
s {$sel:topResources:UsageStatistics' :: Maybe [UsageResourceResult]
topResources = Maybe [UsageResourceResult]
a} :: UsageStatistics) ((Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
 -> UsageStatistics -> f UsageStatistics)
-> ((Maybe [UsageResourceResult]
     -> f (Maybe [UsageResourceResult]))
    -> Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
-> (Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
-> UsageStatistics
-> f UsageStatistics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
-> Iso
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
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
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The usage statistic sum organized by resource.
usageStatistics_sumByResource :: Lens.Lens' UsageStatistics (Prelude.Maybe [UsageResourceResult])
usageStatistics_sumByResource :: (Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
-> UsageStatistics -> f UsageStatistics
usageStatistics_sumByResource = (UsageStatistics -> Maybe [UsageResourceResult])
-> (UsageStatistics
    -> Maybe [UsageResourceResult] -> UsageStatistics)
-> Lens
     UsageStatistics
     UsageStatistics
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageStatistics' {Maybe [UsageResourceResult]
sumByResource :: Maybe [UsageResourceResult]
$sel:sumByResource:UsageStatistics' :: UsageStatistics -> Maybe [UsageResourceResult]
sumByResource} -> Maybe [UsageResourceResult]
sumByResource) (\s :: UsageStatistics
s@UsageStatistics' {} Maybe [UsageResourceResult]
a -> UsageStatistics
s {$sel:sumByResource:UsageStatistics' :: Maybe [UsageResourceResult]
sumByResource = Maybe [UsageResourceResult]
a} :: UsageStatistics) ((Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
 -> UsageStatistics -> f UsageStatistics)
-> ((Maybe [UsageResourceResult]
     -> f (Maybe [UsageResourceResult]))
    -> Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
-> (Maybe [UsageResourceResult] -> f (Maybe [UsageResourceResult]))
-> UsageStatistics
-> f UsageStatistics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
-> Iso
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
     (Maybe [UsageResourceResult])
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
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
  [UsageResourceResult]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The usage statistic sum organized by on data source.
usageStatistics_sumByDataSource :: Lens.Lens' UsageStatistics (Prelude.Maybe [UsageDataSourceResult])
usageStatistics_sumByDataSource :: (Maybe [UsageDataSourceResult]
 -> f (Maybe [UsageDataSourceResult]))
-> UsageStatistics -> f UsageStatistics
usageStatistics_sumByDataSource = (UsageStatistics -> Maybe [UsageDataSourceResult])
-> (UsageStatistics
    -> Maybe [UsageDataSourceResult] -> UsageStatistics)
-> Lens
     UsageStatistics
     UsageStatistics
     (Maybe [UsageDataSourceResult])
     (Maybe [UsageDataSourceResult])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageStatistics' {Maybe [UsageDataSourceResult]
sumByDataSource :: Maybe [UsageDataSourceResult]
$sel:sumByDataSource:UsageStatistics' :: UsageStatistics -> Maybe [UsageDataSourceResult]
sumByDataSource} -> Maybe [UsageDataSourceResult]
sumByDataSource) (\s :: UsageStatistics
s@UsageStatistics' {} Maybe [UsageDataSourceResult]
a -> UsageStatistics
s {$sel:sumByDataSource:UsageStatistics' :: Maybe [UsageDataSourceResult]
sumByDataSource = Maybe [UsageDataSourceResult]
a} :: UsageStatistics) ((Maybe [UsageDataSourceResult]
  -> f (Maybe [UsageDataSourceResult]))
 -> UsageStatistics -> f UsageStatistics)
-> ((Maybe [UsageDataSourceResult]
     -> f (Maybe [UsageDataSourceResult]))
    -> Maybe [UsageDataSourceResult]
    -> f (Maybe [UsageDataSourceResult]))
-> (Maybe [UsageDataSourceResult]
    -> f (Maybe [UsageDataSourceResult]))
-> UsageStatistics
-> f UsageStatistics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UsageDataSourceResult]
  [UsageDataSourceResult]
  [UsageDataSourceResult]
  [UsageDataSourceResult]
-> Iso
     (Maybe [UsageDataSourceResult])
     (Maybe [UsageDataSourceResult])
     (Maybe [UsageDataSourceResult])
     (Maybe [UsageDataSourceResult])
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
  [UsageDataSourceResult]
  [UsageDataSourceResult]
  [UsageDataSourceResult]
  [UsageDataSourceResult]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The usage statistic sum organized by account ID.
usageStatistics_sumByAccount :: Lens.Lens' UsageStatistics (Prelude.Maybe [UsageAccountResult])
usageStatistics_sumByAccount :: (Maybe [UsageAccountResult] -> f (Maybe [UsageAccountResult]))
-> UsageStatistics -> f UsageStatistics
usageStatistics_sumByAccount = (UsageStatistics -> Maybe [UsageAccountResult])
-> (UsageStatistics
    -> Maybe [UsageAccountResult] -> UsageStatistics)
-> Lens
     UsageStatistics
     UsageStatistics
     (Maybe [UsageAccountResult])
     (Maybe [UsageAccountResult])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageStatistics' {Maybe [UsageAccountResult]
sumByAccount :: Maybe [UsageAccountResult]
$sel:sumByAccount:UsageStatistics' :: UsageStatistics -> Maybe [UsageAccountResult]
sumByAccount} -> Maybe [UsageAccountResult]
sumByAccount) (\s :: UsageStatistics
s@UsageStatistics' {} Maybe [UsageAccountResult]
a -> UsageStatistics
s {$sel:sumByAccount:UsageStatistics' :: Maybe [UsageAccountResult]
sumByAccount = Maybe [UsageAccountResult]
a} :: UsageStatistics) ((Maybe [UsageAccountResult] -> f (Maybe [UsageAccountResult]))
 -> UsageStatistics -> f UsageStatistics)
-> ((Maybe [UsageAccountResult] -> f (Maybe [UsageAccountResult]))
    -> Maybe [UsageAccountResult] -> f (Maybe [UsageAccountResult]))
-> (Maybe [UsageAccountResult] -> f (Maybe [UsageAccountResult]))
-> UsageStatistics
-> f UsageStatistics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UsageAccountResult]
  [UsageAccountResult]
  [UsageAccountResult]
  [UsageAccountResult]
-> Iso
     (Maybe [UsageAccountResult])
     (Maybe [UsageAccountResult])
     (Maybe [UsageAccountResult])
     (Maybe [UsageAccountResult])
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
  [UsageAccountResult]
  [UsageAccountResult]
  [UsageAccountResult]
  [UsageAccountResult]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON UsageStatistics where
  parseJSON :: Value -> Parser UsageStatistics
parseJSON =
    String
-> (Object -> Parser UsageStatistics)
-> Value
-> Parser UsageStatistics
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UsageStatistics"
      ( \Object
x ->
          Maybe [UsageResourceResult]
-> Maybe [UsageResourceResult]
-> Maybe [UsageDataSourceResult]
-> Maybe [UsageAccountResult]
-> UsageStatistics
UsageStatistics'
            (Maybe [UsageResourceResult]
 -> Maybe [UsageResourceResult]
 -> Maybe [UsageDataSourceResult]
 -> Maybe [UsageAccountResult]
 -> UsageStatistics)
-> Parser (Maybe [UsageResourceResult])
-> Parser
     (Maybe [UsageResourceResult]
      -> Maybe [UsageDataSourceResult]
      -> Maybe [UsageAccountResult]
      -> UsageStatistics)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [UsageResourceResult]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"topResources" Parser (Maybe (Maybe [UsageResourceResult]))
-> Maybe [UsageResourceResult]
-> Parser (Maybe [UsageResourceResult])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [UsageResourceResult]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe [UsageResourceResult]
   -> Maybe [UsageDataSourceResult]
   -> Maybe [UsageAccountResult]
   -> UsageStatistics)
-> Parser (Maybe [UsageResourceResult])
-> Parser
     (Maybe [UsageDataSourceResult]
      -> Maybe [UsageAccountResult] -> UsageStatistics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [UsageResourceResult]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"sumByResource" Parser (Maybe (Maybe [UsageResourceResult]))
-> Maybe [UsageResourceResult]
-> Parser (Maybe [UsageResourceResult])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [UsageResourceResult]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe [UsageDataSourceResult]
   -> Maybe [UsageAccountResult] -> UsageStatistics)
-> Parser (Maybe [UsageDataSourceResult])
-> Parser (Maybe [UsageAccountResult] -> UsageStatistics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [UsageDataSourceResult]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"sumByDataSource"
                            Parser (Maybe (Maybe [UsageDataSourceResult]))
-> Maybe [UsageDataSourceResult]
-> Parser (Maybe [UsageDataSourceResult])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [UsageDataSourceResult]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe [UsageAccountResult] -> UsageStatistics)
-> Parser (Maybe [UsageAccountResult]) -> Parser UsageStatistics
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [UsageAccountResult]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"sumByAccount" Parser (Maybe (Maybe [UsageAccountResult]))
-> Maybe [UsageAccountResult]
-> Parser (Maybe [UsageAccountResult])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [UsageAccountResult]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable UsageStatistics

instance Prelude.NFData UsageStatistics