{-# 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.GetUsageStatistics
-- 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) quotas and aggregated usage data for one or more
-- accounts.
--
-- This operation returns paginated results.
module Amazonka.MacieV2.GetUsageStatistics
  ( -- * Creating a Request
    GetUsageStatistics (..),
    newGetUsageStatistics,

    -- * Request Lenses
    getUsageStatistics_timeRange,
    getUsageStatistics_nextToken,
    getUsageStatistics_filterBy,
    getUsageStatistics_maxResults,
    getUsageStatistics_sortBy,

    -- * Destructuring the Response
    GetUsageStatisticsResponse (..),
    newGetUsageStatisticsResponse,

    -- * Response Lenses
    getUsageStatisticsResponse_timeRange,
    getUsageStatisticsResponse_records,
    getUsageStatisticsResponse_nextToken,
    getUsageStatisticsResponse_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:/ 'newGetUsageStatistics' smart constructor.
data GetUsageStatistics = GetUsageStatistics'
  { -- | The inclusive time period to query usage 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,
    -- Amazon Macie provides usage data for the preceding 30 days.
    GetUsageStatistics -> Maybe TimeRange
timeRange :: Prelude.Maybe TimeRange,
    -- | The nextToken string that specifies which page of results to return in a
    -- paginated response.
    GetUsageStatistics -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | An array of objects, one for each condition to use to filter the query
    -- results. If you specify more than one condition, Amazon Macie uses an
    -- AND operator to join the conditions.
    GetUsageStatistics -> Maybe [UsageStatisticsFilter]
filterBy :: Prelude.Maybe [UsageStatisticsFilter],
    -- | The maximum number of items to include in each page of the response.
    GetUsageStatistics -> Maybe Int
maxResults :: Prelude.Maybe Prelude.Int,
    -- | The criteria to use to sort the query results.
    GetUsageStatistics -> Maybe UsageStatisticsSortBy
sortBy :: Prelude.Maybe UsageStatisticsSortBy
  }
  deriving (GetUsageStatistics -> GetUsageStatistics -> Bool
(GetUsageStatistics -> GetUsageStatistics -> Bool)
-> (GetUsageStatistics -> GetUsageStatistics -> Bool)
-> Eq GetUsageStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetUsageStatistics -> GetUsageStatistics -> Bool
$c/= :: GetUsageStatistics -> GetUsageStatistics -> Bool
== :: GetUsageStatistics -> GetUsageStatistics -> Bool
$c== :: GetUsageStatistics -> GetUsageStatistics -> Bool
Prelude.Eq, ReadPrec [GetUsageStatistics]
ReadPrec GetUsageStatistics
Int -> ReadS GetUsageStatistics
ReadS [GetUsageStatistics]
(Int -> ReadS GetUsageStatistics)
-> ReadS [GetUsageStatistics]
-> ReadPrec GetUsageStatistics
-> ReadPrec [GetUsageStatistics]
-> Read GetUsageStatistics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetUsageStatistics]
$creadListPrec :: ReadPrec [GetUsageStatistics]
readPrec :: ReadPrec GetUsageStatistics
$creadPrec :: ReadPrec GetUsageStatistics
readList :: ReadS [GetUsageStatistics]
$creadList :: ReadS [GetUsageStatistics]
readsPrec :: Int -> ReadS GetUsageStatistics
$creadsPrec :: Int -> ReadS GetUsageStatistics
Prelude.Read, Int -> GetUsageStatistics -> ShowS
[GetUsageStatistics] -> ShowS
GetUsageStatistics -> String
(Int -> GetUsageStatistics -> ShowS)
-> (GetUsageStatistics -> String)
-> ([GetUsageStatistics] -> ShowS)
-> Show GetUsageStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetUsageStatistics] -> ShowS
$cshowList :: [GetUsageStatistics] -> ShowS
show :: GetUsageStatistics -> String
$cshow :: GetUsageStatistics -> String
showsPrec :: Int -> GetUsageStatistics -> ShowS
$cshowsPrec :: Int -> GetUsageStatistics -> ShowS
Prelude.Show, (forall x. GetUsageStatistics -> Rep GetUsageStatistics x)
-> (forall x. Rep GetUsageStatistics x -> GetUsageStatistics)
-> Generic GetUsageStatistics
forall x. Rep GetUsageStatistics x -> GetUsageStatistics
forall x. GetUsageStatistics -> Rep GetUsageStatistics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetUsageStatistics x -> GetUsageStatistics
$cfrom :: forall x. GetUsageStatistics -> Rep GetUsageStatistics x
Prelude.Generic)

