{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.APIGateway.Types.Usage
-- 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)
module Amazonka.APIGateway.Types.Usage where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents the usage data of a usage plan.
--
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html Create and Use Usage Plans>,
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-usage-plans-with-console.html#api-gateway-usage-plan-manage-usage Manage Usage in a Usage Plan>
--
-- /See:/ 'newUsage' smart constructor.
data Usage = Usage'
  { -- | The plan Id associated with this usage data.
    Usage -> Maybe Text
usagePlanId :: Prelude.Maybe Prelude.Text,
    -- | The ending date of the usage data.
    Usage -> Maybe Text
endDate :: Prelude.Maybe Prelude.Text,
    -- | The usage data, as daily logs of used and remaining quotas, over the
    -- specified time interval indexed over the API keys in a usage plan. For
    -- example,
    -- @{..., \"values\" : { \"{api_key}\" : [ [0, 100], [10, 90], [100, 10]]}@,
    -- where @{api_key}@ stands for an API key value and the daily log entry is
    -- of the format @[used quota, remaining quota]@.
    Usage -> Maybe (HashMap Text [[Integer]])
items :: Prelude.Maybe (Prelude.HashMap Prelude.Text [[Prelude.Integer]]),
    -- | The starting date of the usage data.
    Usage -> Maybe Text
startDate :: Prelude.Maybe Prelude.Text,
    Usage -> Maybe Text
position :: Prelude.Maybe Prelude.Text
  }
  deriving (Usage -> Usage -> Bool
(Usage -> Usage -> Bool) -> (Usage -> Usage -> Bool) -> Eq Usage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Usage -> Usage -> Bool
$c/= :: Usage -> Usage -> Bool
== :: Usage -> Usage -> Bool
$c== :: Usage -> Usage -> Bool
Prelude.Eq, ReadPrec [Usage]
ReadPrec Usage
Int -> ReadS Usage
ReadS [Usage]
(Int -> ReadS Usage)
-> ReadS [Usage]
-> ReadPrec Usage
-> ReadPrec [Usage]
-> Read Usage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Usage]
$creadListPrec :: ReadPrec [Usage]
readPrec :: ReadPrec Usage
$creadPrec :: ReadPrec Usage
readList :: ReadS [Usage]
$creadList :: ReadS [Usage]
readsPrec :: Int -> ReadS Usage
$creadsPrec :: Int -> ReadS Usage
Prelude.Read, Int -> Usage -> ShowS
[Usage] -> ShowS
Usage -> String
(Int -> Usage -> ShowS)
-> (Usage -> String) -> ([Usage] -> ShowS) -> Show Usage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Usage] -> ShowS
$cshowList :: [Usage] -> ShowS
show :: Usage -> String
$cshow :: Usage -> String
showsPrec :: Int -> Usage -> ShowS
$cshowsPrec :: Int -> Usage -> ShowS
Prelude.Show, (forall x. Usage -> Rep Usage x)
-> (forall x. Rep Usage x -> Usage) -> Generic Usage
forall x. Rep Usage x -> Usage
forall x. Usage -> Rep Usage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Usage x -> Usage
$cfrom :: forall x. Usage -> Rep Usage x
Prelude.Generic)

-- |
-- Create a value of 'Usage' 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:
--
-- 'usagePlanId', 'usage_usagePlanId' - The plan Id associated with this usage data.
--
-- 'endDate', 'usage_endDate' - The ending date of the usage data.
--
-- 'items', 'usage_items' - The usage data, as daily logs of used and remaining quotas, over the
-- specified time interval indexed over the API keys in a usage plan. For
-- example,
-- @{..., \"values\" : { \"{api_key}\" : [ [0, 100], [10, 90], [100, 10]]}@,
-- where @{api_key}@ stands for an API key value and the daily log entry is
-- of the format @[used quota, remaining quota]@.
--
-- 'startDate', 'usage_startDate' - The starting date of the usage data.
--
-- 'position', 'usage_position' - Undocumented member.
newUsage ::
  Usage
newUsage :: Usage
newUsage =
  Usage' :: Maybe Text
-> Maybe Text
-> Maybe (HashMap Text [[Integer]])
-> Maybe Text
-> Maybe Text
-> Usage
Usage'
    { $sel:usagePlanId:Usage' :: Maybe Text
usagePlanId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:endDate:Usage' :: Maybe Text
endDate = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:items:Usage' :: Maybe (HashMap Text [[Integer]])
items = Maybe (HashMap Text [[Integer]])
forall a. Maybe a
Prelude.Nothing,
      $sel:startDate:Usage' :: Maybe Text
startDate = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:position:Usage' :: Maybe Text
position = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The plan Id associated with this usage data.
usage_usagePlanId :: Lens.Lens' Usage (Prelude.Maybe Prelude.Text)
usage_usagePlanId :: (Maybe Text -> f (Maybe Text)) -> Usage -> f Usage
usage_usagePlanId = (Usage -> Maybe Text)
-> (Usage -> Maybe Text -> Usage)
-> Lens Usage Usage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Usage' {Maybe Text
usagePlanId :: Maybe Text
$sel:usagePlanId:Usage' :: Usage -> Maybe Text
usagePlanId} -> Maybe Text
usagePlanId) (\s :: Usage
s@Usage' {} Maybe Text
a -> Usage
s {$sel:usagePlanId:Usage' :: Maybe Text
usagePlanId = Maybe Text
a} :: Usage)

-- | The ending date of the usage data.
usage_endDate :: Lens.Lens' Usage (Prelude.Maybe Prelude.Text)
usage_endDate :: (Maybe Text -> f (Maybe Text)) -> Usage -> f Usage
usage_endDate = (Usage -> Maybe Text)
-> (Usage -> Maybe Text -> Usage)
-> Lens Usage Usage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Usage' {Maybe Text
endDate :: Maybe Text
$sel:endDate:Usage' :: Usage -> Maybe Text
endDate} -> Maybe Text
endDate) (\s :: Usage
s@Usage' {} Maybe Text
a -> Usage
s {$sel:endDate:Usage' :: Maybe Text
endDate = Maybe Text
a} :: Usage)

-- | The usage data, as daily logs of used and remaining quotas, over the
-- specified time interval indexed over the API keys in a usage plan. For
-- example,
-- @{..., \"values\" : { \"{api_key}\" : [ [0, 100], [10, 90], [100, 10]]}@,
-- where @{api_key}@ stands for an API key value and the daily log entry is
-- of the format @[used quota, remaining quota]@.
usage_items :: Lens.Lens' Usage (Prelude.Maybe (Prelude.HashMap Prelude.Text [[Prelude.Integer]]))
usage_items :: (Maybe (HashMap Text [[Integer]])
 -> f (Maybe (HashMap Text [[Integer]])))
-> Usage -> f Usage
usage_items = (Usage -> Maybe (HashMap Text [[Integer]]))
-> (Usage -> Maybe (HashMap Text [[Integer]]) -> Usage)
-> Lens
     Usage
     Usage
     (Maybe (HashMap Text [[Integer]]))
     (Maybe (HashMap Text [[Integer]]))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Usage' {Maybe (HashMap Text [[Integer]])
items :: Maybe (HashMap Text [[Integer]])
$sel:items:Usage' :: Usage -> Maybe (HashMap Text [[Integer]])
items} -> Maybe (HashMap Text [[Integer]])
items) (\s :: Usage
s@Usage' {} Maybe (HashMap Text [[Integer]])
a -> Usage
s {$sel:items:Usage' :: Maybe (HashMap Text [[Integer]])
items = Maybe (HashMap Text [[Integer]])
a} :: Usage) ((Maybe (HashMap Text [[Integer]])
  -> f (Maybe (HashMap Text [[Integer]])))
 -> Usage -> f Usage)
-> ((Maybe (HashMap Text [[Integer]])
     -> f (Maybe (HashMap Text [[Integer]])))
    -> Maybe (HashMap Text [[Integer]])
    -> f (Maybe (HashMap Text [[Integer]])))
-> (Maybe (HashMap Text [[Integer]])
    -> f (Maybe (HashMap Text [[Integer]])))
-> Usage
-> f Usage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text [[Integer]])
  (HashMap Text [[Integer]])
  (HashMap Text [[Integer]])
  (HashMap Text [[Integer]])
-> Iso
     (Maybe (HashMap Text [[Integer]]))
     (Maybe (HashMap Text [[Integer]]))
     (Maybe (HashMap Text [[Integer]]))
     (Maybe (HashMap Text [[Integer]]))
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
  (HashMap Text [[Integer]])
  (HashMap Text [[Integer]])
  (HashMap Text [[Integer]])
  (HashMap Text [[Integer]])
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The starting date of the usage data.
usage_startDate :: Lens.Lens' Usage (Prelude.Maybe Prelude.Text)
usage_startDate :: (Maybe Text -> f (Maybe Text)) -> Usage -> f Usage
usage_startDate = (Usage -> Maybe Text)
-> (Usage -> Maybe Text -> Usage)
-> Lens Usage Usage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Usage' {Maybe Text
startDate :: Maybe Text
$sel:startDate:Usage' :: Usage -> Maybe Text
startDate} -> Maybe Text
startDate) (\s :: Usage
s@Usage' {} Maybe Text
a -> Usage
s {$sel:startDate:Usage' :: Maybe Text
startDate = Maybe Text
a} :: Usage)

-- | Undocumented member.
usage_position :: Lens.Lens' Usage (Prelude.Maybe Prelude.Text)
usage_position :: (Maybe Text -> f (Maybe Text)) -> Usage -> f Usage
usage_position = (Usage -> Maybe Text)
-> (Usage -> Maybe Text -> Usage)
-> Lens Usage Usage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Usage' {Maybe Text
position :: Maybe Text
$sel:position:Usage' :: Usage -> Maybe Text
position} -> Maybe Text
position) (\s :: Usage
s@Usage' {} Maybe Text
a -> Usage
s {$sel:position:Usage' :: Maybe Text
position = Maybe Text
a} :: Usage)

instance Core.FromJSON Usage where
  parseJSON :: Value -> Parser Usage
parseJSON =
    String -> (Object -> Parser Usage) -> Value -> Parser Usage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Usage"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe (HashMap Text [[Integer]])
-> Maybe Text
-> Maybe Text
-> Usage
Usage'
            (Maybe Text
 -> Maybe Text
 -> Maybe (HashMap Text [[Integer]])
 -> Maybe Text
 -> Maybe Text
 -> Usage)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe (HashMap Text [[Integer]])
      -> Maybe Text
      -> Maybe Text
      -> Usage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"usagePlanId")
            Parser
  (Maybe Text
   -> Maybe (HashMap Text [[Integer]])
   -> Maybe Text
   -> Maybe Text
   -> Usage)
-> Parser (Maybe Text)
-> Parser
     (Maybe (HashMap Text [[Integer]])
      -> Maybe Text -> Maybe Text -> Usage)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"endDate")
            Parser
  (Maybe (HashMap Text [[Integer]])
   -> Maybe Text -> Maybe Text -> Usage)
-> Parser (Maybe (HashMap Text [[Integer]]))
-> Parser (Maybe Text -> Maybe Text -> Usage)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text [[Integer]])))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"values" Parser (Maybe (Maybe (HashMap Text [[Integer]])))
-> Maybe (HashMap Text [[Integer]])
-> Parser (Maybe (HashMap Text [[Integer]]))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text [[Integer]])
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe Text -> Usage)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Usage)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"startDate")
            Parser (Maybe Text -> Usage) -> Parser (Maybe Text) -> Parser Usage
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"position")
      )

instance Prelude.Hashable Usage

instance Prelude.NFData Usage