{-# 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 #-}
module Amazonka.MarketplaceMetering.Types.UsageRecord where
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MarketplaceMetering.Types.UsageAllocation
import qualified Amazonka.Prelude as Prelude
data UsageRecord = UsageRecord'
{
UsageRecord -> Maybe Natural
quantity :: Prelude.Maybe Prelude.Natural,
UsageRecord -> Maybe (NonEmpty UsageAllocation)
usageAllocations :: Prelude.Maybe (Prelude.NonEmpty UsageAllocation),
UsageRecord -> POSIX
timestamp :: Core.POSIX,
UsageRecord -> Text
customerIdentifier :: Prelude.Text,
UsageRecord -> Text
dimension :: Prelude.Text
}
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)
newUsageRecord ::
Prelude.UTCTime ->
Prelude.Text ->
Prelude.Text ->
UsageRecord
newUsageRecord :: UTCTime -> Text -> Text -> UsageRecord
newUsageRecord
UTCTime
pTimestamp_
Text
pCustomerIdentifier_
Text
pDimension_ =
UsageRecord' :: Maybe Natural
-> Maybe (NonEmpty UsageAllocation)
-> POSIX
-> Text
-> Text
-> UsageRecord
UsageRecord'
{ $sel:quantity:UsageRecord' :: Maybe Natural
quantity = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
$sel:usageAllocations:UsageRecord' :: Maybe (NonEmpty UsageAllocation)
usageAllocations = Maybe (NonEmpty UsageAllocation)
forall a. Maybe a
Prelude.Nothing,
$sel:timestamp:UsageRecord' :: POSIX
timestamp = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
-> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pTimestamp_,
$sel:customerIdentifier:UsageRecord' :: Text
customerIdentifier = Text
pCustomerIdentifier_,
$sel:dimension:UsageRecord' :: Text
dimension = Text
pDimension_
}
usageRecord_quantity :: Lens.Lens' UsageRecord (Prelude.Maybe Prelude.Natural)
usageRecord_quantity :: (Maybe Natural -> f (Maybe Natural))
-> UsageRecord -> f UsageRecord
usageRecord_quantity = (UsageRecord -> Maybe Natural)
-> (UsageRecord -> Maybe Natural -> UsageRecord)
-> Lens UsageRecord UsageRecord (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Maybe Natural
quantity :: Maybe Natural
$sel:quantity:UsageRecord' :: UsageRecord -> Maybe Natural
quantity} -> Maybe Natural
quantity) (\s :: UsageRecord
s@UsageRecord' {} Maybe Natural
a -> UsageRecord
s {$sel:quantity:UsageRecord' :: Maybe Natural
quantity = Maybe Natural
a} :: UsageRecord)
usageRecord_usageAllocations :: Lens.Lens' UsageRecord (Prelude.Maybe (Prelude.NonEmpty UsageAllocation))
usageRecord_usageAllocations :: (Maybe (NonEmpty UsageAllocation)
-> f (Maybe (NonEmpty UsageAllocation)))
-> UsageRecord -> f UsageRecord
usageRecord_usageAllocations = (UsageRecord -> Maybe (NonEmpty UsageAllocation))
-> (UsageRecord -> Maybe (NonEmpty UsageAllocation) -> UsageRecord)
-> Lens
UsageRecord
UsageRecord
(Maybe (NonEmpty UsageAllocation))
(Maybe (NonEmpty UsageAllocation))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Maybe (NonEmpty UsageAllocation)
usageAllocations :: Maybe (NonEmpty UsageAllocation)
$sel:usageAllocations:UsageRecord' :: UsageRecord -> Maybe (NonEmpty UsageAllocation)
usageAllocations} -> Maybe (NonEmpty UsageAllocation)
usageAllocations) (\s :: UsageRecord
s@UsageRecord' {} Maybe (NonEmpty UsageAllocation)
a -> UsageRecord
s {$sel:usageAllocations:UsageRecord' :: Maybe (NonEmpty UsageAllocation)
usageAllocations = Maybe (NonEmpty UsageAllocation)
a} :: UsageRecord) ((Maybe (NonEmpty UsageAllocation)
-> f (Maybe (NonEmpty UsageAllocation)))
-> UsageRecord -> f UsageRecord)
-> ((Maybe (NonEmpty UsageAllocation)
-> f (Maybe (NonEmpty UsageAllocation)))
-> Maybe (NonEmpty UsageAllocation)
-> f (Maybe (NonEmpty UsageAllocation)))
-> (Maybe (NonEmpty UsageAllocation)
-> f (Maybe (NonEmpty UsageAllocation)))
-> UsageRecord
-> f UsageRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
(NonEmpty UsageAllocation)
(NonEmpty UsageAllocation)
(NonEmpty UsageAllocation)
(NonEmpty UsageAllocation)
-> Iso
(Maybe (NonEmpty UsageAllocation))
(Maybe (NonEmpty UsageAllocation))
(Maybe (NonEmpty UsageAllocation))
(Maybe (NonEmpty UsageAllocation))
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
(NonEmpty UsageAllocation)
(NonEmpty UsageAllocation)
(NonEmpty UsageAllocation)
(NonEmpty UsageAllocation)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
usageRecord_timestamp :: Lens.Lens' UsageRecord Prelude.UTCTime
usageRecord_timestamp :: (UTCTime -> f UTCTime) -> UsageRecord -> f UsageRecord
usageRecord_timestamp = (UsageRecord -> POSIX)
-> (UsageRecord -> POSIX -> UsageRecord)
-> Lens UsageRecord UsageRecord POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {POSIX
timestamp :: POSIX
$sel:timestamp:UsageRecord' :: UsageRecord -> POSIX
timestamp} -> POSIX
timestamp) (\s :: UsageRecord
s@UsageRecord' {} POSIX
a -> UsageRecord
s {$sel:timestamp:UsageRecord' :: POSIX
timestamp = POSIX
a} :: UsageRecord) ((POSIX -> f POSIX) -> UsageRecord -> f UsageRecord)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> UsageRecord
-> f UsageRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time
usageRecord_customerIdentifier :: Lens.Lens' UsageRecord Prelude.Text
usageRecord_customerIdentifier :: (Text -> f Text) -> UsageRecord -> f UsageRecord
usageRecord_customerIdentifier = (UsageRecord -> Text)
-> (UsageRecord -> Text -> UsageRecord)
-> Lens UsageRecord UsageRecord Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Text
customerIdentifier :: Text
$sel:customerIdentifier:UsageRecord' :: UsageRecord -> Text
customerIdentifier} -> Text
customerIdentifier) (\s :: UsageRecord
s@UsageRecord' {} Text
a -> UsageRecord
s {$sel:customerIdentifier:UsageRecord' :: Text
customerIdentifier = Text
a} :: UsageRecord)
usageRecord_dimension :: Lens.Lens' UsageRecord Prelude.Text
usageRecord_dimension :: (Text -> f Text) -> UsageRecord -> f UsageRecord
usageRecord_dimension = (UsageRecord -> Text)
-> (UsageRecord -> Text -> UsageRecord)
-> Lens UsageRecord UsageRecord Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UsageRecord' {Text
dimension :: Text
$sel:dimension:UsageRecord' :: UsageRecord -> Text
dimension} -> Text
dimension) (\s :: UsageRecord
s@UsageRecord' {} Text
a -> UsageRecord
s {$sel:dimension:UsageRecord' :: Text
dimension = Text
a} :: UsageRecord)
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 Natural
-> Maybe (NonEmpty UsageAllocation)
-> POSIX
-> Text
-> Text
-> UsageRecord
UsageRecord'
(Maybe Natural
-> Maybe (NonEmpty UsageAllocation)
-> POSIX
-> Text
-> Text
-> UsageRecord)
-> Parser (Maybe Natural)
-> Parser
(Maybe (NonEmpty UsageAllocation)
-> POSIX -> Text -> Text -> UsageRecord)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Quantity")
Parser
(Maybe (NonEmpty UsageAllocation)
-> POSIX -> Text -> Text -> UsageRecord)
-> Parser (Maybe (NonEmpty UsageAllocation))
-> Parser (POSIX -> Text -> Text -> UsageRecord)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty UsageAllocation))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UsageAllocations")
Parser (POSIX -> Text -> Text -> UsageRecord)
-> Parser POSIX -> Parser (Text -> Text -> UsageRecord)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Timestamp")
Parser (Text -> Text -> UsageRecord)
-> Parser Text -> Parser (Text -> UsageRecord)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"CustomerIdentifier")
Parser (Text -> UsageRecord) -> Parser Text -> Parser UsageRecord
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Dimension")
)
instance Prelude.Hashable UsageRecord
instance Prelude.NFData UsageRecord
instance Core.ToJSON UsageRecord where
toJSON :: UsageRecord -> Value
toJSON UsageRecord' {Maybe Natural
Maybe (NonEmpty UsageAllocation)
Text
POSIX
dimension :: Text
customerIdentifier :: Text
timestamp :: POSIX
usageAllocations :: Maybe (NonEmpty UsageAllocation)
quantity :: Maybe Natural
$sel:dimension:UsageRecord' :: UsageRecord -> Text
$sel:customerIdentifier:UsageRecord' :: UsageRecord -> Text
$sel:timestamp:UsageRecord' :: UsageRecord -> POSIX
$sel:usageAllocations:UsageRecord' :: UsageRecord -> Maybe (NonEmpty UsageAllocation)
$sel:quantity:UsageRecord' :: UsageRecord -> Maybe Natural
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Text
"Quantity" 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
quantity,
(Text
"UsageAllocations" Text -> NonEmpty UsageAllocation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
(NonEmpty UsageAllocation -> Pair)
-> Maybe (NonEmpty UsageAllocation) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty UsageAllocation)
usageAllocations,
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Timestamp" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
timestamp),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
(Text
"CustomerIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
customerIdentifier),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Dimension" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
dimension)
]
)