{-# 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.CostExplorer.GetReservationUtilization
-- 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 the reservation utilization for your account. Management
-- account in an organization have access to member accounts. You can
-- filter data by dimensions in a time period. You can use
-- @GetDimensionValues@ to determine the possible dimension values.
-- Currently, you can group only by @SUBSCRIPTION_ID@.
module Amazonka.CostExplorer.GetReservationUtilization
  ( -- * Creating a Request
    GetReservationUtilization (..),
    newGetReservationUtilization,

    -- * Request Lenses
    getReservationUtilization_groupBy,
    getReservationUtilization_nextPageToken,
    getReservationUtilization_granularity,
    getReservationUtilization_filter,
    getReservationUtilization_maxResults,
    getReservationUtilization_sortBy,
    getReservationUtilization_timePeriod,

    -- * Destructuring the Response
    GetReservationUtilizationResponse (..),
    newGetReservationUtilizationResponse,

    -- * Response Lenses
    getReservationUtilizationResponse_nextPageToken,
    getReservationUtilizationResponse_total,
    getReservationUtilizationResponse_httpStatus,
    getReservationUtilizationResponse_utilizationsByTime,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetReservationUtilization' smart constructor.
data GetReservationUtilization = GetReservationUtilization'
  { -- | Groups only by @SUBSCRIPTION_ID@. Metadata is included.
    GetReservationUtilization -> Maybe [GroupDefinition]
groupBy :: Prelude.Maybe [GroupDefinition],
    -- | The token to retrieve the next set of results. Amazon Web Services
    -- provides the token when the response from a previous call has more
    -- results than the maximum page size.
    GetReservationUtilization -> Maybe Text
nextPageToken :: Prelude.Maybe Prelude.Text,
    -- | If @GroupBy@ is set, @Granularity@ can\'t be set. If @Granularity@
    -- isn\'t set, the response object doesn\'t include @Granularity@, either
    -- @MONTHLY@ or @DAILY@. If both @GroupBy@ and @Granularity@ aren\'t set,
    -- @GetReservationUtilization@ defaults to @DAILY@.
    --
    -- The @GetReservationUtilization@ operation supports only @DAILY@ and
    -- @MONTHLY@ granularities.
    GetReservationUtilization -> Maybe Granularity
granularity :: Prelude.Maybe Granularity,
    -- | Filters utilization data by dimensions. You can filter by the following
    -- dimensions:
    --
    -- -   AZ
    --
    -- -   CACHE_ENGINE
    --
    -- -   DEPLOYMENT_OPTION
    --
    -- -   INSTANCE_TYPE
    --
    -- -   LINKED_ACCOUNT
    --
    -- -   OPERATING_SYSTEM
    --
    -- -   PLATFORM
    --
    -- -   REGION
    --
    -- -   SERVICE
    --
    -- -   SCOPE
    --
    -- -   TENANCY
    --
    -- @GetReservationUtilization@ uses the same
    -- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Expression.html Expression>
    -- object as the other operations, but only @AND@ is supported among each
    -- dimension, and nesting is supported up to only one level deep. If there
    -- are multiple values for a dimension, they are OR\'d together.
    GetReservationUtilization -> Maybe Expression
filter' :: Prelude.Maybe Expression,
    -- | The maximum number of objects that you returned for this request. If
    -- more objects are available, in the response, Amazon Web Services
    -- provides a NextPageToken value that you can use in a subsequent call to
    -- get the next batch of objects.
    GetReservationUtilization -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The value by which you want to sort the data.
    --
    -- The following values are supported for @Key@:
    --
    -- -   @UtilizationPercentage@
    --
    -- -   @UtilizationPercentageInUnits@
    --
    -- -   @PurchasedHours@
    --
    -- -   @PurchasedUnits@
    --
    -- -   @TotalActualHours@
    --
    -- -   @TotalActualUnits@
    --
    -- -   @UnusedHours@
    --
    -- -   @UnusedUnits@
    --
    -- -   @OnDemandCostOfRIHoursUsed@
    --
    -- -   @NetRISavings@
    --
    -- -   @TotalPotentialRISavings@
    --
    -- -   @AmortizedUpfrontFee@
    --
    -- -   @AmortizedRecurringFee@
    --
    -- -   @TotalAmortizedFee@
    --
    -- -   @RICostForUnusedHours@
    --
    -- -   @RealizedSavings@
    --
    -- -   @UnrealizedSavings@
    --
    -- Supported values for @SortOrder@ are @ASCENDING@ or @DESCENDING@.
    GetReservationUtilization -> Maybe SortDefinition
sortBy :: Prelude.Maybe SortDefinition,
    -- | Sets the start and end dates for retrieving RI utilization. The start
    -- date is inclusive, but the end date is exclusive. For example, if
    -- @start@ is @2017-01-01@ and @end@ is @2017-05-01@, then the cost and
    -- usage data is retrieved from @2017-01-01@ up to and including
    -- @2017-04-30@ but not including @2017-05-01@.
    GetReservationUtilization -> DateInterval
timePeriod :: DateInterval
  }
  deriving (GetReservationUtilization -> GetReservationUtilization -> Bool
(GetReservationUtilization -> GetReservationUtilization -> Bool)
-> (GetReservationUtilization -> GetReservationUtilization -> Bool)
-> Eq GetReservationUtilization
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetReservationUtilization -> GetReservationUtilization -> Bool
$c/= :: GetReservationUtilization -> GetReservationUtilization -> Bool
== :: GetReservationUtilization -> GetReservationUtilization -> Bool
$c== :: GetReservationUtilization -> GetReservationUtilization -> Bool
Prelude.Eq, ReadPrec [GetReservationUtilization]
ReadPrec GetReservationUtilization
Int -> ReadS GetReservationUtilization
ReadS [GetReservationUtilization]
(Int -> ReadS GetReservationUtilization)
-> ReadS [GetReservationUtilization]
-> ReadPrec GetReservationUtilization
-> ReadPrec [GetReservationUtilization]
-> Read GetReservationUtilization
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetReservationUtilization]
$creadListPrec :: ReadPrec [GetReservationUtilization]
readPrec :: ReadPrec GetReservationUtilization
$creadPrec :: ReadPrec GetReservationUtilization
readList :: ReadS [GetReservationUtilization]
$creadList :: ReadS [GetReservationUtilization]
readsPrec :: Int -> ReadS GetReservationUtilization
$creadsPrec :: Int -> ReadS GetReservationUtilization
Prelude.Read, Int -> GetReservationUtilization -> ShowS
[GetReservationUtilization] -> ShowS
GetReservationUtilization -> String
(Int -> GetReservationUtilization -> ShowS)
-> (GetReservationUtilization -> String)
-> ([GetReservationUtilization] -> ShowS)
-> Show GetReservationUtilization
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetReservationUtilization] -> ShowS
$cshowList :: [GetReservationUtilization] -> ShowS
show :: GetReservationUtilization -> String
$cshow :: GetReservationUtilization -> String
showsPrec :: Int -> GetReservationUtilization -> ShowS
$cshowsPrec :: Int -> GetReservationUtilization -> ShowS
Prelude.Show, (forall x.
 GetReservationUtilization -> Rep GetReservationUtilization x)
-> (forall x.
    Rep GetReservationUtilization x -> GetReservationUtilization)
-> Generic GetReservationUtilization
forall x.
Rep GetReservationUtilization x -> GetReservationUtilization
forall x.
GetReservationUtilization -> Rep GetReservationUtilization x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetReservationUtilization x -> GetReservationUtilization
$cfrom :: forall x.
GetReservationUtilization -> Rep GetReservationUtilization x
Prelude.Generic)