-- |
-- Create a value of 'GetUsageStatistics' 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', 'getUsageStatistics_timeRange' - The inclusive time period to query usage 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,
-- Amazon Macie provides usage data for the preceding 30 days.
--
-- 'nextToken', 'getUsageStatistics_nextToken' - The nextToken string that specifies which page of results to return in a
-- paginated response.
--
-- 'filterBy', 'getUsageStatistics_filterBy' - An array of objects, one for each condition to use to filter the query
-- results. If you specify more than one condition, Amazon Macie uses an
-- AND operator to join the conditions.
--
-- 'maxResults', 'getUsageStatistics_maxResults' - The maximum number of items to include in each page of the response.
--
-- 'sortBy', 'getUsageStatistics_sortBy' - The criteria to use to sort the query results.
newGetUsageStatistics ::
  GetUsageStatistics
newGetUsageStatistics :: GetUsageStatistics
newGetUsageStatistics =
  GetUsageStatistics' :: Maybe TimeRange
-> Maybe Text
-> Maybe [UsageStatisticsFilter]
-> Maybe Int
-> Maybe UsageStatisticsSortBy
-> GetUsageStatistics
GetUsageStatistics'
    { $sel:timeRange:GetUsageStatistics' :: Maybe TimeRange
timeRange = Maybe TimeRange
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetUsageStatistics' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filterBy:GetUsageStatistics' :: Maybe [UsageStatisticsFilter]
filterBy = Maybe [UsageStatisticsFilter]
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:GetUsageStatistics' :: Maybe Int
maxResults = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:sortBy:GetUsageStatistics' :: Maybe UsageStatisticsSortBy
sortBy = Maybe UsageStatisticsSortBy
forall a. Maybe a
Prelude.Nothing
    }

-- | The inclusive time period to query usage 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,
-- Amazon Macie provides usage data for the preceding 30 days.
getUsageStatistics_timeRange :: Lens.Lens' GetUsageStatistics (Prelude.Maybe TimeRange)
getUsageStatistics_timeRange :: (Maybe TimeRange -> f (Maybe TimeRange))
-> GetUsageStatistics -> f GetUsageStatistics
getUsageStatistics_timeRange = (GetUsageStatistics -> Maybe TimeRange)
-> (GetUsageStatistics -> Maybe TimeRange -> GetUsageStatistics)
-> Lens
     GetUsageStatistics
     GetUsageStatistics
     (Maybe TimeRange)
     (Maybe TimeRange)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatistics' {Maybe TimeRange
timeRange :: Maybe TimeRange
$sel:timeRange:GetUsageStatistics' :: GetUsageStatistics -> Maybe TimeRange
timeRange} -> Maybe TimeRange
timeRange) (\s :: GetUsageStatistics
s@GetUsageStatistics' {} Maybe TimeRange
a -> GetUsageStatistics
s {$sel:timeRange:GetUsageStatistics' :: Maybe TimeRange
timeRange = Maybe TimeRange
a} :: GetUsageStatistics)

