module TD.Data.Thumbnail
(Thumbnail(..)) 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.ThumbnailFormat as ThumbnailFormat
import qualified TD.Data.File as File
data Thumbnail
= Thumbnail
{ Thumbnail -> Maybe ThumbnailFormat
format :: Maybe ThumbnailFormat.ThumbnailFormat
, Thumbnail -> Maybe Int
width :: Maybe Int
, Thumbnail -> Maybe Int
height :: Maybe Int
, Thumbnail -> Maybe File
file :: Maybe File.File
}
deriving (Thumbnail -> Thumbnail -> Bool
(Thumbnail -> Thumbnail -> Bool)
-> (Thumbnail -> Thumbnail -> Bool) -> Eq Thumbnail
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Thumbnail -> Thumbnail -> Bool
== :: Thumbnail -> Thumbnail -> Bool
$c/= :: Thumbnail -> Thumbnail -> Bool
/= :: Thumbnail -> Thumbnail -> Bool
Eq, Int -> Thumbnail -> ShowS
[Thumbnail] -> ShowS
Thumbnail -> String
(Int -> Thumbnail -> ShowS)
-> (Thumbnail -> String)
-> ([Thumbnail] -> ShowS)
-> Show Thumbnail
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Thumbnail -> ShowS
showsPrec :: Int -> Thumbnail -> ShowS
$cshow :: Thumbnail -> String
show :: Thumbnail -> String
$cshowList :: [Thumbnail] -> ShowS
showList :: [Thumbnail] -> ShowS
Show)
instance I.ShortShow Thumbnail where
shortShow :: Thumbnail -> String
shortShow Thumbnail
{ format :: Thumbnail -> Maybe ThumbnailFormat
format = Maybe ThumbnailFormat
format_
, width :: Thumbnail -> Maybe Int
width = Maybe Int
width_
, height :: Thumbnail -> Maybe Int
height = Maybe Int
height_
, file :: Thumbnail -> Maybe File
file = Maybe File
file_
}
= String
"Thumbnail"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"format" String -> Maybe ThumbnailFormat -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ThumbnailFormat
format_
, String
"width" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
width_
, String
"height" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_
, String
"file" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
file_
]
instance AT.FromJSON Thumbnail where
parseJSON :: Value -> Parser Thumbnail
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
"thumbnail" -> Value -> Parser Thumbnail
parseThumbnail Value
v
String
_ -> Parser Thumbnail
forall a. Monoid a => a
mempty
where
parseThumbnail :: A.Value -> AT.Parser Thumbnail
parseThumbnail :: Value -> Parser Thumbnail
parseThumbnail = String -> (Object -> Parser Thumbnail) -> Value -> Parser Thumbnail
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Thumbnail" ((Object -> Parser Thumbnail) -> Value -> Parser Thumbnail)
-> (Object -> Parser Thumbnail) -> Value -> Parser Thumbnail
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ThumbnailFormat
format_ <- Object
o Object -> Key -> Parser (Maybe ThumbnailFormat)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"format"
Maybe Int
width_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"width"
Maybe Int
height_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"height"
Maybe File
file_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"file"
Thumbnail -> Parser Thumbnail
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Thumbnail -> Parser Thumbnail) -> Thumbnail -> Parser Thumbnail
forall a b. (a -> b) -> a -> b
$ Thumbnail
{ format :: Maybe ThumbnailFormat
format = Maybe ThumbnailFormat
format_
, width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
, file :: Maybe File
file = Maybe File
file_
}
parseJSON Value
_ = Parser Thumbnail
forall a. Monoid a => a
mempty