-- |
-- Create a value of 'GetReservationUtilization' 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:
--
-- 'groupBy', 'getReservationUtilization_groupBy' - Groups only by @SUBSCRIPTION_ID@. Metadata is included.
--
-- 'nextPageToken', 'getReservationUtilization_nextPageToken' - The token to retrieve the next set of results. Amazon Web Services
-- provides the token when the response from a previous call has more
-- results than the maximum page size.
--
-- 'granularity', 'getReservationUtilization_granularity' - If @GroupBy@ is set, @Granularity@ can\'t be set. If @Granularity@
-- isn\'t set, the response object doesn\'t include @Granularity@, either
-- @MONTHLY@ or @DAILY@. If both @GroupBy@ and @Granularity@ aren\'t set,
-- @GetReservationUtilization@ defaults to @DAILY@.
--
-- The @GetReservationUtilization@ operation supports only @DAILY@ and
-- @MONTHLY@ granularities.
--
-- 'filter'', 'getReservationUtilization_filter' - Filters utilization data by dimensions. You can filter by the following
-- dimensions:
--
-- -   AZ
--
-- -   CACHE_ENGINE
--
-- -   DEPLOYMENT_OPTION
--
-- -   INSTANCE_TYPE
--
-- -   LINKED_ACCOUNT
--
-- -   OPERATING_SYSTEM
--
-- -   PLATFORM
--
-- -   REGION
--
-- -   SERVICE
--
-- -   SCOPE
--
-- -   TENANCY
--
-- @GetReservationUtilization@ uses the same
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Expression.html Expression>
-- object as the other operations, but only @AND@ is supported among each
-- dimension, and nesting is supported up to only one level deep. If there
-- are multiple values for a dimension, they are OR\'d together.
--
-- 'maxResults', 'getReservationUtilization_maxResults' - The maximum number of objects that you returned for this request. If
-- more objects are available, in the response, Amazon Web Services
-- provides a NextPageToken value that you can use in a subsequent call to
-- get the next batch of objects.
--
-- 'sortBy', 'getReservationUtilization_sortBy' - The value by which you want to sort the data.
--
-- The following values are supported for @Key@:
--
-- -   @UtilizationPercentage@
--
-- -   @UtilizationPercentageInUnits@
--
-- -   @PurchasedHours@
--
-- -   @PurchasedUnits@
--
-- -   @TotalActualHours@
--
-- -   @TotalActualUnits@
--
-- -   @UnusedHours@
--
-- -   @UnusedUnits@
--
-- -   @OnDemandCostOfRIHoursUsed@
--
-- -   @NetRISavings@
--
-- -   @TotalPotentialRISavings@
--
-- -   @AmortizedUpfrontFee@
--
-- -   @AmortizedRecurringFee@
--
-- -   @TotalAmortizedFee@
--
-- -   @RICostForUnusedHours@
--
-- -   @RealizedSavings@
--
-- -   @UnrealizedSavings@
--
-- Supported values for @SortOrder@ are @ASCENDING@ or @DESCENDING@.
--
-- 'timePeriod', 'getReservationUtilization_timePeriod' - Sets the start and end dates for retrieving RI utilization. The start
-- date is inclusive, but the end date is exclusive. For example, if
-- @start@ is @2017-01-01@ and @end@ is @2017-05-01@, then the cost and
-- usage data is retrieved from @2017-01-01@ up to and including
-- @2017-04-30@ but not including @2017-05-01@.
newGetReservationUtilization ::
  -- | 'timePeriod'
  DateInterval ->
  GetReservationUtilization
