module TD.Data.InputAnimation
( InputAnimation(..)
, defaultInputAnimation
) 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 InputAnimation
= InputAnimation
{ InputAnimation -> Maybe InputFile
animation :: Maybe InputFile.InputFile
, InputAnimation -> Maybe InputThumbnail
thumbnail :: Maybe InputThumbnail.InputThumbnail
, InputAnimation -> Maybe [Int]
added_sticker_file_ids :: Maybe [Int]
, InputAnimation -> Maybe Int
duration :: Maybe Int
, InputAnimation -> Maybe Int
width :: Maybe Int
, InputAnimation -> Maybe Int
height :: Maybe Int
}
deriving (InputAnimation -> InputAnimation -> Bool
(InputAnimation -> InputAnimation -> Bool)
-> (InputAnimation -> InputAnimation -> Bool) -> Eq InputAnimation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputAnimation -> InputAnimation -> Bool
== :: InputAnimation -> InputAnimation -> Bool
$c/= :: InputAnimation -> InputAnimation -> Bool
/= :: InputAnimation -> InputAnimation -> Bool
Eq, Int -> InputAnimation -> ShowS
[InputAnimation] -> ShowS
InputAnimation -> String
(Int -> InputAnimation -> ShowS)
-> (InputAnimation -> String)
-> ([InputAnimation] -> ShowS)
-> Show InputAnimation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputAnimation -> ShowS
showsPrec :: Int -> InputAnimation -> ShowS
$cshow :: InputAnimation -> String
show :: InputAnimation -> String
$cshowList :: [InputAnimation] -> ShowS
showList :: [InputAnimation] -> ShowS
Show)
instance I.ShortShow InputAnimation where
shortShow :: InputAnimation -> String
shortShow InputAnimation
{ animation :: InputAnimation -> Maybe InputFile
animation = Maybe InputFile
animation_
, thumbnail :: InputAnimation -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, added_sticker_file_ids :: InputAnimation -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, duration :: InputAnimation -> Maybe Int
duration = Maybe Int
duration_
, width :: InputAnimation -> Maybe Int
width = Maybe Int
width_
, height :: InputAnimation -> Maybe Int
height = Maybe Int
height_
}
= String
"InputAnimation"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"animation" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
animation_
, String
"thumbnail" String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
, String
"added_sticker_file_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
added_sticker_file_ids_
, 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_
]
instance AT.FromJSON InputAnimation where
parseJSON :: Value -> Parser InputAnimation
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
"inputAnimation" -> Value -> Parser InputAnimation
parseInputAnimation Value
v
String
_ -> Parser InputAnimation
forall a. Monoid a => a
mempty
where
parseInputAnimation :: A.Value -> AT.Parser InputAnimation
parseInputAnimation :: Value -> Parser InputAnimation
parseInputAnimation = String
-> (Object -> Parser InputAnimation)
-> Value
-> Parser InputAnimation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputAnimation" ((Object -> Parser InputAnimation)
-> Value -> Parser InputAnimation)
-> (Object -> Parser InputAnimation)
-> Value
-> Parser InputAnimation
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputFile
animation_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"animation"
Maybe InputThumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
Maybe [Int]
added_sticker_file_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"added_sticker_file_ids"
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"
InputAnimation -> Parser InputAnimation
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputAnimation -> Parser InputAnimation)
-> InputAnimation -> Parser InputAnimation
forall a b. (a -> b) -> a -> b
$ InputAnimation
{ animation :: Maybe InputFile
animation = Maybe InputFile
animation_
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, duration :: Maybe Int
duration = Maybe Int
duration_
, width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
}
parseJSON Value
_ = Parser InputAnimation
forall a. Monoid a => a
mempty
instance AT.ToJSON InputAnimation where
toJSON :: InputAnimation -> Value
toJSON InputAnimation
{ animation :: InputAnimation -> Maybe InputFile
animation = Maybe InputFile
animation_
, thumbnail :: InputAnimation -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, added_sticker_file_ids :: InputAnimation -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, duration :: InputAnimation -> Maybe Int
duration = Maybe Int
duration_
, width :: InputAnimation -> Maybe Int
width = Maybe Int
width_
, height :: InputAnimation -> Maybe Int
height = Maybe Int
height_
}
= [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
"inputAnimation"
, Key
"animation" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
animation_
, 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
"added_sticker_file_ids" Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
added_sticker_file_ids_
, Key
"duration" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
duration_
, Key
"width" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
width_
, Key
"height" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
height_
]
defaultInputAnimation :: InputAnimation
defaultInputAnimation :: InputAnimation
defaultInputAnimation =
InputAnimation
{ animation :: Maybe InputFile
animation = Maybe InputFile
forall a. Maybe a
Nothing
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
forall a. Maybe a
Nothing
, added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
forall a. Maybe a
Nothing
, duration :: Maybe Int
duration = Maybe Int
forall a. Maybe a
Nothing
, width :: Maybe Int
width = Maybe Int
forall a. Maybe a
Nothing
, height :: Maybe Int
height = Maybe Int
forall a. Maybe a
Nothing
}