module TD.Data.InputChatPhoto
(InputChatPhoto(..)) 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.ChatPhotoSticker as ChatPhotoSticker
data InputChatPhoto
= InputChatPhotoPrevious
{ InputChatPhoto -> Maybe Int
chat_photo_id :: Maybe Int
}
| InputChatPhotoStatic
{ InputChatPhoto -> Maybe InputFile
photo :: Maybe InputFile.InputFile
}
| InputChatPhotoAnimation
{ InputChatPhoto -> Maybe InputFile
animation :: Maybe InputFile.InputFile
, InputChatPhoto -> Maybe Double
main_frame_timestamp :: Maybe Double
}
| InputChatPhotoSticker
{ InputChatPhoto -> Maybe ChatPhotoSticker
sticker :: Maybe ChatPhotoSticker.ChatPhotoSticker
}
deriving (InputChatPhoto -> InputChatPhoto -> Bool
(InputChatPhoto -> InputChatPhoto -> Bool)
-> (InputChatPhoto -> InputChatPhoto -> Bool) -> Eq InputChatPhoto
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputChatPhoto -> InputChatPhoto -> Bool
== :: InputChatPhoto -> InputChatPhoto -> Bool
$c/= :: InputChatPhoto -> InputChatPhoto -> Bool
/= :: InputChatPhoto -> InputChatPhoto -> Bool
Eq, Int -> InputChatPhoto -> ShowS
[InputChatPhoto] -> ShowS
InputChatPhoto -> String
(Int -> InputChatPhoto -> ShowS)
-> (InputChatPhoto -> String)
-> ([InputChatPhoto] -> ShowS)
-> Show InputChatPhoto
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputChatPhoto -> ShowS
showsPrec :: Int -> InputChatPhoto -> ShowS
$cshow :: InputChatPhoto -> String
show :: InputChatPhoto -> String
$cshowList :: [InputChatPhoto] -> ShowS
showList :: [InputChatPhoto] -> ShowS
Show)
instance I.ShortShow InputChatPhoto where
shortShow :: InputChatPhoto -> String
shortShow InputChatPhotoPrevious
{ chat_photo_id :: InputChatPhoto -> Maybe Int
chat_photo_id = Maybe Int
chat_photo_id_
}
= String
"InputChatPhotoPrevious"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_photo_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_photo_id_
]
shortShow InputChatPhotoStatic
{ photo :: InputChatPhoto -> Maybe InputFile
photo = Maybe InputFile
photo_
}
= String
"InputChatPhotoStatic"
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_
]
shortShow InputChatPhotoAnimation
{ animation :: InputChatPhoto -> Maybe InputFile
animation = Maybe InputFile
animation_
, main_frame_timestamp :: InputChatPhoto -> Maybe Double
main_frame_timestamp = Maybe Double
main_frame_timestamp_
}
= String
"InputChatPhotoAnimation"
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
"main_frame_timestamp" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
main_frame_timestamp_
]
shortShow InputChatPhotoSticker
{ sticker :: InputChatPhoto -> Maybe ChatPhotoSticker
sticker = Maybe ChatPhotoSticker
sticker_
}
= String
"InputChatPhotoSticker"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"sticker" String -> Maybe ChatPhotoSticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatPhotoSticker
sticker_
]
instance AT.FromJSON InputChatPhoto where
parseJSON :: Value -> Parser InputChatPhoto
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
"inputChatPhotoPrevious" -> Value -> Parser InputChatPhoto
parseInputChatPhotoPrevious Value
v
String
"inputChatPhotoStatic" -> Value -> Parser InputChatPhoto
parseInputChatPhotoStatic Value
v
String
"inputChatPhotoAnimation" -> Value -> Parser InputChatPhoto
parseInputChatPhotoAnimation Value
v
String
"inputChatPhotoSticker" -> Value -> Parser InputChatPhoto
parseInputChatPhotoSticker Value
v
String
_ -> Parser InputChatPhoto
forall a. Monoid a => a
mempty
where
parseInputChatPhotoPrevious :: A.Value -> AT.Parser InputChatPhoto
parseInputChatPhotoPrevious :: Value -> Parser InputChatPhoto
parseInputChatPhotoPrevious = String
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChatPhotoPrevious" ((Object -> Parser InputChatPhoto)
-> Value -> Parser InputChatPhoto)
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
chat_photo_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_photo_id"
InputChatPhoto -> Parser InputChatPhoto
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChatPhoto -> Parser InputChatPhoto)
-> InputChatPhoto -> Parser InputChatPhoto
forall a b. (a -> b) -> a -> b
$ InputChatPhotoPrevious
{ chat_photo_id :: Maybe Int
chat_photo_id = Maybe Int
chat_photo_id_
}
parseInputChatPhotoStatic :: A.Value -> AT.Parser InputChatPhoto
parseInputChatPhotoStatic :: Value -> Parser InputChatPhoto
parseInputChatPhotoStatic = String
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChatPhotoStatic" ((Object -> Parser InputChatPhoto)
-> Value -> Parser InputChatPhoto)
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
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"
InputChatPhoto -> Parser InputChatPhoto
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChatPhoto -> Parser InputChatPhoto)
-> InputChatPhoto -> Parser InputChatPhoto
forall a b. (a -> b) -> a -> b
$ InputChatPhotoStatic
{ photo :: Maybe InputFile
photo = Maybe InputFile
photo_
}
parseInputChatPhotoAnimation :: A.Value -> AT.Parser InputChatPhoto
parseInputChatPhotoAnimation :: Value -> Parser InputChatPhoto
parseInputChatPhotoAnimation = String
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChatPhotoAnimation" ((Object -> Parser InputChatPhoto)
-> Value -> Parser InputChatPhoto)
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
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 Double
main_frame_timestamp_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"main_frame_timestamp"
InputChatPhoto -> Parser InputChatPhoto
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChatPhoto -> Parser InputChatPhoto)
-> InputChatPhoto -> Parser InputChatPhoto
forall a b. (a -> b) -> a -> b
$ InputChatPhotoAnimation
{ animation :: Maybe InputFile
animation = Maybe InputFile
animation_
, main_frame_timestamp :: Maybe Double
main_frame_timestamp = Maybe Double
main_frame_timestamp_
}
parseInputChatPhotoSticker :: A.Value -> AT.Parser InputChatPhoto
parseInputChatPhotoSticker :: Value -> Parser InputChatPhoto
parseInputChatPhotoSticker = String
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChatPhotoSticker" ((Object -> Parser InputChatPhoto)
-> Value -> Parser InputChatPhoto)
-> (Object -> Parser InputChatPhoto)
-> Value
-> Parser InputChatPhoto
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ChatPhotoSticker
sticker_ <- Object
o Object -> Key -> Parser (Maybe ChatPhotoSticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sticker"
InputChatPhoto -> Parser InputChatPhoto
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChatPhoto -> Parser InputChatPhoto)
-> InputChatPhoto -> Parser InputChatPhoto
forall a b. (a -> b) -> a -> b
$ InputChatPhotoSticker
{ sticker :: Maybe ChatPhotoSticker
sticker = Maybe ChatPhotoSticker
sticker_
}
parseJSON Value
_ = Parser InputChatPhoto
forall a. Monoid a => a
mempty
instance AT.ToJSON InputChatPhoto where
toJSON :: InputChatPhoto -> Value
toJSON InputChatPhotoPrevious
{ chat_photo_id :: InputChatPhoto -> Maybe Int
chat_photo_id = Maybe Int
chat_photo_id_
}
= [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
"inputChatPhotoPrevious"
, Key
"chat_photo_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64 Maybe Int
chat_photo_id_
]
toJSON InputChatPhotoStatic
{ photo :: InputChatPhoto -> Maybe InputFile
photo = Maybe InputFile
photo_
}
= [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
"inputChatPhotoStatic"
, 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_
]
toJSON InputChatPhotoAnimation
{ animation :: InputChatPhoto -> Maybe InputFile
animation = Maybe InputFile
animation_
, main_frame_timestamp :: InputChatPhoto -> Maybe Double
main_frame_timestamp = Maybe Double
main_frame_timestamp_
}
= [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
"inputChatPhotoAnimation"
, 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
"main_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
main_frame_timestamp_
]
toJSON InputChatPhotoSticker
{ sticker :: InputChatPhoto -> Maybe ChatPhotoSticker
sticker = Maybe ChatPhotoSticker
sticker_
}
= [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
"inputChatPhotoSticker"
, Key
"sticker" Key -> Maybe ChatPhotoSticker -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ChatPhotoSticker
sticker_
]