newGetReservationUtilization :: DateInterval -> GetReservationUtilization
newGetReservationUtilization DateInterval
pTimePeriod_ =
  GetReservationUtilization' :: Maybe [GroupDefinition]
-> Maybe Text
-> Maybe Granularity
-> Maybe Expression
-> Maybe Natural
-> Maybe SortDefinition
-> DateInterval
-> GetReservationUtilization
GetReservationUtilization'
    { $sel:groupBy:GetReservationUtilization' :: Maybe [GroupDefinition]
groupBy =
        Maybe [GroupDefinition]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextPageToken:GetReservationUtilization' :: Maybe Text
nextPageToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:granularity:GetReservationUtilization' :: Maybe Granularity
granularity = Maybe Granularity
forall a. Maybe a
Prelude.Nothing,
      $sel:filter':GetReservationUtilization' :: Maybe Expression
filter' = Maybe Expression
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:GetReservationUtilization' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:sortBy:GetReservationUtilization' :: Maybe SortDefinition
sortBy = Maybe SortDefinition
forall a. Maybe a
Prelude.Nothing,
      $sel:timePeriod:GetReservationUtilization' :: DateInterval
timePeriod = DateInterval
pTimePeriod_
    }

-- | Groups only by @SUBSCRIPTION_ID@. Metadata is included.
getReservationUtilization_groupBy :: Lens.Lens' GetReservationUtilization (Prelude.Maybe [GroupDefinition])
getReservationUtilization_groupBy :: (Maybe [GroupDefinition] -> f (Maybe [GroupDefinition]))
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_groupBy = (GetReservationUtilization -> Maybe [GroupDefinition])
-> (GetReservationUtilization
    -> Maybe [GroupDefinition] -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     (Maybe [GroupDefinition])
     (Maybe [GroupDefinition])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {Maybe [GroupDefinition]
groupBy :: Maybe [GroupDefinition]
$sel:groupBy:GetReservationUtilization' :: GetReservationUtilization -> Maybe [GroupDefinition]
groupBy} -> Maybe [GroupDefinition]
groupBy) (\s :: GetReservationUtilization
s@GetReservationUtilization' {} Maybe [GroupDefinition]
a -> GetReservationUtilization
s {$sel:groupBy:GetReservationUtilization' :: Maybe [GroupDefinition]
groupBy = Maybe [GroupDefinition]
a} :: GetReservationUtilization) ((Maybe [GroupDefinition] -> f (Maybe [GroupDefinition]))
 -> GetReservationUtilization -> f GetReservationUtilization)