-- | The nextToken string that specifies which page of results to return in a
-- paginated response.
getUsageStatistics_nextToken :: Lens.Lens' GetUsageStatistics (Prelude.Maybe Prelude.Text)
getUsageStatistics_nextToken :: (Maybe Text -> f (Maybe Text))
-> GetUsageStatistics -> f GetUsageStatistics
getUsageStatistics_nextToken = (GetUsageStatistics -> Maybe Text)
-> (GetUsageStatistics -> Maybe Text -> GetUsageStatistics)
-> Lens
     GetUsageStatistics GetUsageStatistics (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatistics' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetUsageStatistics' :: GetUsageStatistics -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetUsageStatistics
s@GetUsageStatistics' {} Maybe Text
a -> GetUsageStatistics
s {$sel:nextToken:GetUsageStatistics' :: Maybe Text
nextToken = Maybe Text
a} :: GetUsageStatistics)

-- | An array of objects, one for each condition to use to filter the query
-- results. If you specify more than one condition, Amazon Macie uses an
-- AND operator to join the conditions.
getUsageStatistics_filterBy :: Lens.Lens' GetUsageStatistics (Prelude.Maybe [UsageStatisticsFilter])
getUsageStatistics_filterBy :: (Maybe [UsageStatisticsFilter]
 -> f (Maybe [UsageStatisticsFilter]))
-> GetUsageStatistics -> f GetUsageStatistics
getUsageStatistics_filterBy = (GetUsageStatistics -> Maybe [UsageStatisticsFilter])
-> (GetUsageStatistics
    -> Maybe [UsageStatisticsFilter] -> GetUsageStatistics)
-> Lens
     GetUsageStatistics
     GetUsageStatistics
     (Maybe [UsageStatisticsFilter])
     (Maybe [UsageStatisticsFilter])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatistics' {Maybe [UsageStatisticsFilter]
filterBy :: Maybe [UsageStatisticsFilter]
$sel:filterBy:GetUsageStatistics' :: GetUsageStatistics -> Maybe [UsageStatisticsFilter]
filterBy} -> Maybe [UsageStatisticsFilter]
filterBy) (\s :: GetUsageStatistics
s@GetUsageStatistics' {} Maybe [UsageStatisticsFilter]
a -> GetUsageStatistics
s {$sel:filterBy:GetUsageStatistics' :: Maybe [UsageStatisticsFilter]
filterBy = Maybe [UsageStatisticsFilter]
a} :: GetUsageStatistics) ((Maybe [UsageStatisticsFilter]
  -> f (Maybe [UsageStatisticsFilter]))
 -> GetUsageStatistics -> f GetUsageStatistics)
-> ((Maybe [UsageStatisticsFilter]
     -> f (Maybe [UsageStatisticsFilter]))
    -> Maybe [UsageStatisticsFilter]
    -> f (Maybe [UsageStatisticsFilter]))
-> (Maybe [UsageStatisticsFilter]
    -> f (Maybe [UsageStatisticsFilter]))
-> GetUsageStatistics
-> f GetUsageStatistics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UsageStatisticsFilter]
  [UsageStatisticsFilter]
  [UsageStatisticsFilter]
  [UsageStatisticsFilter]
-> Iso
     (Maybe [UsageStatisticsFilter])
     (Maybe [UsageStatisticsFilter])
     (Maybe [UsageStatisticsFilter])
     (Maybe [UsageStatisticsFilter])
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
  [UsageStatisticsFilter]
  [UsageStatisticsFilter]
  [UsageStatisticsFilter]
  [UsageStatisticsFilter]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The maximum number of items to include in each page of the response.
getUsageStatistics_maxResults :: Lens.Lens' GetUsageStatistics (Prelude.Maybe Prelude.Int)
getUsageStatistics_maxResults :: (Maybe Int -> f (Maybe Int))
-> GetUsageStatistics -> f GetUsageStatistics
getUsageStatistics_maxResults = (GetUsageStatistics -> Maybe Int)
-> (GetUsageStatistics -> Maybe Int -> GetUsageStatistics)
-> Lens
     GetUsageStatistics GetUsageStatistics (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatistics' {Maybe Int
maxResults :: Maybe Int
$sel:maxResults:GetUsageStatistics' :: GetUsageStatistics -> Maybe Int
maxResults} -> Maybe Int
maxResults) (\s :: GetUsageStatistics
s@GetUsageStatistics' {} Maybe Int
a -> GetUsageStatistics
s {$sel:maxResults:GetUsageStatistics' :: Maybe Int
maxResults = Maybe Int
a} :: GetUsageStatistics)

