{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.GetUsageTotals
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves (queries) aggregated usage data for an account.
module Amazonka.MacieV2.GetUsageTotals
  ( -- * Creating a Request
    GetUsageTotals (..),
    newGetUsageTotals,

    -- * Request Lenses
    getUsageTotals_timeRange,

    -- * Destructuring the Response
    GetUsageTotalsResponse (..),
    newGetUsageTotalsResponse,

    -- * Response Lenses
    getUsageTotalsResponse_timeRange,
    getUsageTotalsResponse_usageTotals,
    getUsageTotalsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MacieV2.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetUsageTotals' smart constructor.
data GetUsageTotals = GetUsageTotals'
  { -- | The inclusive time period to retrieve the data for. Valid values are:
    -- MONTH_TO_DATE, for the current calendar month to date; and,
    -- PAST_30_DAYS, for the preceding 30 days. If you don\'t specify a value
    -- for this parameter, Amazon Macie provides aggregated usage data for the
    -- preceding 30 days.
    GetUsageTotals -> Maybe Text
timeRange :: Prelude.Maybe Prelude.Text
  }
  deriving (GetUsageTotals -> GetUsageTotals -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetUsageTotals -> GetUsageTotals -> Bool
$c/= :: GetUsageTotals -> GetUsageTotals -> Bool
== :: GetUsageTotals -> GetUsageTotals -> Bool
$c== :: GetUsageTotals -> GetUsageTotals -> Bool
Prelude.Eq, ReadPrec [GetUsageTotals]
ReadPrec GetUsageTotals
Int -> ReadS GetUsageTotals
ReadS [GetUsageTotals]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetUsageTotals]
$creadListPrec :: ReadPrec [GetUsageTotals]
readPrec :: ReadPrec GetUsageTotals
$creadPrec :: ReadPrec GetUsageTotals
readList :: ReadS [GetUsageTotals]
$creadList :: ReadS [GetUsageTotals]
readsPrec :: Int -> ReadS GetUsageTotals
$creadsPrec :: Int -> ReadS GetUsageTotals
Prelude.Read, Int -> GetUsageTotals -> ShowS
[GetUsageTotals] -> ShowS
GetUsageTotals -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetUsageTotals] -> ShowS
$cshowList :: [GetUsageTotals] -> ShowS
show :: GetUsageTotals -> String
$cshow :: GetUsageTotals -> String
showsPrec :: Int -> GetUsageTotals -> ShowS
$cshowsPrec :: Int -> GetUsageTotals -> ShowS
Prelude.Show, forall x. Rep GetUsageTotals x -> GetUsageTotals
forall x. GetUsageTotals -> Rep GetUsageTotals x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetUsageTotals x -> GetUsageTotals
$cfrom :: forall x. GetUsageTotals -> Rep GetUsageTotals x
Prelude.Generic)

-- |
-- Create a value of 'GetUsageTotals' 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:
--
-- 'timeRange', 'getUsageTotals_timeRange' - The inclusive time period to retrieve the data for. Valid values are:
-- MONTH_TO_DATE, for the current calendar month to date; and,
-- PAST_30_DAYS, for the preceding 30 days. If you don\'t specify a value
-- for this parameter, Amazon Macie provides aggregated usage data for the
-- preceding 30 days.
newGetUsageTotals ::
  GetUsageTotals
newGetUsageTotals :: GetUsageTotals
newGetUsageTotals =
  GetUsageTotals' {$sel:timeRange:GetUsageTotals' :: Maybe Text
timeRange = forall a. Maybe a
Prelude.Nothing}

-- | The inclusive time period to retrieve the data for. Valid values are:
-- MONTH_TO_DATE, for the current calendar month to date; and,
-- PAST_30_DAYS, for the preceding 30 days. If you don\'t specify a value
-- for this parameter, Amazon Macie provides aggregated usage data for the
-- preceding 30 days.
getUsageTotals_timeRange :: Lens.Lens' GetUsageTotals (Prelude.Maybe Prelude.Text)
getUsageTotals_timeRange :: Lens' GetUsageTotals (Maybe Text)
getUsageTotals_timeRange = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageTotals' {Maybe Text
timeRange :: Maybe Text
$sel:timeRange:GetUsageTotals' :: GetUsageTotals -> Maybe Text
timeRange} -> Maybe Text
timeRange) (\s :: GetUsageTotals
s@GetUsageTotals' {} Maybe Text
a -> GetUsageTotals
s {$sel:timeRange:GetUsageTotals' :: Maybe Text
timeRange = Maybe Text
a} :: GetUsageTotals)