-> ((Maybe [GroupDefinition] -> f (Maybe [GroupDefinition]))
    -> Maybe [GroupDefinition] -> f (Maybe [GroupDefinition]))
-> (Maybe [GroupDefinition] -> f (Maybe [GroupDefinition]))
-> GetReservationUtilization
-> f GetReservationUtilization
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [GroupDefinition]
  [GroupDefinition]
  [GroupDefinition]
  [GroupDefinition]
-> Iso
     (Maybe [GroupDefinition])
     (Maybe [GroupDefinition])
     (Maybe [GroupDefinition])
     (Maybe [GroupDefinition])
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
  [GroupDefinition]
  [GroupDefinition]
  [GroupDefinition]
  [GroupDefinition]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The token to retrieve the next set of results. Amazon Web Services
-- provides the token when the response from a previous call has more
-- results than the maximum page size.
getReservationUtilization_nextPageToken :: Lens.Lens' GetReservationUtilization (Prelude.Maybe Prelude.Text)
getReservationUtilization_nextPageToken :: (Maybe Text -> f (Maybe Text))
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_nextPageToken = (GetReservationUtilization -> Maybe Text)
-> (GetReservationUtilization
    -> Maybe Text -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {Maybe Text
nextPageToken :: Maybe Text
$sel:nextPageToken:GetReservationUtilization' :: GetReservationUtilization -> Maybe Text
nextPageToken} -> Maybe Text
nextPageToken) (\s :: GetReservationUtilization
s@GetReservationUtilization' {} Maybe Text
a -> GetReservationUtilization
s {$sel:nextPageToken:GetReservationUtilization' :: Maybe Text
nextPageToken = Maybe Text
a} :: GetReservationUtilization)