-- | The criteria to use to sort the query results.
getUsageStatistics_sortBy :: Lens.Lens' GetUsageStatistics (Prelude.Maybe UsageStatisticsSortBy)
getUsageStatistics_sortBy :: (Maybe UsageStatisticsSortBy -> f (Maybe UsageStatisticsSortBy))
-> GetUsageStatistics -> f GetUsageStatistics
getUsageStatistics_sortBy = (GetUsageStatistics -> Maybe UsageStatisticsSortBy)
-> (GetUsageStatistics
    -> Maybe UsageStatisticsSortBy -> GetUsageStatistics)
-> Lens
     GetUsageStatistics
     GetUsageStatistics
     (Maybe UsageStatisticsSortBy)
     (Maybe UsageStatisticsSortBy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatistics' {Maybe UsageStatisticsSortBy
sortBy :: Maybe UsageStatisticsSortBy
$sel:sortBy:GetUsageStatistics' :: GetUsageStatistics -> Maybe UsageStatisticsSortBy
sortBy} -> Maybe UsageStatisticsSortBy
sortBy) (\s :: GetUsageStatistics
s@GetUsageStatistics' {} Maybe UsageStatisticsSortBy
a -> GetUsageStatistics
s {$sel:sortBy:GetUsageStatistics' :: Maybe UsageStatisticsSortBy
sortBy = Maybe UsageStatisticsSortBy
a} :: GetUsageStatistics)

instance Core.AWSPager GetUsageStatistics where
  page :: GetUsageStatistics
-> AWSResponse GetUsageStatistics -> Maybe GetUsageStatistics
page GetUsageStatistics
rq AWSResponse GetUsageStatistics
rs
    | Maybe Text -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetUsageStatistics
GetUsageStatisticsResponse
rs
            GetUsageStatisticsResponse
-> Getting (First Text) GetUsageStatisticsResponse Text
-> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> GetUsageStatisticsResponse
-> Const (First Text) GetUsageStatisticsResponse
Lens' GetUsageStatisticsResponse (Maybe Text)
getUsageStatisticsResponse_nextToken
              ((Maybe Text -> Const (First Text) (Maybe Text))
 -> GetUsageStatisticsResponse
 -> Const (First Text) GetUsageStatisticsResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) GetUsageStatisticsResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe GetUsageStatistics
forall a. Maybe a
Prelude.Nothing
    | Maybe [UsageRecord] -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetUsageStatistics
GetUsageStatisticsResponse
rs
            GetUsageStatisticsResponse
-> Getting
     (First [UsageRecord]) GetUsageStatisticsResponse [UsageRecord]
-> Maybe [UsageRecord]
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe [UsageRecord]
 -> Const (First [UsageRecord]) (Maybe [UsageRecord]))
-> GetUsageStatisticsResponse
-> Const (First [UsageRecord]) GetUsageStatisticsResponse
Lens' GetUsageStatisticsResponse (Maybe [UsageRecord])
getUsageStatisticsResponse_records
              ((Maybe [UsageRecord]
  -> Const (First [UsageRecord]) (Maybe [UsageRecord]))
 -> GetUsageStatisticsResponse
 -> Const (First [UsageRecord]) GetUsageStatisticsResponse)
-> (([UsageRecord] -> Const (First [UsageRecord]) [UsageRecord])
    -> Maybe [UsageRecord]
    -> Const (First [UsageRecord]) (Maybe [UsageRecord]))
-> Getting
     (First [UsageRecord]) GetUsageStatisticsResponse [UsageRecord]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([UsageRecord] -> Const (First [UsageRecord]) [UsageRecord])
-> Maybe [UsageRecord]
-> Const (First [UsageRecord]) (Maybe [UsageRecord])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe GetUsageStatistics
forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
      GetUsageStatistics -> Maybe GetUsageStatistics
