module TD.Data.Document
(Document(..)) 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
import qualified TD.Data.Minithumbnail as Minithumbnail
import qualified TD.Data.Thumbnail as Thumbnail
import qualified TD.Data.File as File
data Document
= Document
{ Document -> Maybe Text
file_name :: Maybe T.Text
, Document -> Maybe Text
mime_type :: Maybe T.Text
, Document -> Maybe Minithumbnail
minithumbnail :: Maybe Minithumbnail.Minithumbnail
, Document -> Maybe Thumbnail
thumbnail :: Maybe Thumbnail.Thumbnail
, Document -> Maybe File
document :: Maybe File.File
}
deriving (Document -> Document -> Bool
(Document -> Document -> Bool)
-> (Document -> Document -> Bool) -> Eq Document
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Document -> Document -> Bool
== :: Document -> Document -> Bool
$c/= :: Document -> Document -> Bool
/= :: Document -> Document -> Bool
Eq, Int -> Document -> ShowS
[Document] -> ShowS
Document -> String
(Int -> Document -> ShowS)
-> (Document -> String) -> ([Document] -> ShowS) -> Show Document
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Document -> ShowS
showsPrec :: Int -> Document -> ShowS
$cshow :: Document -> String
show :: Document -> String
$cshowList :: [Document] -> ShowS
showList :: [Document] -> ShowS
Show)
instance I.ShortShow Document where
shortShow :: Document -> String
shortShow Document
{ file_name :: Document -> Maybe Text
file_name = Maybe Text
file_name_
, mime_type :: Document -> Maybe Text
mime_type = Maybe Text
mime_type_
, minithumbnail :: Document -> Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
, thumbnail :: Document -> Maybe Thumbnail
thumbnail = Maybe Thumbnail
thumbnail_
, document :: Document -> Maybe File
document = Maybe File
document_
}
= String
"Document"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"file_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
file_name_
, String
"mime_type" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
mime_type_
, String
"minithumbnail" String -> Maybe Minithumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Minithumbnail
minithumbnail_
, String
"thumbnail" String -> Maybe Thumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Thumbnail
thumbnail_
, String
"document" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
document_
]
instance AT.FromJSON Document where
parseJSON :: Value -> Parser Document
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
"document" -> Value -> Parser Document
parseDocument Value
v
String
_ -> Parser Document
forall a. Monoid a => a
mempty
where
parseDocument :: A.Value -> AT.Parser Document
parseDocument :: Value -> Parser Document
parseDocument = String -> (Object -> Parser Document) -> Value -> Parser Document
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Document" ((Object -> Parser Document) -> Value -> Parser Document)
-> (Object -> Parser Document) -> Value -> Parser Document
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
file_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"file_name"
Maybe Text
mime_type_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"mime_type"
Maybe Minithumbnail
minithumbnail_ <- Object
o Object -> Key -> Parser (Maybe Minithumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"minithumbnail"
Maybe Thumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe Thumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
Maybe File
document_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"document"
Document -> Parser Document
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Document -> Parser Document) -> Document -> Parser Document
forall a b. (a -> b) -> a -> b
$ Document
{ file_name :: Maybe Text
file_name = Maybe Text
file_name_
, mime_type :: Maybe Text
mime_type = Maybe Text
mime_type_
, minithumbnail :: Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
, thumbnail :: Maybe Thumbnail
thumbnail = Maybe Thumbnail
thumbnail_
, document :: Maybe File
document = Maybe File
document_
}
parseJSON Value
_ = Parser Document
forall a. Monoid a => a
mempty