-- | If @GroupBy@ is set, @Granularity@ can\'t be set. If @Granularity@
-- isn\'t set, the response object doesn\'t include @Granularity@, either
-- @MONTHLY@ or @DAILY@. If both @GroupBy@ and @Granularity@ aren\'t set,
-- @GetReservationUtilization@ defaults to @DAILY@.
--
-- The @GetReservationUtilization@ operation supports only @DAILY@ and
-- @MONTHLY@ granularities.
getReservationUtilization_granularity :: Lens.Lens' GetReservationUtilization (Prelude.Maybe Granularity)
getReservationUtilization_granularity :: (Maybe Granularity -> f (Maybe Granularity))
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_granularity = (GetReservationUtilization -> Maybe Granularity)
-> (GetReservationUtilization
    -> Maybe Granularity -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     (Maybe Granularity)
     (Maybe Granularity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {Maybe Granularity
granularity :: Maybe Granularity
$sel:granularity:GetReservationUtilization' :: GetReservationUtilization -> Maybe Granularity
granularity} -> Maybe Granularity
granularity) (\s :: GetReservationUtilization
s@GetReservationUtilization' {} Maybe Granularity
a -> GetReservationUtilization
s {$sel:granularity:GetReservationUtilization' :: Maybe Granularity
granularity = Maybe Granularity
a} :: GetReservationUtilization)

-- | Filters utilization data by dimensions. You can filter by the following
-- dimensions:
--
-- -   AZ
--
-- -   CACHE_ENGINE
--
-- -   DEPLOYMENT_OPTION
--
-- -   INSTANCE_TYPE
--
-- -   LINKED_ACCOUNT
--
-- -   OPERATING_SYSTEM
--
-- -   PLATFORM
--
-- -   REGION
--
-- -   SERVICE
--
-- -   SCOPE
--
-- -   TENANCY
--
-- @GetReservationUtilization@ uses the same
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_Expression.html Expression>
-- object as the other operations, but only @AND@ is supported among each
-- dimension, and nesting is supported up to only one level deep. If there
-- are multiple values for a dimension, they are OR\'d together.
getReservationUtilization_filter :: Lens.Lens' GetReservationUtilization (Prelude.Maybe Expression)
getReservationUtilization_filter :: (Maybe Expression -> f (Maybe Expression))
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_filter = (GetReservationUtilization -> Maybe Expression)
-> (GetReservationUtilization
    -> Maybe Expression -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     (Maybe Expression)
     (Maybe Expression)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {Maybe Expression
filter' :: Maybe Expression
$sel:filter':GetReservationUtilization' :: GetReservationUtilization -> Maybe Expression
filter'} -> Maybe Expression
filter') (\s :: GetReservationUtilization
s@GetReservationUtilization' {} Maybe Expression
a -> GetReservationUtilization
s {$sel:filter':GetReservationUtilization' :: Maybe Expression
filter' = Maybe Expression
a} :: GetReservationUtilization)

-- | The maximum number of objects that you returned for this request. If
-- more objects are available, in the response, Amazon Web Services
-- provides a NextPageToken value that you can use in a subsequent call to
-- get the next batch of objects.
getReservationUtilization_maxResults :: Lens.Lens' GetReservationUtilization (Prelude.Maybe Prelude.Natural)
getReservationUtilization_maxResults :: (Maybe Natural -> f (Maybe Natural))
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_maxResults = (GetReservationUtilization -> Maybe Natural)
-> (GetReservationUtilization
    -> Maybe Natural -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:GetReservationUtilization' :: GetReservationUtilization -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: GetReservationUtilization
s@GetReservationUtilization' {} Maybe Natural
a -> GetReservationUtilization
s {$sel:maxResults:GetReservationUtilization' :: Maybe Natural
maxResults = Maybe Natural
a} :: GetReservationUtilization)

-- | The value by which you want to sort the data.
--
-- The following values are supported for @Key@:
--
-- -   @UtilizationPercentage@
--
-- -   @UtilizationPercentageInUnits@
--
-- -   @PurchasedHours@
--
-- -   @PurchasedUnits@
--
-- -   @TotalActualHours@
--
-- -   @TotalActualUnits@
--
-- -   @UnusedHours@
--
-- -   @UnusedUnits@
--
-- -   @OnDemandCostOfRIHoursUsed@
--
-- -   @NetRISavings@
--
-- -   @TotalPotentialRISavings@
--
-- -   @AmortizedUpfrontFee@
--
-- -   @AmortizedRecurringFee@
--
-- -   @TotalAmortizedFee@
--
-- -   @RICostForUnusedHours@
--
-- -   @RealizedSavings@
--
-- -   @UnrealizedSavings@
--
-- Supported values for @SortOrder@ are @ASCENDING@ or @DESCENDING@.
getReservationUtilization_sortBy :: Lens.Lens' GetReservationUtilization (Prelude.Maybe SortDefinition)
getReservationUtilization_sortBy :: (Maybe SortDefinition -> f (Maybe SortDefinition))
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_sortBy = (GetReservationUtilization -> Maybe SortDefinition)
-> (GetReservationUtilization
    -> Maybe SortDefinition -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     (Maybe SortDefinition)
     (Maybe SortDefinition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {Maybe SortDefinition
sortBy :: Maybe SortDefinition
$sel:sortBy:GetReservationUtilization' :: GetReservationUtilization -> Maybe SortDefinition
sortBy} -> Maybe SortDefinition
sortBy) (\s :: GetReservationUtilization
s@GetReservationUtilization' {} Maybe SortDefinition
a -> GetReservationUtilization
s {$sel:sortBy:GetReservationUtilization' :: Maybe SortDefinition
sortBy = Maybe SortDefinition
a} :: GetReservationUtilization)

-- | Sets the start and end dates for retrieving RI utilization. The start
-- date is inclusive, but the end date is exclusive. For example, if
-- @start@ is @2017-01-01@ and @end@ is @2017-05-01@, then the cost and
-- usage data is retrieved from @2017-01-01@ up to and including
-- @2017-04-30@ but not including @2017-05-01@.
getReservationUtilization_timePeriod :: Lens.Lens' GetReservationUtilization DateInterval
getReservationUtilization_timePeriod :: (DateInterval -> f DateInterval)
-> GetReservationUtilization -> f GetReservationUtilization
getReservationUtilization_timePeriod = (GetReservationUtilization -> DateInterval)
-> (GetReservationUtilization
    -> DateInterval -> GetReservationUtilization)
-> Lens
     GetReservationUtilization
     GetReservationUtilization
     DateInterval
     DateInterval
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilization' {DateInterval
timePeriod :: DateInterval
$sel:timePeriod:GetReservationUtilization' :: GetReservationUtilization -> DateInterval
timePeriod} -> DateInterval
timePeriod) (\s :: GetReservationUtilization
s@GetReservationUtilization' {} DateInterval
a -> GetReservationUtilization
s {$sel:timePeriod:GetReservationUtilization' :: DateInterval
timePeriod = DateInterval
a} :: GetReservationUtilization)

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

instance Prelude.Hashable GetReservationUtilization

instance Prelude.NFData GetReservationUtilization

instance Core.ToHeaders GetReservationUtilization where
  toHeaders :: GetReservationUtilization -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetReservationUtilization -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSInsightsIndexService.GetReservationUtilization" ::
                          Prelude.ByteString
                      ),
            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 GetReservationUtilization where
  toJSON :: GetReservationUtilization -> Value