forall a. a -> Maybe a
Prelude.Just (GetUsageStatistics -> Maybe GetUsageStatistics)
-> GetUsageStatistics -> Maybe GetUsageStatistics
forall a b. (a -> b) -> a -> b
Prelude.$
        GetUsageStatistics
rq
          GetUsageStatistics
-> (GetUsageStatistics -> GetUsageStatistics) -> GetUsageStatistics
forall a b. a -> (a -> b) -> b
Prelude.& (Maybe Text -> Identity (Maybe Text))
-> GetUsageStatistics -> Identity GetUsageStatistics
Lens
  GetUsageStatistics GetUsageStatistics (Maybe Text) (Maybe Text)
getUsageStatistics_nextToken
          ((Maybe Text -> Identity (Maybe Text))
 -> GetUsageStatistics -> Identity GetUsageStatistics)
-> Maybe Text -> GetUsageStatistics -> GetUsageStatistics
forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetUsageStatistics
GetUsageStatisticsResponse
rs
          GetUsageStatisticsResponse
-> Getting (First Text) GetUsageStatisticsResponse Text
-> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> GetUsageStatisticsResponse
-> Const (First Text) GetUsageStatisticsResponse
Lens' GetUsageStatisticsResponse (Maybe Text)
getUsageStatisticsResponse_nextToken
            ((Maybe Text -> Const (First Text) (Maybe Text))
 -> GetUsageStatisticsResponse
 -> Const (First Text) GetUsageStatisticsResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) GetUsageStatisticsResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest GetUsageStatistics where
  type
    AWSResponse GetUsageStatistics =
      GetUsageStatisticsResponse
  request :: GetUsageStatistics -> Request GetUsageStatistics
request = Service -> GetUsageStatistics -> Request GetUsageStatistics
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetUsageStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetUsageStatistics)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetUsageStatistics))
-> Logger
-> Service
-> Proxy GetUsageStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetUsageStatistics)))
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 [UsageRecord]
-> Maybe Text
-> Int
-> GetUsageStatisticsResponse
GetUsageStatisticsResponse'
            (Maybe TimeRange
 -> Maybe [UsageRecord]
 -> Maybe Text
 -> Int
 -> GetUsageStatisticsResponse)
-> Either String (Maybe TimeRange)
-> Either
     String
     (Maybe [UsageRecord]
      -> Maybe Text -> Int -> GetUsageStatisticsResponse)
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 [UsageRecord]
   -> Maybe Text -> Int -> GetUsageStatisticsResponse)
-> Either String (Maybe [UsageRecord])
-> Either String (Maybe Text -> Int -> GetUsageStatisticsResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [UsageRecord]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"records" Either String (Maybe (Maybe [UsageRecord]))
-> Maybe [UsageRecord] -> Either String (Maybe [UsageRecord])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [UsageRecord]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Maybe Text -> Int -> GetUsageStatisticsResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetUsageStatisticsResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"nextToken")
            Either String (Int -> GetUsageStatisticsResponse)
-> Either String Int -> Either String GetUsageStatisticsResponse
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 GetUsageStatistics

instance Prelude.NFData GetUsageStatistics

instance Core.ToHeaders GetUsageStatistics where
  toHeaders :: GetUsageStatistics -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetUsageStatistics -> 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.ToJSON GetUsageStatistics where
  toJSON :: GetUsageStatistics -> Value
