module TD.Data.DownloadedFileCounts
(DownloadedFileCounts(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data DownloadedFileCounts
= DownloadedFileCounts
{ DownloadedFileCounts -> Maybe Int
active_count :: Maybe Int
, DownloadedFileCounts -> Maybe Int
paused_count :: Maybe Int
, DownloadedFileCounts -> Maybe Int
completed_count :: Maybe Int
}
deriving (DownloadedFileCounts -> DownloadedFileCounts -> Bool
(DownloadedFileCounts -> DownloadedFileCounts -> Bool)
-> (DownloadedFileCounts -> DownloadedFileCounts -> Bool)
-> Eq DownloadedFileCounts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DownloadedFileCounts -> DownloadedFileCounts -> Bool
== :: DownloadedFileCounts -> DownloadedFileCounts -> Bool
$c/= :: DownloadedFileCounts -> DownloadedFileCounts -> Bool
/= :: DownloadedFileCounts -> DownloadedFileCounts -> Bool
Eq, Int -> DownloadedFileCounts -> ShowS
[DownloadedFileCounts] -> ShowS
DownloadedFileCounts -> String
(Int -> DownloadedFileCounts -> ShowS)
-> (DownloadedFileCounts -> String)
-> ([DownloadedFileCounts] -> ShowS)
-> Show DownloadedFileCounts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DownloadedFileCounts -> ShowS
showsPrec :: Int -> DownloadedFileCounts -> ShowS
$cshow :: DownloadedFileCounts -> String
show :: DownloadedFileCounts -> String
$cshowList :: [DownloadedFileCounts] -> ShowS
showList :: [DownloadedFileCounts] -> ShowS
Show)
instance I.ShortShow DownloadedFileCounts where
shortShow :: DownloadedFileCounts -> String
shortShow DownloadedFileCounts
{ active_count :: DownloadedFileCounts -> Maybe Int
active_count = Maybe Int
active_count_
, paused_count :: DownloadedFileCounts -> Maybe Int
paused_count = Maybe Int
paused_count_
, completed_count :: DownloadedFileCounts -> Maybe Int
completed_count = Maybe Int
completed_count_
}
= String
"DownloadedFileCounts"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"active_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
active_count_
, String
"paused_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
paused_count_
, String
"completed_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
completed_count_
]
instance AT.FromJSON DownloadedFileCounts where
parseJSON :: Value -> Parser DownloadedFileCounts
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
"downloadedFileCounts" -> Value -> Parser DownloadedFileCounts
parseDownloadedFileCounts Value
v
String
_ -> Parser DownloadedFileCounts
forall a. Monoid a => a
mempty
where
parseDownloadedFileCounts :: A.Value -> AT.Parser DownloadedFileCounts
parseDownloadedFileCounts :: Value -> Parser DownloadedFileCounts
parseDownloadedFileCounts = String
-> (Object -> Parser DownloadedFileCounts)
-> Value
-> Parser DownloadedFileCounts
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"DownloadedFileCounts" ((Object -> Parser DownloadedFileCounts)
-> Value -> Parser DownloadedFileCounts)
-> (Object -> Parser DownloadedFileCounts)
-> Value
-> Parser DownloadedFileCounts
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
active_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"active_count"
Maybe Int
paused_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"paused_count"
Maybe Int
completed_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"completed_count"
DownloadedFileCounts -> Parser DownloadedFileCounts
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DownloadedFileCounts -> Parser DownloadedFileCounts)
-> DownloadedFileCounts -> Parser DownloadedFileCounts
forall a b. (a -> b) -> a -> b
$ DownloadedFileCounts
{ active_count :: Maybe Int
active_count = Maybe Int
active_count_
, paused_count :: Maybe Int
paused_count = Maybe Int
paused_count_
, completed_count :: Maybe Int
completed_count = Maybe Int
completed_count_
}
parseJSON Value
_ = Parser DownloadedFileCounts
forall a. Monoid a => a
mempty