toJSON GetReservationUtilization' {Maybe Natural
Maybe [GroupDefinition]
Maybe Text
Maybe Granularity
Maybe SortDefinition
Maybe Expression
DateInterval
timePeriod :: DateInterval
sortBy :: Maybe SortDefinition
maxResults :: Maybe Natural
filter' :: Maybe Expression
granularity :: Maybe Granularity
nextPageToken :: Maybe Text
groupBy :: Maybe [GroupDefinition]
$sel:timePeriod:GetReservationUtilization' :: GetReservationUtilization -> DateInterval
$sel:sortBy:GetReservationUtilization' :: GetReservationUtilization -> Maybe SortDefinition
$sel:maxResults:GetReservationUtilization' :: GetReservationUtilization -> Maybe Natural
$sel:filter':GetReservationUtilization' :: GetReservationUtilization -> Maybe Expression
$sel:granularity:GetReservationUtilization' :: GetReservationUtilization -> Maybe Granularity
$sel:nextPageToken:GetReservationUtilization' :: GetReservationUtilization -> Maybe Text
$sel:groupBy:GetReservationUtilization' :: GetReservationUtilization -> Maybe [GroupDefinition]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"GroupBy" Text -> [GroupDefinition] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([GroupDefinition] -> Pair)
-> Maybe [GroupDefinition] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [GroupDefinition]
groupBy,
            (Text
"NextPageToken" 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
nextPageToken,
            (Text
"Granularity" Text -> Granularity -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Granularity -> Pair) -> Maybe Granularity -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Granularity
granularity,
            (Text
"Filter" Text -> Expression -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Expression -> Pair) -> Maybe Expression -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Expression
filter',
            (Text
"MaxResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Text
"SortBy" Text -> SortDefinition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SortDefinition -> Pair) -> Maybe SortDefinition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SortDefinition
sortBy,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TimePeriod" Text -> DateInterval -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DateInterval
timePeriod)
          ]
      )

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

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

