module TD.Data.NetworkStatisticsEntry
(NetworkStatisticsEntry(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.FileType as FileType
import qualified TD.Data.NetworkType as NetworkType
data NetworkStatisticsEntry
= NetworkStatisticsEntryFile
{ NetworkStatisticsEntry -> Maybe FileType
file_type :: Maybe FileType.FileType
, NetworkStatisticsEntry -> Maybe NetworkType
network_type :: Maybe NetworkType.NetworkType
, NetworkStatisticsEntry -> Maybe Int
sent_bytes :: Maybe Int
, NetworkStatisticsEntry -> Maybe Int
received_bytes :: Maybe Int
}
| NetworkStatisticsEntryCall
{ network_type :: Maybe NetworkType.NetworkType
, sent_bytes :: Maybe Int
, received_bytes :: Maybe Int
, NetworkStatisticsEntry -> Maybe Double
duration :: Maybe Double
}
deriving (NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool
(NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool)
-> (NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool)
-> Eq NetworkStatisticsEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool
== :: NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool
$c/= :: NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool
/= :: NetworkStatisticsEntry -> NetworkStatisticsEntry -> Bool
Eq, Int -> NetworkStatisticsEntry -> ShowS
[NetworkStatisticsEntry] -> ShowS
NetworkStatisticsEntry -> String
(Int -> NetworkStatisticsEntry -> ShowS)
-> (NetworkStatisticsEntry -> String)
-> ([NetworkStatisticsEntry] -> ShowS)
-> Show NetworkStatisticsEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NetworkStatisticsEntry -> ShowS
showsPrec :: Int -> NetworkStatisticsEntry -> ShowS
$cshow :: NetworkStatisticsEntry -> String
show :: NetworkStatisticsEntry -> String
$cshowList :: [NetworkStatisticsEntry] -> ShowS
showList :: [NetworkStatisticsEntry] -> ShowS
Show)
instance I.ShortShow NetworkStatisticsEntry where
shortShow :: NetworkStatisticsEntry -> String
shortShow NetworkStatisticsEntryFile
{ file_type :: NetworkStatisticsEntry -> Maybe FileType
file_type = Maybe FileType
file_type_
, network_type :: NetworkStatisticsEntry -> Maybe NetworkType
network_type = Maybe NetworkType
network_type_
, sent_bytes :: NetworkStatisticsEntry -> Maybe Int
sent_bytes = Maybe Int
sent_bytes_
, received_bytes :: NetworkStatisticsEntry -> Maybe Int
received_bytes = Maybe Int
received_bytes_
}
= String
"NetworkStatisticsEntryFile"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"file_type" String -> Maybe FileType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FileType
file_type_
, String
"network_type" String -> Maybe NetworkType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe NetworkType
network_type_
, String
"sent_bytes" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sent_bytes_
, String
"received_bytes" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
received_bytes_
]
shortShow NetworkStatisticsEntryCall
{ network_type :: NetworkStatisticsEntry -> Maybe NetworkType
network_type = Maybe NetworkType
network_type_
, sent_bytes :: NetworkStatisticsEntry -> Maybe Int
sent_bytes = Maybe Int
sent_bytes_
, received_bytes :: NetworkStatisticsEntry -> Maybe Int
received_bytes = Maybe Int
received_bytes_
, duration :: NetworkStatisticsEntry -> Maybe Double
duration = Maybe Double
duration_
}
= String
"NetworkStatisticsEntryCall"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"network_type" String -> Maybe NetworkType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe NetworkType
network_type_
, String
"sent_bytes" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sent_bytes_
, String
"received_bytes" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
received_bytes_
, String
"duration" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
duration_
]
instance AT.FromJSON NetworkStatisticsEntry where
parseJSON :: Value -> Parser NetworkStatisticsEntry
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"networkStatisticsEntryFile" -> Value -> Parser NetworkStatisticsEntry
parseNetworkStatisticsEntryFile Value
v
String
"networkStatisticsEntryCall" -> Value -> Parser NetworkStatisticsEntry
parseNetworkStatisticsEntryCall Value
v
String
_ -> Parser NetworkStatisticsEntry
forall a. Monoid a => a
mempty
where
parseNetworkStatisticsEntryFile :: A.Value -> AT.Parser NetworkStatisticsEntry
parseNetworkStatisticsEntryFile :: Value -> Parser NetworkStatisticsEntry
parseNetworkStatisticsEntryFile = String
-> (Object -> Parser NetworkStatisticsEntry)
-> Value
-> Parser NetworkStatisticsEntry
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"NetworkStatisticsEntryFile" ((Object -> Parser NetworkStatisticsEntry)
-> Value -> Parser NetworkStatisticsEntry)
-> (Object -> Parser NetworkStatisticsEntry)
-> Value
-> Parser NetworkStatisticsEntry
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe FileType
file_type_ <- Object
o Object -> Key -> Parser (Maybe FileType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"file_type"
Maybe NetworkType
network_type_ <- Object
o Object -> Key -> Parser (Maybe NetworkType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"network_type"
Maybe Int
sent_bytes_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sent_bytes"
Maybe Int
received_bytes_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"received_bytes"
NetworkStatisticsEntry -> Parser NetworkStatisticsEntry
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NetworkStatisticsEntry -> Parser NetworkStatisticsEntry)
-> NetworkStatisticsEntry -> Parser NetworkStatisticsEntry
forall a b. (a -> b) -> a -> b
$ NetworkStatisticsEntryFile
{ file_type :: Maybe FileType
file_type = Maybe FileType
file_type_
, network_type :: Maybe NetworkType
network_type = Maybe NetworkType
network_type_
, sent_bytes :: Maybe Int
sent_bytes = Maybe Int
sent_bytes_
, received_bytes :: Maybe Int
received_bytes = Maybe Int
received_bytes_
}
parseNetworkStatisticsEntryCall :: A.Value -> AT.Parser NetworkStatisticsEntry
parseNetworkStatisticsEntryCall :: Value -> Parser NetworkStatisticsEntry
parseNetworkStatisticsEntryCall = String
-> (Object -> Parser NetworkStatisticsEntry)
-> Value
-> Parser NetworkStatisticsEntry
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"NetworkStatisticsEntryCall" ((Object -> Parser NetworkStatisticsEntry)
-> Value -> Parser NetworkStatisticsEntry)
-> (Object -> Parser NetworkStatisticsEntry)
-> Value
-> Parser NetworkStatisticsEntry
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe NetworkType
network_type_ <- Object
o Object -> Key -> Parser (Maybe NetworkType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"network_type"
Maybe Int
sent_bytes_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sent_bytes"
Maybe Int
received_bytes_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"received_bytes"
Maybe Double
duration_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"duration"
NetworkStatisticsEntry -> Parser NetworkStatisticsEntry
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NetworkStatisticsEntry -> Parser NetworkStatisticsEntry)
-> NetworkStatisticsEntry -> Parser NetworkStatisticsEntry
forall a b. (a -> b) -> a -> b
$ NetworkStatisticsEntryCall
{ network_type :: Maybe NetworkType
network_type = Maybe NetworkType
network_type_
, sent_bytes :: Maybe Int
sent_bytes = Maybe Int
sent_bytes_
, received_bytes :: Maybe Int
received_bytes = Maybe Int
received_bytes_
, duration :: Maybe Double
duration = Maybe Double
duration_
}
parseJSON Value
_ = Parser NetworkStatisticsEntry
forall a. Monoid a => a
mempty
instance AT.ToJSON NetworkStatisticsEntry where
toJSON :: NetworkStatisticsEntry -> Value
toJSON NetworkStatisticsEntryFile
{ file_type :: NetworkStatisticsEntry -> Maybe FileType
file_type = Maybe FileType
file_type_
, network_type :: NetworkStatisticsEntry -> Maybe NetworkType
network_type = Maybe NetworkType
network_type_
, sent_bytes :: NetworkStatisticsEntry -> Maybe Int
sent_bytes = Maybe Int
sent_bytes_
, received_bytes :: NetworkStatisticsEntry -> Maybe Int
received_bytes = Maybe Int
received_bytes_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"networkStatisticsEntryFile"
, Key
"file_type" Key -> Maybe FileType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FileType
file_type_
, Key
"network_type" Key -> Maybe NetworkType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe NetworkType
network_type_
, Key
"sent_bytes" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
sent_bytes_
, Key
"received_bytes" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
received_bytes_
]
toJSON NetworkStatisticsEntryCall
{ network_type :: NetworkStatisticsEntry -> Maybe NetworkType
network_type = Maybe NetworkType
network_type_
, sent_bytes :: NetworkStatisticsEntry -> Maybe Int
sent_bytes = Maybe Int
sent_bytes_
, received_bytes :: NetworkStatisticsEntry -> Maybe Int
received_bytes = Maybe Int
received_bytes_
, duration :: NetworkStatisticsEntry -> Maybe Double
duration = Maybe Double
duration_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"networkStatisticsEntryCall"
, Key
"network_type" Key -> Maybe NetworkType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe NetworkType
network_type_
, Key
"sent_bytes" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
sent_bytes_
, Key
"received_bytes" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
received_bytes_
, Key
"duration" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
duration_
]