{-# 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-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)
--
-- 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.Lens as Lens
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
(GetUsageTotals -> GetUsageTotals -> Bool)
-> (GetUsageTotals -> GetUsageTotals -> Bool) -> Eq GetUsageTotals
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]
(Int -> ReadS GetUsageTotals)
-> ReadS [GetUsageTotals]
-> ReadPrec GetUsageTotals
-> ReadPrec [GetUsageTotals]
-> Read 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
(Int -> GetUsageTotals -> ShowS)
-> (GetUsageTotals -> String)
-> ([GetUsageTotals] -> ShowS)
-> Show GetUsageTotals
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. GetUsageTotals -> Rep GetUsageTotals x)
-> (forall x. Rep GetUsageTotals x -> GetUsageTotals)
-> Generic GetUsageTotals
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' :: Maybe Text -> GetUsageTotals
GetUsageTotals' {$sel:timeRange:GetUsageTotals' :: Maybe Text
timeRange = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> GetUsageTotals -> f GetUsageTotals
getUsageTotals_timeRange = (GetUsageTotals -> Maybe Text)
-> (GetUsageTotals -> Maybe Text -> GetUsageTotals)
-> Lens GetUsageTotals GetUsageTotals (Maybe Text) (Maybe Text)
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 :: GetUsageTotals -> Request GetUsageTotals
request = Service -> GetUsageTotals -> Request GetUsageTotals
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetUsageTotals
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetUsageTotals)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetUsageTotals))
-> Logger
-> Service
-> Proxy GetUsageTotals
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetUsageTotals)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> 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'
            (Maybe TimeRange
 -> Maybe [UsageTotal] -> Int -> GetUsageTotalsResponse)
-> Either String (Maybe TimeRange)
-> Either
     String (Maybe [UsageTotal] -> Int -> GetUsageTotalsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe TimeRange)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"timeRange")
            Either String (Maybe [UsageTotal] -> Int -> GetUsageTotalsResponse)
-> Either String (Maybe [UsageTotal])
-> Either String (Int -> GetUsageTotalsResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [UsageTotal]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"usageTotals" Either String (Maybe (Maybe [UsageTotal]))
-> Maybe [UsageTotal] -> Either String (Maybe [UsageTotal])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [UsageTotal]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetUsageTotalsResponse)
-> Either String Int -> Either String GetUsageTotalsResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetUsageTotals

instance Prelude.NFData GetUsageTotals

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

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

instance Core.ToQuery GetUsageTotals where
  toQuery :: GetUsageTotals -> QueryString
toQuery GetUsageTotals' {Maybe Text
timeRange :: Maybe Text
$sel:timeRange:GetUsageTotals' :: GetUsageTotals -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"timeRange" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: 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
(GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool)
-> (GetUsageTotalsResponse -> GetUsageTotalsResponse -> Bool)
-> Eq GetUsageTotalsResponse
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]
(Int -> ReadS GetUsageTotalsResponse)
-> ReadS [GetUsageTotalsResponse]
-> ReadPrec GetUsageTotalsResponse
-> ReadPrec [GetUsageTotalsResponse]
-> Read 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
(Int -> GetUsageTotalsResponse -> ShowS)
-> (GetUsageTotalsResponse -> String)
-> ([GetUsageTotalsResponse] -> ShowS)
-> Show GetUsageTotalsResponse
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. GetUsageTotalsResponse -> Rep GetUsageTotalsResponse x)
-> (forall x.
    Rep GetUsageTotalsResponse x -> GetUsageTotalsResponse)
-> Generic GetUsageTotalsResponse
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' :: Maybe TimeRange
-> Maybe [UsageTotal] -> Int -> GetUsageTotalsResponse
GetUsageTotalsResponse'
    { $sel:timeRange:GetUsageTotalsResponse' :: Maybe TimeRange
timeRange =
        Maybe TimeRange
forall a. Maybe a
Prelude.Nothing,
      $sel:usageTotals:GetUsageTotalsResponse' :: Maybe [UsageTotal]
usageTotals = Maybe [UsageTotal]
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 :: (Maybe TimeRange -> f (Maybe TimeRange))
-> GetUsageTotalsResponse -> f GetUsageTotalsResponse
getUsageTotalsResponse_timeRange = (GetUsageTotalsResponse -> Maybe TimeRange)
-> (GetUsageTotalsResponse
    -> Maybe TimeRange -> GetUsageTotalsResponse)
-> Lens
     GetUsageTotalsResponse
     GetUsageTotalsResponse
     (Maybe TimeRange)
     (Maybe 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 :: (Maybe [UsageTotal] -> f (Maybe [UsageTotal]))
-> GetUsageTotalsResponse -> f GetUsageTotalsResponse
getUsageTotalsResponse_usageTotals = (GetUsageTotalsResponse -> Maybe [UsageTotal])
-> (GetUsageTotalsResponse
    -> Maybe [UsageTotal] -> GetUsageTotalsResponse)
-> Lens
     GetUsageTotalsResponse
     GetUsageTotalsResponse
     (Maybe [UsageTotal])
     (Maybe [UsageTotal])
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) ((Maybe [UsageTotal] -> f (Maybe [UsageTotal]))
 -> GetUsageTotalsResponse -> f GetUsageTotalsResponse)
-> ((Maybe [UsageTotal] -> f (Maybe [UsageTotal]))
    -> Maybe [UsageTotal] -> f (Maybe [UsageTotal]))
-> (Maybe [UsageTotal] -> f (Maybe [UsageTotal]))
-> GetUsageTotalsResponse
-> f GetUsageTotalsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [UsageTotal] [UsageTotal] [UsageTotal] [UsageTotal]
-> Iso
     (Maybe [UsageTotal])
     (Maybe [UsageTotal])
     (Maybe [UsageTotal])
     (Maybe [UsageTotal])
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 [UsageTotal] [UsageTotal] [UsageTotal] [UsageTotal]
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 :: (Int -> f Int)
-> GetUsageTotalsResponse -> f GetUsageTotalsResponse
getUsageTotalsResponse_httpStatus = (GetUsageTotalsResponse -> Int)
-> (GetUsageTotalsResponse -> Int -> GetUsageTotalsResponse)
-> Lens GetUsageTotalsResponse GetUsageTotalsResponse Int Int
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