-- | /See:/ 'newGetReservationUtilizationResponse' smart constructor.
data GetReservationUtilizationResponse = GetReservationUtilizationResponse'
  { -- | The token for the next set of retrievable results. Amazon Web Services
    -- provides the token when the response from a previous call has more
    -- results than the maximum page size.
    GetReservationUtilizationResponse -> Maybe Text
nextPageToken :: Prelude.Maybe Prelude.Text,
    -- | The total amount of time that you used your RIs.
    GetReservationUtilizationResponse -> Maybe ReservationAggregates
total :: Prelude.Maybe ReservationAggregates,
    -- | The response's http status code.
    GetReservationUtilizationResponse -> Int
httpStatus :: Prelude.Int,
    -- | The amount of time that you used your RIs.
    GetReservationUtilizationResponse -> [UtilizationByTime]
utilizationsByTime :: [UtilizationByTime]
  }
  deriving (GetReservationUtilizationResponse
-> GetReservationUtilizationResponse -> Bool
(GetReservationUtilizationResponse
 -> GetReservationUtilizationResponse -> Bool)
-> (GetReservationUtilizationResponse
    -> GetReservationUtilizationResponse -> Bool)
-> Eq GetReservationUtilizationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetReservationUtilizationResponse
-> GetReservationUtilizationResponse -> Bool
$c/= :: GetReservationUtilizationResponse
-> GetReservationUtilizationResponse -> Bool
== :: GetReservationUtilizationResponse
-> GetReservationUtilizationResponse -> Bool
$c== :: GetReservationUtilizationResponse
-> GetReservationUtilizationResponse -> Bool
Prelude.Eq, ReadPrec [GetReservationUtilizationResponse]
ReadPrec GetReservationUtilizationResponse
Int -> ReadS GetReservationUtilizationResponse
ReadS [GetReservationUtilizationResponse]
(Int -> ReadS GetReservationUtilizationResponse)
-> ReadS [GetReservationUtilizationResponse]
-> ReadPrec GetReservationUtilizationResponse
-> ReadPrec [GetReservationUtilizationResponse]
-> Read GetReservationUtilizationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetReservationUtilizationResponse]
$creadListPrec :: ReadPrec [GetReservationUtilizationResponse]
readPrec :: ReadPrec GetReservationUtilizationResponse
$creadPrec :: ReadPrec GetReservationUtilizationResponse
readList :: ReadS [GetReservationUtilizationResponse]
$creadList :: ReadS [GetReservationUtilizationResponse]
readsPrec :: Int -> ReadS GetReservationUtilizationResponse
$creadsPrec :: Int -> ReadS GetReservationUtilizationResponse
Prelude.Read, Int -> GetReservationUtilizationResponse -> ShowS
[GetReservationUtilizationResponse] -> ShowS
GetReservationUtilizationResponse -> String
(Int -> GetReservationUtilizationResponse -> ShowS)
-> (GetReservationUtilizationResponse -> String)
-> ([GetReservationUtilizationResponse] -> ShowS)
-> Show GetReservationUtilizationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetReservationUtilizationResponse] -> ShowS
$cshowList :: [GetReservationUtilizationResponse] -> ShowS
show :: GetReservationUtilizationResponse -> String
$cshow :: GetReservationUtilizationResponse -> String
showsPrec :: Int -> GetReservationUtilizationResponse -> ShowS
$cshowsPrec :: Int -> GetReservationUtilizationResponse -> ShowS
Prelude.Show, (forall x.
 GetReservationUtilizationResponse
 -> Rep GetReservationUtilizationResponse x)
-> (forall x.
    Rep GetReservationUtilizationResponse x
    -> GetReservationUtilizationResponse)
-> Generic GetReservationUtilizationResponse
forall x.
Rep GetReservationUtilizationResponse x
-> GetReservationUtilizationResponse
forall x.
GetReservationUtilizationResponse
-> Rep GetReservationUtilizationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetReservationUtilizationResponse x
-> GetReservationUtilizationResponse
$cfrom :: forall x.
GetReservationUtilizationResponse
-> Rep GetReservationUtilizationResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetReservationUtilizationResponse' 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:
--
-- 'nextPageToken', 'getReservationUtilizationResponse_nextPageToken' - The token for the next set of retrievable results. Amazon Web Services
-- provides the token when the response from a previous call has more
-- results than the maximum page size.
--
-- 'total', 'getReservationUtilizationResponse_total' - The total amount of time that you used your RIs.
--
-- 'httpStatus', 'getReservationUtilizationResponse_httpStatus' - The response's http status code.
--
-- 'utilizationsByTime', 'getReservationUtilizationResponse_utilizationsByTime' - The amount of time that you used your RIs.
newGetReservationUtilizationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetReservationUtilizationResponse
newGetReservationUtilizationResponse :: Int -> GetReservationUtilizationResponse
newGetReservationUtilizationResponse Int
pHttpStatus_ =
  GetReservationUtilizationResponse' :: Maybe Text
-> Maybe ReservationAggregates
-> Int
-> [UtilizationByTime]
-> GetReservationUtilizationResponse
GetReservationUtilizationResponse'
    { $sel:nextPageToken:GetReservationUtilizationResponse' :: Maybe Text
nextPageToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:total:GetReservationUtilizationResponse' :: Maybe ReservationAggregates
total = Maybe ReservationAggregates
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetReservationUtilizationResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:utilizationsByTime:GetReservationUtilizationResponse' :: [UtilizationByTime]
utilizationsByTime = [UtilizationByTime]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The token for the next set of retrievable results. Amazon Web Services
-- provides the token when the response from a previous call has more
-- results than the maximum page size.
getReservationUtilizationResponse_nextPageToken :: Lens.Lens' GetReservationUtilizationResponse (Prelude.Maybe Prelude.Text)
getReservationUtilizationResponse_nextPageToken :: (Maybe Text -> f (Maybe Text))
-> GetReservationUtilizationResponse
-> f GetReservationUtilizationResponse
getReservationUtilizationResponse_nextPageToken = (GetReservationUtilizationResponse -> Maybe Text)
-> (GetReservationUtilizationResponse
    -> Maybe Text -> GetReservationUtilizationResponse)
-> Lens
     GetReservationUtilizationResponse
     GetReservationUtilizationResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilizationResponse' {Maybe Text
nextPageToken :: Maybe Text
$sel:nextPageToken:GetReservationUtilizationResponse' :: GetReservationUtilizationResponse -> Maybe Text
nextPageToken} -> Maybe Text
nextPageToken) (\s :: GetReservationUtilizationResponse
s@GetReservationUtilizationResponse' {} Maybe Text
a -> GetReservationUtilizationResponse
s {$sel:nextPageToken:GetReservationUtilizationResponse' :: Maybe Text
nextPageToken = Maybe Text
a} :: GetReservationUtilizationResponse)

