module TD.Data.FileDownload
(FileDownload(..)) 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.Message as Message
data FileDownload
= FileDownload
{ FileDownload -> Maybe Int
file_id :: Maybe Int
, FileDownload -> Maybe Message
message :: Maybe Message.Message
, FileDownload -> Maybe Int
add_date :: Maybe Int
, FileDownload -> Maybe Int
complete_date :: Maybe Int
, FileDownload -> Maybe Bool
is_paused :: Maybe Bool
}
deriving (FileDownload -> FileDownload -> Bool
(FileDownload -> FileDownload -> Bool)
-> (FileDownload -> FileDownload -> Bool) -> Eq FileDownload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileDownload -> FileDownload -> Bool
== :: FileDownload -> FileDownload -> Bool
$c/= :: FileDownload -> FileDownload -> Bool
/= :: FileDownload -> FileDownload -> Bool
Eq, Int -> FileDownload -> ShowS
[FileDownload] -> ShowS
FileDownload -> String
(Int -> FileDownload -> ShowS)
-> (FileDownload -> String)
-> ([FileDownload] -> ShowS)
-> Show FileDownload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileDownload -> ShowS
showsPrec :: Int -> FileDownload -> ShowS
$cshow :: FileDownload -> String
show :: FileDownload -> String
$cshowList :: [FileDownload] -> ShowS
showList :: [FileDownload] -> ShowS
Show)
instance I.ShortShow FileDownload where
shortShow :: FileDownload -> String
shortShow FileDownload
{ file_id :: FileDownload -> Maybe Int
file_id = Maybe Int
file_id_
, message :: FileDownload -> Maybe Message
message = Maybe Message
message_
, add_date :: FileDownload -> Maybe Int
add_date = Maybe Int
add_date_
, complete_date :: FileDownload -> Maybe Int
complete_date = Maybe Int
complete_date_
, is_paused :: FileDownload -> Maybe Bool
is_paused = Maybe Bool
is_paused_
}
= String
"FileDownload"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"file_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
file_id_
, String
"message" String -> Maybe Message -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Message
message_
, String
"add_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
add_date_
, String
"complete_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
complete_date_
, String
"is_paused" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_paused_
]
instance AT.FromJSON FileDownload where
parseJSON :: Value -> Parser FileDownload
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
"fileDownload" -> Value -> Parser FileDownload
parseFileDownload Value
v
String
_ -> Parser FileDownload
forall a. Monoid a => a
mempty
where
parseFileDownload :: A.Value -> AT.Parser FileDownload
parseFileDownload :: Value -> Parser FileDownload
parseFileDownload = String
-> (Object -> Parser FileDownload) -> Value -> Parser FileDownload
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"FileDownload" ((Object -> Parser FileDownload) -> Value -> Parser FileDownload)
-> (Object -> Parser FileDownload) -> Value -> Parser FileDownload
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
file_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"file_id"
Maybe Message
message_ <- Object
o Object -> Key -> Parser (Maybe Message)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message"
Maybe Int
add_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"add_date"
Maybe Int
complete_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"complete_date"
Maybe Bool
is_paused_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_paused"
FileDownload -> Parser FileDownload
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FileDownload -> Parser FileDownload)
-> FileDownload -> Parser FileDownload
forall a b. (a -> b) -> a -> b
$ FileDownload
{ file_id :: Maybe Int
file_id = Maybe Int
file_id_
, message :: Maybe Message
message = Maybe Message
message_
, add_date :: Maybe Int
add_date = Maybe Int
add_date_
, complete_date :: Maybe Int
complete_date = Maybe Int
complete_date_
, is_paused :: Maybe Bool
is_paused = Maybe Bool
is_paused_
}
parseJSON Value
_ = Parser FileDownload
forall a. Monoid a => a
mempty