instance Core.AWSRequest GetUsageTotals where
  type
    AWSResponse GetUsageTotals =
      GetUsageTotalsResponse
  request :: (Service -> Service) -> GetUsageTotals -> Request GetUsageTotals
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetUsageTotals
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetUsageTotals)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe TimeRange
-> Maybe [UsageTotal] -> Int -> GetUsageTotalsResponse
GetUsageTotalsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"timeRange")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"usageTotals" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetUsageTotals where
  hashWithSalt :: Int -> GetUsageTotals -> Int
hashWithSalt Int
_salt GetUsageTotals' {Maybe Text
timeRange :: Maybe Text
$sel:timeRange:GetUsageTotals' :: GetUsageTotals -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
timeRange

instance Prelude.NFData GetUsageTotals where
  rnf :: GetUsageTotals -> ()
rnf GetUsageTotals' {Maybe Text
timeRange :: Maybe Text
$sel:timeRange:GetUsageTotals' :: GetUsageTotals -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
timeRange

instance Data.ToHeaders GetUsageTotals where
  toHeaders :: GetUsageTotals -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToPath GetUsageTotals where
  toPath :: GetUsageTotals -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/usage"

instance Data.ToQuery GetUsageTotals where
  toQuery :: GetUsageTotals -> QueryString
toQuery GetUsageTotals' {Maybe Text
timeRange :: Maybe Text
$sel:timeRange:GetUsageTotals' :: GetUsageTotals -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"timeRange" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
timeRange]

-- | /See:/ 'newGetUsageTotalsResponse' smart constructor.
data GetUsageTotalsResponse = GetUsageTotalsResponse'
  { -- | The inclusive time period that the usage data applies to. Possible
    -- values are: MONTH_TO_DATE, for the current calendar month to date; and,
    -- PAST_30_DAYS, for the preceding 30 days.
    GetUsageTotalsResponse -> Maybe TimeRange
timeRange :: Prelude.Maybe TimeRange,
    -- | An array of objects that contains the results of the query. Each object
    -- contains the data for a specific usage metric.
    GetUsageTotalsResponse -> Maybe [UsageTotal]
usageTotals :: Prelude.Maybe [UsageTotal],
    -- | The response's http status code.
    GetUsageTotalsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool
$c/= :: GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool
== :: GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool
$c== :: GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool
Prelude.Eq, ReadPrec [GetUsageTotalsResponse]
ReadPrec GetUsageTotalsResponse
Int -> ReadS GetUsageTotalsResponse
ReadS [GetUsageTotalsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetUsageTotalsResponse]
$creadListPrec :: ReadPrec [GetUsageTotalsResponse]
readPrec :: ReadPrec GetUsageTotalsResponse
$creadPrec :: ReadPrec GetUsageTotalsResponse
readList :: ReadS [GetUsageTotalsResponse]
$creadList :: ReadS [GetUsageTotalsResponse]
readsPrec :: Int -> ReadS GetUsageTotalsResponse
$creadsPrec :: Int -> ReadS GetUsageTotalsResponse
Prelude.Read, Int -> GetUsageTotalsResponse -> ShowS
[GetUsageTotalsResponse] -> ShowS
GetUsageTotalsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetUsageTotalsResponse] -> ShowS
$cshowList :: [GetUsageTotalsResponse] -> ShowS
show :: GetUsageTotalsResponse -> String
$cshow :: GetUsageTotalsResponse -> String
showsPrec :: Int -> GetUsageTotalsResponse -> ShowS
$cshowsPrec :: Int -> GetUsageTotalsResponse -> ShowS
Prelude.Show, forall x. Rep GetUsageTotalsResponse x -> GetUsageTotalsResponse
forall x. GetUsageTotalsResponse -> Rep GetUsageTotalsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetUsageTotalsResponse x -> GetUsageTotalsResponse
$cfrom :: forall x. GetUsageTotalsResponse -> Rep GetUsageTotalsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetUsageTotalsResponse' 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:
--
-- 'timeRange', 'getUsageTotalsResponse_timeRange' - The inclusive time period that the usage data applies to. Possible
-- values are: MONTH_TO_DATE, for the current calendar month to date; and,
-- PAST_30_DAYS, for the preceding 30 days.
--
-- 'usageTotals', 'getUsageTotalsResponse_usageTotals' - An array of objects that contains the results of the query. Each object
-- contains the data for a specific usage metric.
--
-- 'httpStatus', 'getUsageTotalsResponse_httpStatus' - The response's http status code.
newGetUsageTotalsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetUsageTotalsResponse
newGetUsageTotalsResponse :: Int -> GetUsageTotalsResponse
newGetUsageTotalsResponse Int
pHttpStatus_ =
  GetUsageTotalsResponse'
    { $sel:timeRange:GetUsageTotalsResponse' :: Maybe TimeRange
timeRange =
        forall a. Maybe a
Prelude.Nothing,
      $sel:usageTotals:GetUsageTotalsResponse' :: Maybe [UsageTotal]
usageTotals = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetUsageTotalsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The inclusive time period that the usage data applies to. Possible
-- values are: MONTH_TO_DATE, for the current calendar month to date; and,
-- PAST_30_DAYS, for the preceding 30 days.
getUsageTotalsResponse_timeRange :: Lens.Lens' GetUsageTotalsResponse (Prelude.Maybe TimeRange)
getUsageTotalsResponse_timeRange :: Lens' GetUsageTotalsResponse (Maybe TimeRange)
getUsageTotalsResponse_timeRange = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageTotalsResponse' {Maybe TimeRange
timeRange :: Maybe TimeRange
$sel:timeRange:GetUsageTotalsResponse' :: GetUsageTotalsResponse -> Maybe TimeRange
timeRange} -> Maybe TimeRange
timeRange) (\s :: GetUsageTotalsResponse
s@GetUsageTotalsResponse' {} Maybe TimeRange
a -> GetUsageTotalsResponse
s {$sel:timeRange:GetUsageTotalsResponse' :: Maybe TimeRange
timeRange = Maybe TimeRange
a} :: GetUsageTotalsResponse)

