{-# 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.MacieV2.Types.UsageRecord
-- 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.MacieV2.Types.UsageRecord where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MacieV2.Types.UsageByAccount
import qualified Amazonka.Prelude as Prelude

-- | Provides quota and aggregated usage data for an Amazon Macie account.
--
-- /See:/ 'newUsageRecord' smart constructor.
data UsageRecord = UsageRecord'
  { -- | The unique identifier for the Amazon Web Services account that the data
    -- applies to.
    UsageRecord -> Maybe Text
accountId :: Prelude.Maybe Prelude.Text,
    -- | The date and time, in UTC and extended ISO 8601 format, when the free
    -- trial started for the account.
    UsageRecord -> Maybe POSIX
freeTrialStartDate :: Prelude.Maybe Core.POSIX,
    -- | An array of objects that contains usage data and quotas for the account.
    -- Each object contains the data for a specific usage metric and the
    -- corresponding quota.
    UsageRecord -> Maybe [UsageByAccount]
usage :: Prelude.Maybe [UsageByAccount]
  }
  deriving (UsageRecord -> UsageRecord -> Bool
(UsageRecord -> UsageRecord -> Bool)
-> (UsageRecord -> UsageRecord -> Bool) -> Eq UsageRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UsageRecord -> UsageRecord -> Bool
$c/= :: UsageRecord -> UsageRecord -> Bool
== :: UsageRecord -> UsageRecord -> Bool
$c== :: UsageRecord -> UsageRecord -> Bool
Prelude.Eq, ReadPrec [UsageRecord]
ReadPrec UsageRecord
Int -> ReadS UsageRecord
ReadS [UsageRecord]
(Int -> ReadS UsageRecord)
-> ReadS [UsageRecord]
-> ReadPrec UsageRecord
-> ReadPrec [UsageRecord]
-> Read UsageRecord
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UsageRecord]
$creadListPrec :: ReadPrec [UsageRecord]
readPrec :: ReadPrec UsageRecord
$creadPrec :: ReadPrec UsageRecord
readList :: ReadS [UsageRecord]
$creadList :: ReadS [UsageRecord]
readsPrec :: Int -> ReadS UsageRecord
$creadsPrec :: Int -> ReadS UsageRecord
Prelude.Read, Int -> UsageRecord -> ShowS
[UsageRecord] -> ShowS
UsageRecord -> String
(Int -> UsageRecord -> ShowS)
-> (UsageRecord -> String)
-> ([UsageRecord] -> ShowS)
-> Show UsageRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UsageRecord] -> ShowS
$cshowList :: [UsageRecord] -> ShowS
show :: UsageRecord -> String
$cshow :: UsageRecord -> String
showsPrec :: Int -> UsageRecord -> ShowS
$cshowsPrec :: Int -> UsageRecord -> ShowS
Prelude.Show, (forall x. UsageRecord -> Rep UsageRecord x)
-> (forall x. Rep UsageRecord x -> UsageRecord)
-> Generic UsageRecord
forall x. Rep UsageRecord x -> UsageRecord
forall x. UsageRecord -> Rep UsageRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UsageRecord x -> UsageRecord
$cfrom :: forall x. UsageRecord -> Rep UsageRecord x
Prelude.Generic)

-- |
-- Create a value of 'UsageRecord' 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:
--
-- 'accountId', 'usageRecord_accountId' - The unique identifier for the Amazon Web Services account that the data
-- applies to.
--
-- 'freeTrialStartDate', 'usageRecord_freeTrialStartDate' - The date and time, in UTC and extended ISO 8601 format, when the free
-- trial started for the account.
--
-- 'usage', 'usageRecord_usage' - An array of objects that contains usage data and quotas for the account.
-- Each object contains the data for a specific usage metric and the
-- corresponding quota.
newUsageRecord ::
  UsageRecord
newUsageRecord :: UsageRecord
newUsageRecord =
  UsageRecord' :: Maybe Text -> Maybe POSIX -> Maybe [UsageByAccount] -> UsageRecord
UsageRecord'
    { $sel:accountId:UsageRecord' :: Maybe Text
accountId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:freeTrialStartDate:UsageRecord' :: Maybe POSIX
freeTrialStartDate = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:usage:UsageRecord' :: Maybe [UsageByAccount]
usage = Maybe [UsageByAccount]
forall a. Maybe a
Prelude.Nothing
    }

-- | The unique identifier for the Amazon Web Services account that the data
-- applies to.
usageRecord_accountId :: Lens.Lens' UsageRecord (Prelude.Maybe Prelude.Text)
usageRecord_accountId :: (Maybe Text -> f (Maybe Text)) -> UsageRecord -> f UsageRecord
usageRecord_accountId = (UsageRecord -> Maybe Text)
-> (UsageRecord -> Maybe Text -> UsageRecord)
-> Lens UsageRecord UsageRecord (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Maybe Text
accountId :: Maybe Text
$sel:accountId:UsageRecord' :: UsageRecord -> Maybe Text
accountId} -> Maybe Text
accountId) (\s :: UsageRecord
s@UsageRecord' {} Maybe Text
a -> UsageRecord
s {$sel:accountId:UsageRecord' :: Maybe Text
accountId = Maybe Text
a} :: UsageRecord)

-- | The date and time, in UTC and extended ISO 8601 format, when the free
-- trial started for the account.
usageRecord_freeTrialStartDate :: Lens.Lens' UsageRecord (Prelude.Maybe Prelude.UTCTime)
usageRecord_freeTrialStartDate :: (Maybe UTCTime -> f (Maybe UTCTime))
-> UsageRecord -> f UsageRecord
usageRecord_freeTrialStartDate = (UsageRecord -> Maybe POSIX)
-> (UsageRecord -> Maybe POSIX -> UsageRecord)
-> Lens UsageRecord UsageRecord (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Maybe POSIX
freeTrialStartDate :: Maybe POSIX
$sel:freeTrialStartDate:UsageRecord' :: UsageRecord -> Maybe POSIX
freeTrialStartDate} -> Maybe POSIX
freeTrialStartDate) (\s :: UsageRecord
s@UsageRecord' {} Maybe POSIX
a -> UsageRecord
s {$sel:freeTrialStartDate:UsageRecord' :: Maybe POSIX
freeTrialStartDate = Maybe POSIX
a} :: UsageRecord) ((Maybe POSIX -> f (Maybe POSIX)) -> UsageRecord -> f UsageRecord)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> UsageRecord
-> f UsageRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | An array of objects that contains usage data and quotas for the account.
-- Each object contains the data for a specific usage metric and the
-- corresponding quota.
usageRecord_usage :: Lens.Lens' UsageRecord (Prelude.Maybe [UsageByAccount])
usageRecord_usage :: (Maybe [UsageByAccount] -> f (Maybe [UsageByAccount]))
-> UsageRecord -> f UsageRecord
usageRecord_usage = (UsageRecord -> Maybe [UsageByAccount])
-> (UsageRecord -> Maybe [UsageByAccount] -> UsageRecord)
-> Lens
     UsageRecord
     UsageRecord
     (Maybe [UsageByAccount])
     (Maybe [UsageByAccount])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Maybe [UsageByAccount]
usage :: Maybe [UsageByAccount]
$sel:usage:UsageRecord' :: UsageRecord -> Maybe [UsageByAccount]
usage} -> Maybe [UsageByAccount]
usage) (\s :: UsageRecord
s@UsageRecord' {} Maybe [UsageByAccount]
a -> UsageRecord
s {$sel:usage:UsageRecord' :: Maybe [UsageByAccount]
usage = Maybe [UsageByAccount]
a} :: UsageRecord) ((Maybe [UsageByAccount] -> f (Maybe [UsageByAccount]))
 -> UsageRecord -> f UsageRecord)
-> ((Maybe [UsageByAccount] -> f (Maybe [UsageByAccount]))
    -> Maybe [UsageByAccount] -> f (Maybe [UsageByAccount]))
-> (Maybe [UsageByAccount] -> f (Maybe [UsageByAccount]))
-> UsageRecord
-> f UsageRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UsageByAccount] [UsageByAccount] [UsageByAccount] [UsageByAccount]
-> Iso
     (Maybe [UsageByAccount])
     (Maybe [UsageByAccount])
     (Maybe [UsageByAccount])
     (Maybe [UsageByAccount])
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
  [UsageByAccount] [UsageByAccount] [UsageByAccount] [UsageByAccount]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON UsageRecord where
  parseJSON :: Value -> Parser UsageRecord
parseJSON =
    String
-> (Object -> Parser UsageRecord) -> Value -> Parser UsageRecord
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UsageRecord"
      ( \Object
x ->
          Maybe Text -> Maybe POSIX -> Maybe [UsageByAccount] -> UsageRecord
UsageRecord'
            (Maybe Text
 -> Maybe POSIX -> Maybe [UsageByAccount] -> UsageRecord)
-> Parser (Maybe Text)
-> Parser (Maybe POSIX -> Maybe [UsageByAccount] -> UsageRecord)
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
"accountId")
            Parser (Maybe POSIX -> Maybe [UsageByAccount] -> UsageRecord)
-> Parser (Maybe POSIX)
-> Parser (Maybe [UsageByAccount] -> UsageRecord)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"freeTrialStartDate")
            Parser (Maybe [UsageByAccount] -> UsageRecord)
-> Parser (Maybe [UsageByAccount]) -> Parser UsageRecord
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [UsageByAccount]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"usage" Parser (Maybe (Maybe [UsageByAccount]))
-> Maybe [UsageByAccount] -> Parser (Maybe [UsageByAccount])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [UsageByAccount]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable UsageRecord

instance Prelude.NFData UsageRecord