module TD.Data.FoundFileDownloads
(FoundFileDownloads(..)) 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.DownloadedFileCounts as DownloadedFileCounts
import qualified TD.Data.FileDownload as FileDownload
import qualified Data.Text as T
data FoundFileDownloads
= FoundFileDownloads
{ FoundFileDownloads -> Maybe DownloadedFileCounts
total_counts :: Maybe DownloadedFileCounts.DownloadedFileCounts
, FoundFileDownloads -> Maybe [FileDownload]
files :: Maybe [FileDownload.FileDownload]
, FoundFileDownloads -> Maybe Text
next_offset :: Maybe T.Text
}
deriving (FoundFileDownloads -> FoundFileDownloads -> Bool
(FoundFileDownloads -> FoundFileDownloads -> Bool)
-> (FoundFileDownloads -> FoundFileDownloads -> Bool)
-> Eq FoundFileDownloads
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FoundFileDownloads -> FoundFileDownloads -> Bool
== :: FoundFileDownloads -> FoundFileDownloads -> Bool
$c/= :: FoundFileDownloads -> FoundFileDownloads -> Bool
/= :: FoundFileDownloads -> FoundFileDownloads -> Bool
Eq, Int -> FoundFileDownloads -> ShowS
[FoundFileDownloads] -> ShowS
FoundFileDownloads -> String
(Int -> FoundFileDownloads -> ShowS)
-> (FoundFileDownloads -> String)
-> ([FoundFileDownloads] -> ShowS)
-> Show FoundFileDownloads
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FoundFileDownloads -> ShowS
showsPrec :: Int -> FoundFileDownloads -> ShowS
$cshow :: FoundFileDownloads -> String
show :: FoundFileDownloads -> String
$cshowList :: [FoundFileDownloads] -> ShowS
showList :: [FoundFileDownloads] -> ShowS
Show)
instance I.ShortShow FoundFileDownloads where
shortShow :: FoundFileDownloads -> String
shortShow FoundFileDownloads
{ total_counts :: FoundFileDownloads -> Maybe DownloadedFileCounts
total_counts = Maybe DownloadedFileCounts
total_counts_
, files :: FoundFileDownloads -> Maybe [FileDownload]
files = Maybe [FileDownload]
files_
, next_offset :: FoundFileDownloads -> Maybe Text
next_offset = Maybe Text
next_offset_
}
= String
"FoundFileDownloads"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"total_counts" String -> Maybe DownloadedFileCounts -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe DownloadedFileCounts
total_counts_
, String
"files" String -> Maybe [FileDownload] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [FileDownload]
files_
, String
"next_offset" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
]
instance AT.FromJSON FoundFileDownloads where
parseJSON :: Value -> Parser FoundFileDownloads
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
"foundFileDownloads" -> Value -> Parser FoundFileDownloads
parseFoundFileDownloads Value
v
String
_ -> Parser FoundFileDownloads
forall a. Monoid a => a
mempty
where
parseFoundFileDownloads :: A.Value -> AT.Parser FoundFileDownloads
parseFoundFileDownloads :: Value -> Parser FoundFileDownloads
parseFoundFileDownloads = String
-> (Object -> Parser FoundFileDownloads)
-> Value
-> Parser FoundFileDownloads
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"FoundFileDownloads" ((Object -> Parser FoundFileDownloads)
-> Value -> Parser FoundFileDownloads)
-> (Object -> Parser FoundFileDownloads)
-> Value
-> Parser FoundFileDownloads
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe DownloadedFileCounts
total_counts_ <- Object
o Object -> Key -> Parser (Maybe DownloadedFileCounts)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"total_counts"
Maybe [FileDownload]
files_ <- Object
o Object -> Key -> Parser (Maybe [FileDownload])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"files"
Maybe Text
next_offset_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"next_offset"
FoundFileDownloads -> Parser FoundFileDownloads
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FoundFileDownloads -> Parser FoundFileDownloads)
-> FoundFileDownloads -> Parser FoundFileDownloads
forall a b. (a -> b) -> a -> b
$ FoundFileDownloads
{ total_counts :: Maybe DownloadedFileCounts
total_counts = Maybe DownloadedFileCounts
total_counts_
, files :: Maybe [FileDownload]
files = Maybe [FileDownload]
files_
, next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
}
parseJSON Value
_ = Parser FoundFileDownloads
forall a. Monoid a => a
mempty