toJSON GetUsageStatistics' {Maybe Int
Maybe [UsageStatisticsFilter]
Maybe Text
Maybe TimeRange
Maybe UsageStatisticsSortBy
sortBy :: Maybe UsageStatisticsSortBy
maxResults :: Maybe Int
filterBy :: Maybe [UsageStatisticsFilter]
nextToken :: Maybe Text
timeRange :: Maybe TimeRange
$sel:sortBy:GetUsageStatistics' :: GetUsageStatistics -> Maybe UsageStatisticsSortBy
$sel:maxResults:GetUsageStatistics' :: GetUsageStatistics -> Maybe Int
$sel:filterBy:GetUsageStatistics' :: GetUsageStatistics -> Maybe [UsageStatisticsFilter]
$sel:nextToken:GetUsageStatistics' :: GetUsageStatistics -> Maybe Text
$sel:timeRange:GetUsageStatistics' :: GetUsageStatistics -> Maybe TimeRange
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"timeRange" Text -> TimeRange -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimeRange -> Pair) -> Maybe TimeRange -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimeRange
timeRange,
            (Text
"nextToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            (Text
"filterBy" Text -> [UsageStatisticsFilter] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([UsageStatisticsFilter] -> Pair)
-> Maybe [UsageStatisticsFilter] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [UsageStatisticsFilter]
filterBy,
            (Text
"maxResults" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
maxResults,
            (Text
"sortBy" Text -> UsageStatisticsSortBy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (UsageStatisticsSortBy -> Pair)
-> Maybe UsageStatisticsSortBy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe UsageStatisticsSortBy
sortBy
          ]
      )

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

instance Core.ToQuery GetUsageStatistics where
  toQuery :: GetUsageStatistics -> QueryString
toQuery = QueryString -> GetUsageStatistics -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newGetUsageStatisticsResponse' smart constructor.
data GetUsageStatisticsResponse = GetUsageStatisticsResponse'
  { -- | 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.
    GetUsageStatisticsResponse -> Maybe TimeRange
timeRange :: Prelude.Maybe TimeRange,
    -- | An array of objects that contains the results of the query. Each object
    -- contains the data for an account that meets the filter criteria
    -- specified in the request.
    GetUsageStatisticsResponse -> Maybe [UsageRecord]
records :: Prelude.Maybe [UsageRecord],
    -- | The string to use in a subsequent request to get the next page of
    -- results in a paginated response. This value is null if there are no
    -- additional pages.
    GetUsageStatisticsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetUsageStatisticsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetUsageStatisticsResponse -> GetUsageStatisticsResponse -> Bool
(GetUsageStatisticsResponse -> GetUsageStatisticsResponse -> Bool)
-> (GetUsageStatisticsResponse
    -> GetUsageStatisticsResponse -> Bool)
-> Eq GetUsageStatisticsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetUsageStatisticsResponse -> GetUsageStatisticsResponse -> Bool
$c/= :: GetUsageStatisticsResponse -> GetUsageStatisticsResponse -> Bool
== :: GetUsageStatisticsResponse -> GetUsageStatisticsResponse -> Bool
$c== :: GetUsageStatisticsResponse -> GetUsageStatisticsResponse -> Bool
Prelude.Eq, ReadPrec [GetUsageStatisticsResponse]
ReadPrec GetUsageStatisticsResponse
Int -> ReadS GetUsageStatisticsResponse
ReadS [GetUsageStatisticsResponse]
(Int -> ReadS GetUsageStatisticsResponse)
-> ReadS [GetUsageStatisticsResponse]
-> ReadPrec GetUsageStatisticsResponse
-> ReadPrec [GetUsageStatisticsResponse]
-> Read GetUsageStatisticsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetUsageStatisticsResponse]
$creadListPrec :: ReadPrec [GetUsageStatisticsResponse]
readPrec :: ReadPrec GetUsageStatisticsResponse
$creadPrec :: ReadPrec GetUsageStatisticsResponse
readList :: ReadS [GetUsageStatisticsResponse]
$creadList :: ReadS [GetUsageStatisticsResponse]
readsPrec :: Int -> ReadS GetUsageStatisticsResponse
$creadsPrec :: Int -> ReadS GetUsageStatisticsResponse
Prelude.Read, Int -> GetUsageStatisticsResponse -> ShowS
[GetUsageStatisticsResponse] -> ShowS
GetUsageStatisticsResponse -> String
(Int -> GetUsageStatisticsResponse -> ShowS)
-> (GetUsageStatisticsResponse -> String)
-> ([GetUsageStatisticsResponse] -> ShowS)
-> Show GetUsageStatisticsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetUsageStatisticsResponse] -> ShowS
$cshowList :: [GetUsageStatisticsResponse] -> ShowS
show :: GetUsageStatisticsResponse -> String
$cshow :: GetUsageStatisticsResponse -> String
showsPrec :: Int -> GetUsageStatisticsResponse -> ShowS
$cshowsPrec :: Int -> GetUsageStatisticsResponse -> ShowS
Prelude.Show, (forall x.
 GetUsageStatisticsResponse -> Rep GetUsageStatisticsResponse x)