-- | An array of objects that contains the results of the query. Each object
-- contains the data for a specific usage metric.
getUsageTotalsResponse_usageTotals :: Lens.Lens' GetUsageTotalsResponse (Prelude.Maybe [UsageTotal])
getUsageTotalsResponse_usageTotals :: Lens' GetUsageTotalsResponse (Maybe [UsageTotal])
getUsageTotalsResponse_usageTotals = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageTotalsResponse' {Maybe [UsageTotal]
usageTotals :: Maybe [UsageTotal]
$sel:usageTotals:GetUsageTotalsResponse' :: GetUsageTotalsResponse -> Maybe [UsageTotal]
usageTotals} -> Maybe [UsageTotal]
usageTotals) (\s :: GetUsageTotalsResponse
s@GetUsageTotalsResponse' {} Maybe [UsageTotal]
a -> GetUsageTotalsResponse
s {$sel:usageTotals:GetUsageTotalsResponse' :: Maybe [UsageTotal]
usageTotals = Maybe [UsageTotal]
a} :: GetUsageTotalsResponse) 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 response's http status code.
getUsageTotalsResponse_httpStatus :: Lens.Lens' GetUsageTotalsResponse Prelude.Int
getUsageTotalsResponse_httpStatus :: Lens' GetUsageTotalsResponse Int
getUsageTotalsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageTotalsResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetUsageTotalsResponse' :: GetUsageTotalsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetUsageTotalsResponse
s@GetUsageTotalsResponse' {} Int
a -> GetUsageTotalsResponse
s {$sel:httpStatus:GetUsageTotalsResponse' :: Int
httpStatus = Int
a} :: GetUsageTotalsResponse)

instance Prelude.NFData GetUsageTotalsResponse where
  rnf :: GetUsageTotalsResponse -> ()
rnf GetUsageTotalsResponse' {Int
Maybe [UsageTotal]
Maybe TimeRange
httpStatus :: Int
usageTotals :: Maybe [UsageTotal]
timeRange :: Maybe TimeRange
$sel:httpStatus:GetUsageTotalsResponse' :: GetUsageTotalsResponse -> Int
$sel:usageTotals:GetUsageTotalsResponse' :: GetUsageTotalsResponse -> Maybe [UsageTotal]
$sel:timeRange:GetUsageTotalsResponse' :: GetUsageTotalsResponse -> Maybe TimeRange
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe TimeRange
timeRange
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [UsageTotal]
usageTotals
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus