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