-> (forall x.
    Rep GetUsageStatisticsResponse x -> GetUsageStatisticsResponse)
-> Generic GetUsageStatisticsResponse
forall x.
Rep GetUsageStatisticsResponse x -> GetUsageStatisticsResponse
forall x.
GetUsageStatisticsResponse -> Rep GetUsageStatisticsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetUsageStatisticsResponse x -> GetUsageStatisticsResponse
$cfrom :: forall x.
GetUsageStatisticsResponse -> Rep GetUsageStatisticsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetUsageStatisticsResponse' 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', 'getUsageStatisticsResponse_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.
--
-- 'records', 'getUsageStatisticsResponse_records' - An array of objects that contains the results of the query. Each object
-- contains the data for an account that meets the filter criteria
-- specified in the request.
--
-- 'nextToken', 'getUsageStatisticsResponse_nextToken' - The string to use in a subsequent request to get the next page of
-- results in a paginated response. This value is null if there are no
-- additional pages.
--
-- 'httpStatus', 'getUsageStatisticsResponse_httpStatus' - The response's http status code.
newGetUsageStatisticsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetUsageStatisticsResponse
newGetUsageStatisticsResponse :: Int -> GetUsageStatisticsResponse
newGetUsageStatisticsResponse Int
pHttpStatus_ =
  GetUsageStatisticsResponse' :: Maybe TimeRange
-> Maybe [UsageRecord]
-> Maybe Text
-> Int
-> GetUsageStatisticsResponse
GetUsageStatisticsResponse'
    { $sel:timeRange:GetUsageStatisticsResponse' :: Maybe TimeRange
timeRange =
        Maybe TimeRange
forall a. Maybe a
Prelude.Nothing,
      $sel:records:GetUsageStatisticsResponse' :: Maybe [UsageRecord]
records = Maybe [UsageRecord]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetUsageStatisticsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetUsageStatisticsResponse' :: 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.
getUsageStatisticsResponse_timeRange :: Lens.Lens' GetUsageStatisticsResponse (Prelude.Maybe TimeRange)
getUsageStatisticsResponse_timeRange :: (Maybe TimeRange -> f (Maybe TimeRange))
-> GetUsageStatisticsResponse -> f GetUsageStatisticsResponse
getUsageStatisticsResponse_timeRange = (GetUsageStatisticsResponse -> Maybe TimeRange)
-> (GetUsageStatisticsResponse
    -> Maybe TimeRange -> GetUsageStatisticsResponse)
-> Lens
     GetUsageStatisticsResponse
     GetUsageStatisticsResponse
     (Maybe TimeRange)
     (Maybe TimeRange)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatisticsResponse' {Maybe TimeRange
timeRange :: Maybe TimeRange
$sel:timeRange:GetUsageStatisticsResponse' :: GetUsageStatisticsResponse -> Maybe TimeRange
timeRange} -> Maybe TimeRange
timeRange) (\s :: GetUsageStatisticsResponse
s@GetUsageStatisticsResponse' {} Maybe TimeRange
a -> GetUsageStatisticsResponse
s {$sel:timeRange:GetUsageStatisticsResponse' :: Maybe TimeRange
timeRange = Maybe TimeRange
a} :: GetUsageStatisticsResponse)