-- | The total amount of time that you used your RIs.
getReservationUtilizationResponse_total :: Lens.Lens' GetReservationUtilizationResponse (Prelude.Maybe ReservationAggregates)
getReservationUtilizationResponse_total :: (Maybe ReservationAggregates -> f (Maybe ReservationAggregates))
-> GetReservationUtilizationResponse
-> f GetReservationUtilizationResponse
getReservationUtilizationResponse_total = (GetReservationUtilizationResponse -> Maybe ReservationAggregates)
-> (GetReservationUtilizationResponse
    -> Maybe ReservationAggregates
    -> GetReservationUtilizationResponse)
-> Lens
     GetReservationUtilizationResponse
     GetReservationUtilizationResponse
     (Maybe ReservationAggregates)
     (Maybe ReservationAggregates)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilizationResponse' {Maybe ReservationAggregates
total :: Maybe ReservationAggregates
$sel:total:GetReservationUtilizationResponse' :: GetReservationUtilizationResponse -> Maybe ReservationAggregates
total} -> Maybe ReservationAggregates
total) (\s :: GetReservationUtilizationResponse
s@GetReservationUtilizationResponse' {} Maybe ReservationAggregates
a -> GetReservationUtilizationResponse
s {$sel:total:GetReservationUtilizationResponse' :: Maybe ReservationAggregates
total = Maybe ReservationAggregates
a} :: GetReservationUtilizationResponse)

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

-- | The amount of time that you used your RIs.
getReservationUtilizationResponse_utilizationsByTime :: Lens.Lens' GetReservationUtilizationResponse [UtilizationByTime]
getReservationUtilizationResponse_utilizationsByTime :: ([UtilizationByTime] -> f [UtilizationByTime])
-> GetReservationUtilizationResponse
-> f GetReservationUtilizationResponse
getReservationUtilizationResponse_utilizationsByTime = (GetReservationUtilizationResponse -> [UtilizationByTime])
-> (GetReservationUtilizationResponse
    -> [UtilizationByTime] -> GetReservationUtilizationResponse)
-> Lens
     GetReservationUtilizationResponse
     GetReservationUtilizationResponse
     [UtilizationByTime]
     [UtilizationByTime]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetReservationUtilizationResponse' {[UtilizationByTime]
utilizationsByTime :: [UtilizationByTime]
$sel:utilizationsByTime:GetReservationUtilizationResponse' :: GetReservationUtilizationResponse -> [UtilizationByTime]
utilizationsByTime} -> [UtilizationByTime]
utilizationsByTime) (\s :: GetReservationUtilizationResponse
s@GetReservationUtilizationResponse' {} [UtilizationByTime]
a -> GetReservationUtilizationResponse
s {$sel:utilizationsByTime:GetReservationUtilizationResponse' :: [UtilizationByTime]
utilizationsByTime = [UtilizationByTime]
a} :: GetReservationUtilizationResponse) (([UtilizationByTime] -> f [UtilizationByTime])
 -> GetReservationUtilizationResponse
 -> f GetReservationUtilizationResponse)
-> (([UtilizationByTime] -> f [UtilizationByTime])
    -> [UtilizationByTime] -> f [UtilizationByTime])
-> ([UtilizationByTime] -> f [UtilizationByTime])
-> GetReservationUtilizationResponse
-> f GetReservationUtilizationResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([UtilizationByTime] -> f [UtilizationByTime])
-> [UtilizationByTime] -> f [UtilizationByTime]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance
  Prelude.NFData
    GetReservationUtilizationResponse