module TD.Data.InputStoryContent
(InputStoryContent(..)) 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
data InputStoryContent
= InputStoryContentPhoto
{ InputStoryContent -> Maybe InputFile
photo :: Maybe InputFile.InputFile
, InputStoryContent -> Maybe [Int]
added_sticker_file_ids :: Maybe [Int]
}
| InputStoryContentVideo
{ InputStoryContent -> Maybe InputFile
video :: Maybe InputFile.InputFile
, added_sticker_file_ids :: Maybe [Int]
, InputStoryContent -> Maybe Double
duration :: Maybe Double
, InputStoryContent -> Maybe Double
cover_frame_timestamp :: Maybe Double
, InputStoryContent -> Maybe Bool
is_animation :: Maybe Bool
}
deriving (InputStoryContent -> InputStoryContent -> Bool
(InputStoryContent -> InputStoryContent -> Bool)
-> (InputStoryContent -> InputStoryContent -> Bool)
-> Eq InputStoryContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputStoryContent -> InputStoryContent -> Bool
== :: InputStoryContent -> InputStoryContent -> Bool
$c/= :: InputStoryContent -> InputStoryContent -> Bool
/= :: InputStoryContent -> InputStoryContent -> Bool
Eq, Int -> InputStoryContent -> ShowS
[InputStoryContent] -> ShowS
InputStoryContent -> String
(Int -> InputStoryContent -> ShowS)
-> (InputStoryContent -> String)
-> ([InputStoryContent] -> ShowS)
-> Show InputStoryContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputStoryContent -> ShowS
showsPrec :: Int -> InputStoryContent -> ShowS
$cshow :: InputStoryContent -> String
show :: InputStoryContent -> String
$cshowList :: [InputStoryContent] -> ShowS
showList :: [InputStoryContent] -> ShowS
Show)
instance I.ShortShow InputStoryContent where
shortShow :: InputStoryContent -> String
shortShow InputStoryContentPhoto
{ photo :: InputStoryContent -> Maybe InputFile
photo = Maybe InputFile
photo_
, added_sticker_file_ids :: InputStoryContent -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
}
= String
"InputStoryContentPhoto"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"photo" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
photo_
, 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_
]
shortShow InputStoryContentVideo
{ video :: InputStoryContent -> Maybe InputFile
video = Maybe InputFile
video_
, added_sticker_file_ids :: InputStoryContent -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, duration :: InputStoryContent -> Maybe Double
duration = Maybe Double
duration_
, cover_frame_timestamp :: InputStoryContent -> Maybe Double
cover_frame_timestamp = Maybe Double
cover_frame_timestamp_
, is_animation :: InputStoryContent -> Maybe Bool
is_animation = Maybe Bool
is_animation_
}
= String
"InputStoryContentVideo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"video" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
video_
, 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 Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
duration_
, String
"cover_frame_timestamp" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
cover_frame_timestamp_
, String
"is_animation" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_animation_
]
instance AT.FromJSON InputStoryContent where
parseJSON :: Value -> Parser InputStoryContent
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
"inputStoryContentPhoto" -> Value -> Parser InputStoryContent
parseInputStoryContentPhoto Value
v
String
"inputStoryContentVideo" -> Value -> Parser InputStoryContent
parseInputStoryContentVideo Value
v
String
_ -> Parser InputStoryContent
forall a. Monoid a => a
mempty
where
parseInputStoryContentPhoto :: A.Value -> AT.Parser InputStoryContent
parseInputStoryContentPhoto :: Value -> Parser InputStoryContent
parseInputStoryContentPhoto = String
-> (Object -> Parser InputStoryContent)
-> Value
-> Parser InputStoryContent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputStoryContentPhoto" ((Object -> Parser InputStoryContent)
-> Value -> Parser InputStoryContent)
-> (Object -> Parser InputStoryContent)
-> Value
-> Parser InputStoryContent
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputFile
photo_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
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"
InputStoryContent -> Parser InputStoryContent
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputStoryContent -> Parser InputStoryContent)
-> InputStoryContent -> Parser InputStoryContent
forall a b. (a -> b) -> a -> b
$ InputStoryContentPhoto
{ photo :: Maybe InputFile
photo = Maybe InputFile
photo_
, added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
}
parseInputStoryContentVideo :: A.Value -> AT.Parser InputStoryContent
parseInputStoryContentVideo :: Value -> Parser InputStoryContent
parseInputStoryContentVideo = String
-> (Object -> Parser InputStoryContent)
-> Value
-> Parser InputStoryContent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputStoryContentVideo" ((Object -> Parser InputStoryContent)
-> Value -> Parser InputStoryContent)
-> (Object -> Parser InputStoryContent)
-> Value
-> Parser InputStoryContent
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputFile
video_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"video"
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 Double
duration_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"duration"
Maybe Double
cover_frame_timestamp_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"cover_frame_timestamp"
Maybe Bool
is_animation_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_animation"
InputStoryContent -> Parser InputStoryContent
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputStoryContent -> Parser InputStoryContent)
-> InputStoryContent -> Parser InputStoryContent
forall a b. (a -> b) -> a -> b
$ InputStoryContentVideo
{ video :: Maybe InputFile
video = Maybe InputFile
video_
, added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, duration :: Maybe Double
duration = Maybe Double
duration_
, cover_frame_timestamp :: Maybe Double
cover_frame_timestamp = Maybe Double
cover_frame_timestamp_
, is_animation :: Maybe Bool
is_animation = Maybe Bool
is_animation_
}
parseJSON Value
_ = Parser InputStoryContent
forall a. Monoid a => a
mempty
instance AT.ToJSON InputStoryContent where
toJSON :: InputStoryContent -> Value
toJSON InputStoryContentPhoto
{ photo :: InputStoryContent -> Maybe InputFile
photo = Maybe InputFile
photo_
, added_sticker_file_ids :: InputStoryContent -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
}
= [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
"inputStoryContentPhoto"
, Key
"photo" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
photo_
, 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_
]
toJSON InputStoryContentVideo
{ video :: InputStoryContent -> Maybe InputFile
video = Maybe InputFile
video_
, added_sticker_file_ids :: InputStoryContent -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, duration :: InputStoryContent -> Maybe Double
duration = Maybe Double
duration_
, cover_frame_timestamp :: InputStoryContent -> Maybe Double
cover_frame_timestamp = Maybe Double
cover_frame_timestamp_
, is_animation :: InputStoryContent -> Maybe Bool
is_animation = Maybe Bool
is_animation_
}
= [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
"inputStoryContentVideo"
, Key
"video" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
video_
, 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 Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
duration_
, Key
"cover_frame_timestamp" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
cover_frame_timestamp_
, Key
"is_animation" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_animation_
]