-- | An array of objects that contains the results of the query. Each object
-- contains the data for an account that meets the filter criteria
-- specified in the request.
getUsageStatisticsResponse_records :: Lens.Lens' GetUsageStatisticsResponse (Prelude.Maybe [UsageRecord])
getUsageStatisticsResponse_records :: (Maybe [UsageRecord] -> f (Maybe [UsageRecord]))
-> GetUsageStatisticsResponse -> f GetUsageStatisticsResponse
getUsageStatisticsResponse_records = (GetUsageStatisticsResponse -> Maybe [UsageRecord])
-> (GetUsageStatisticsResponse
    -> Maybe [UsageRecord] -> GetUsageStatisticsResponse)
-> Lens' GetUsageStatisticsResponse (Maybe [UsageRecord])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatisticsResponse' {Maybe [UsageRecord]
records :: Maybe [UsageRecord]
$sel:records:GetUsageStatisticsResponse' :: GetUsageStatisticsResponse -> Maybe [UsageRecord]
records} -> Maybe [UsageRecord]
records) (\s :: GetUsageStatisticsResponse
s@GetUsageStatisticsResponse' {} Maybe [UsageRecord]
a -> GetUsageStatisticsResponse
s {$sel:records:GetUsageStatisticsResponse' :: Maybe [UsageRecord]
records = Maybe [UsageRecord]
a} :: GetUsageStatisticsResponse) ((Maybe [UsageRecord] -> f (Maybe [UsageRecord]))
 -> GetUsageStatisticsResponse -> f GetUsageStatisticsResponse)
-> ((Maybe [UsageRecord] -> f (Maybe [UsageRecord]))
    -> Maybe [UsageRecord] -> f (Maybe [UsageRecord]))
-> (Maybe [UsageRecord] -> f (Maybe [UsageRecord]))
-> GetUsageStatisticsResponse
-> f GetUsageStatisticsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [UsageRecord] [UsageRecord] [UsageRecord] [UsageRecord]
-> Iso
     (Maybe [UsageRecord])
     (Maybe [UsageRecord])
     (Maybe [UsageRecord])
     (Maybe [UsageRecord])
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 [UsageRecord] [UsageRecord] [UsageRecord] [UsageRecord]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The string to use in a subsequent request to get the next page of
-- results in a paginated response. This value is null if there are no
-- additional pages.
getUsageStatisticsResponse_nextToken :: Lens.Lens' GetUsageStatisticsResponse (Prelude.Maybe Prelude.Text)
getUsageStatisticsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> GetUsageStatisticsResponse -> f GetUsageStatisticsResponse
getUsageStatisticsResponse_nextToken = (GetUsageStatisticsResponse -> Maybe Text)
-> (GetUsageStatisticsResponse
    -> Maybe Text -> GetUsageStatisticsResponse)
-> Lens' GetUsageStatisticsResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatisticsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetUsageStatisticsResponse' :: GetUsageStatisticsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetUsageStatisticsResponse
s@GetUsageStatisticsResponse' {} Maybe Text
a -> GetUsageStatisticsResponse
s {$sel:nextToken:GetUsageStatisticsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetUsageStatisticsResponse)

-- | The response's http status code.
getUsageStatisticsResponse_httpStatus :: Lens.Lens' GetUsageStatisticsResponse Prelude.Int
getUsageStatisticsResponse_httpStatus :: (Int -> f Int)
-> GetUsageStatisticsResponse -> f GetUsageStatisticsResponse
getUsageStatisticsResponse_httpStatus = (GetUsageStatisticsResponse -> Int)
-> (GetUsageStatisticsResponse
    -> Int -> GetUsageStatisticsResponse)
-> Lens
     GetUsageStatisticsResponse GetUsageStatisticsResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetUsageStatisticsResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetUsageStatisticsResponse' :: GetUsageStatisticsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetUsageStatisticsResponse
s@GetUsageStatisticsResponse' {} Int
a -> GetUsageStatisticsResponse
s {$sel:httpStatus:GetUsageStatisticsResponse' :: Int
httpStatus = Int
a} :: GetUsageStatisticsResponse)

instance Prelude.NFData GetUsageStatisticsResponse