module TD.Data.RemoteFile
(RemoteFile(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data RemoteFile
= RemoteFile
{ RemoteFile -> Maybe Text
_id :: Maybe T.Text
, RemoteFile -> Maybe Text
unique_id :: Maybe T.Text
, RemoteFile -> Maybe Bool
is_uploading_active :: Maybe Bool
, RemoteFile -> Maybe Bool
is_uploading_completed :: Maybe Bool
, RemoteFile -> Maybe Int
uploaded_size :: Maybe Int
}
deriving (RemoteFile -> RemoteFile -> Bool
(RemoteFile -> RemoteFile -> Bool)
-> (RemoteFile -> RemoteFile -> Bool) -> Eq RemoteFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RemoteFile -> RemoteFile -> Bool
== :: RemoteFile -> RemoteFile -> Bool
$c/= :: RemoteFile -> RemoteFile -> Bool
/= :: RemoteFile -> RemoteFile -> Bool
Eq, Int -> RemoteFile -> ShowS
[RemoteFile] -> ShowS
RemoteFile -> String
(Int -> RemoteFile -> ShowS)
-> (RemoteFile -> String)
-> ([RemoteFile] -> ShowS)
-> Show RemoteFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RemoteFile -> ShowS
showsPrec :: Int -> RemoteFile -> ShowS
$cshow :: RemoteFile -> String
show :: RemoteFile -> String
$cshowList :: [RemoteFile] -> ShowS
showList :: [RemoteFile] -> ShowS
Show)
instance I.ShortShow RemoteFile where
shortShow :: RemoteFile -> String
shortShow RemoteFile
{ _id :: RemoteFile -> Maybe Text
_id = Maybe Text
_id_
, unique_id :: RemoteFile -> Maybe Text
unique_id = Maybe Text
unique_id_
, is_uploading_active :: RemoteFile -> Maybe Bool
is_uploading_active = Maybe Bool
is_uploading_active_
, is_uploading_completed :: RemoteFile -> Maybe Bool
is_uploading_completed = Maybe Bool
is_uploading_completed_
, uploaded_size :: RemoteFile -> Maybe Int
uploaded_size = Maybe Int
uploaded_size_
}
= String
"RemoteFile"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
, String
"unique_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
unique_id_
, String
"is_uploading_active" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_uploading_active_
, String
"is_uploading_completed" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_uploading_completed_
, String
"uploaded_size" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
uploaded_size_
]
instance AT.FromJSON RemoteFile where
parseJSON :: Value -> Parser RemoteFile
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
"remoteFile" -> Value -> Parser RemoteFile
parseRemoteFile Value
v
String
_ -> Parser RemoteFile
forall a. Monoid a => a
mempty
where
parseRemoteFile :: A.Value -> AT.Parser RemoteFile
parseRemoteFile :: Value -> Parser RemoteFile
parseRemoteFile = String
-> (Object -> Parser RemoteFile) -> Value -> Parser RemoteFile
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"RemoteFile" ((Object -> Parser RemoteFile) -> Value -> Parser RemoteFile)
-> (Object -> Parser RemoteFile) -> Value -> Parser RemoteFile
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Text
unique_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"unique_id"
Maybe Bool
is_uploading_active_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_uploading_active"
Maybe Bool
is_uploading_completed_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_uploading_completed"
Maybe Int
uploaded_size_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"uploaded_size"
RemoteFile -> Parser RemoteFile
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RemoteFile -> Parser RemoteFile)
-> RemoteFile -> Parser RemoteFile
forall a b. (a -> b) -> a -> b
$ RemoteFile
{ _id :: Maybe Text
_id = Maybe Text
_id_
, unique_id :: Maybe Text
unique_id = Maybe Text
unique_id_
, is_uploading_active :: Maybe Bool
is_uploading_active = Maybe Bool
is_uploading_active_
, is_uploading_completed :: Maybe Bool
is_uploading_completed = Maybe Bool
is_uploading_completed_
, uploaded_size :: Maybe Int
uploaded_size = Maybe Int
uploaded_size_
}
parseJSON Value
_ = Parser RemoteFile
forall a. Monoid a => a
mempty