module TD.Data.InputDocument
( InputDocument(..)
, defaultInputDocument
) 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.InputFile as InputFile
import qualified TD.Data.InputThumbnail as InputThumbnail
data InputDocument
= InputDocument
{ InputDocument -> Maybe InputFile
document :: Maybe InputFile.InputFile
, InputDocument -> Maybe InputThumbnail
thumbnail :: Maybe InputThumbnail.InputThumbnail
, InputDocument -> Maybe Bool
disable_content_type_detection :: Maybe Bool
}
deriving (InputDocument -> InputDocument -> Bool
(InputDocument -> InputDocument -> Bool)
-> (InputDocument -> InputDocument -> Bool) -> Eq InputDocument
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputDocument -> InputDocument -> Bool
== :: InputDocument -> InputDocument -> Bool
$c/= :: InputDocument -> InputDocument -> Bool
/= :: InputDocument -> InputDocument -> Bool
Eq, Int -> InputDocument -> ShowS
[InputDocument] -> ShowS
InputDocument -> String
(Int -> InputDocument -> ShowS)
-> (InputDocument -> String)
-> ([InputDocument] -> ShowS)
-> Show InputDocument
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputDocument -> ShowS
showsPrec :: Int -> InputDocument -> ShowS
$cshow :: InputDocument -> String
show :: InputDocument -> String
$cshowList :: [InputDocument] -> ShowS
showList :: [InputDocument] -> ShowS
Show)
instance I.ShortShow InputDocument where
shortShow :: InputDocument -> String
shortShow InputDocument
{ document :: InputDocument -> Maybe InputFile
document = Maybe InputFile
document_
, thumbnail :: InputDocument -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, disable_content_type_detection :: InputDocument -> Maybe Bool
disable_content_type_detection = Maybe Bool
disable_content_type_detection_
}
= String
"InputDocument"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"document" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
document_
, String
"thumbnail" String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
, String
"disable_content_type_detection" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
disable_content_type_detection_
]
instance AT.FromJSON InputDocument where
parseJSON :: Value -> Parser InputDocument
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
"inputDocument" -> Value -> Parser InputDocument
parseInputDocument Value
v
String
_ -> Parser InputDocument
forall a. Monoid a => a
mempty
where
parseInputDocument :: A.Value -> AT.Parser InputDocument
parseInputDocument :: Value -> Parser InputDocument
parseInputDocument = String
-> (Object -> Parser InputDocument)
-> Value
-> Parser InputDocument
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputDocument" ((Object -> Parser InputDocument) -> Value -> Parser InputDocument)
-> (Object -> Parser InputDocument)
-> Value
-> Parser InputDocument
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputFile
document_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"document"
Maybe InputThumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
Maybe Bool
disable_content_type_detection_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"disable_content_type_detection"
InputDocument -> Parser InputDocument
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputDocument -> Parser InputDocument)
-> InputDocument -> Parser InputDocument
forall a b. (a -> b) -> a -> b
$ InputDocument
{ document :: Maybe InputFile
document = Maybe InputFile
document_
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, disable_content_type_detection :: Maybe Bool
disable_content_type_detection = Maybe Bool
disable_content_type_detection_
}
parseJSON Value
_ = Parser InputDocument
forall a. Monoid a => a
mempty
instance AT.ToJSON InputDocument where
toJSON :: InputDocument -> Value
toJSON InputDocument
{ document :: InputDocument -> Maybe InputFile
document = Maybe InputFile
document_
, thumbnail :: InputDocument -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, disable_content_type_detection :: InputDocument -> Maybe Bool
disable_content_type_detection = Maybe Bool
disable_content_type_detection_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputDocument"
, Key
"document" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
document_
, Key
"thumbnail" Key -> Maybe InputThumbnail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputThumbnail
thumbnail_
, Key
"disable_content_type_detection" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
disable_content_type_detection_
]
defaultInputDocument :: InputDocument
defaultInputDocument :: InputDocument
defaultInputDocument =
InputDocument
{ document :: Maybe InputFile
document = Maybe InputFile
forall a. Maybe a
Nothing
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
forall a. Maybe a
Nothing
, disable_content_type_detection :: Maybe Bool
disable_content_type_detection = Maybe Bool
forall a. Maybe a
Nothing
}