{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.GuardDuty.Types.UsageStatistics where

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

-- | The usage statistic sum organized by account ID.
usageStatistics_sumByAccount :: Lens.Lens' UsageStatistics (Prelude.Maybe [UsageAccountResult])
usageStatistics_sumByAccount :: Lens' UsageStatistics (Maybe [UsageAccountResult])
usageStatistics_sumByAccount = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' UsageStatistics (Maybe [UsageDataSourceResult])
usageStatistics_sumByDataSource = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' UsageStatistics (Maybe [UsageResourceResult])
usageStatistics_sumByResource = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' UsageStatistics (Maybe [UsageResourceResult])
usageStatistics_topResources = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable UsageStatistics where
  hashWithSalt :: Int -> UsageStatistics -> Int
hashWithSalt Int
_salt UsageStatistics' {Maybe [UsageAccountResult]
Maybe [UsageDataSourceResult]
Maybe [UsageResourceResult]
topResources :: Maybe [UsageResourceResult]
sumByResource :: Maybe [UsageResourceResult]
sumByDataSource :: Maybe [UsageDataSourceResult]
sumByAccount :: Maybe [UsageAccountResult]
$sel:topResources:UsageStatistics' :: UsageStatistics -> Maybe [UsageResourceResult]
$sel:sumByResource:UsageStatistics' :: UsageStatistics -> Maybe [UsageResourceResult]
$sel:sumByDataSource:UsageStatistics' :: UsageStatistics -> Maybe [UsageDataSourceResult]
$sel:sumByAccount:UsageStatistics' :: UsageStatistics -> Maybe [UsageAccountResult]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [UsageAccountResult]
sumByAccount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [UsageDataSourceResult]
sumByDataSource
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [UsageResourceResult]
sumByResource
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [UsageResourceResult]
topResources

instance Prelude.NFData UsageStatistics where
  rnf :: UsageStatistics -> ()
rnf UsageStatistics' {Maybe [UsageAccountResult]
Maybe [UsageDataSourceResult]
Maybe [UsageResourceResult]
topResources :: Maybe [UsageResourceResult]
sumByResource :: Maybe [UsageResourceResult]
sumByDataSource :: Maybe [UsageDataSourceResult]
sumByAccount :: Maybe [UsageAccountResult]
$sel:topResources:UsageStatistics' :: UsageStatistics -> Maybe [UsageResourceResult]
$sel:sumByResource:UsageStatistics' :: UsageStatistics -> Maybe [UsageResourceResult]
$sel:sumByDataSource:UsageStatistics' :: UsageStatistics -> Maybe [UsageDataSourceResult]
$sel:sumByAccount:UsageStatistics' :: UsageStatistics -> Maybe [UsageAccountResult]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [UsageAccountResult]
sumByAccount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [UsageDataSourceResult]
sumByDataSource
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [UsageResourceResult]
sumByResource
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [UsageResourceResult]
topResources