module TD.Data.ChatPhoto
(ChatPhoto(..)) 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.Minithumbnail as Minithumbnail
import qualified TD.Data.PhotoSize as PhotoSize
import qualified TD.Data.AnimatedChatPhoto as AnimatedChatPhoto
import qualified TD.Data.ChatPhotoSticker as ChatPhotoSticker
data ChatPhoto
= ChatPhoto
{ ChatPhoto -> Maybe Int
_id :: Maybe Int
, ChatPhoto -> Maybe Int
added_date :: Maybe Int
, ChatPhoto -> Maybe Minithumbnail
minithumbnail :: Maybe Minithumbnail.Minithumbnail
, ChatPhoto -> Maybe [PhotoSize]
sizes :: Maybe [PhotoSize.PhotoSize]
, ChatPhoto -> Maybe AnimatedChatPhoto
animation :: Maybe AnimatedChatPhoto.AnimatedChatPhoto
, ChatPhoto -> Maybe AnimatedChatPhoto
small_animation :: Maybe AnimatedChatPhoto.AnimatedChatPhoto
, ChatPhoto -> Maybe ChatPhotoSticker
sticker :: Maybe ChatPhotoSticker.ChatPhotoSticker
}
deriving (ChatPhoto -> ChatPhoto -> Bool
(ChatPhoto -> ChatPhoto -> Bool)
-> (ChatPhoto -> ChatPhoto -> Bool) -> Eq ChatPhoto
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatPhoto -> ChatPhoto -> Bool
== :: ChatPhoto -> ChatPhoto -> Bool
$c/= :: ChatPhoto -> ChatPhoto -> Bool
/= :: ChatPhoto -> ChatPhoto -> Bool
Eq, Int -> ChatPhoto -> ShowS
[ChatPhoto] -> ShowS
ChatPhoto -> String
(Int -> ChatPhoto -> ShowS)
-> (ChatPhoto -> String)
-> ([ChatPhoto] -> ShowS)
-> Show ChatPhoto
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatPhoto -> ShowS
showsPrec :: Int -> ChatPhoto -> ShowS
$cshow :: ChatPhoto -> String
show :: ChatPhoto -> String
$cshowList :: [ChatPhoto] -> ShowS
showList :: [ChatPhoto] -> ShowS
Show)
instance I.ShortShow ChatPhoto where
shortShow :: ChatPhoto -> String
shortShow ChatPhoto
{ _id :: ChatPhoto -> Maybe Int
_id = Maybe Int
_id_
, added_date :: ChatPhoto -> Maybe Int
added_date = Maybe Int
added_date_
, minithumbnail :: ChatPhoto -> Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
, sizes :: ChatPhoto -> Maybe [PhotoSize]
sizes = Maybe [PhotoSize]
sizes_
, animation :: ChatPhoto -> Maybe AnimatedChatPhoto
animation = Maybe AnimatedChatPhoto
animation_
, small_animation :: ChatPhoto -> Maybe AnimatedChatPhoto
small_animation = Maybe AnimatedChatPhoto
small_animation_
, sticker :: ChatPhoto -> Maybe ChatPhotoSticker
sticker = Maybe ChatPhotoSticker
sticker_
}
= String
"ChatPhoto"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"added_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
added_date_
, String
"minithumbnail" String -> Maybe Minithumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Minithumbnail
minithumbnail_
, String
"sizes" String -> Maybe [PhotoSize] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [PhotoSize]
sizes_
, String
"animation" String -> Maybe AnimatedChatPhoto -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AnimatedChatPhoto
animation_
, String
"small_animation" String -> Maybe AnimatedChatPhoto -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AnimatedChatPhoto
small_animation_
, String
"sticker" String -> Maybe ChatPhotoSticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatPhotoSticker
sticker_
]
instance AT.FromJSON ChatPhoto where
parseJSON :: Value -> Parser ChatPhoto
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
"chatPhoto" -> Value -> Parser ChatPhoto
parseChatPhoto Value
v
String
_ -> Parser ChatPhoto
forall a. Monoid a => a
mempty
where
parseChatPhoto :: A.Value -> AT.Parser ChatPhoto
parseChatPhoto :: Value -> Parser ChatPhoto
parseChatPhoto = String -> (Object -> Parser ChatPhoto) -> Value -> Parser ChatPhoto
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatPhoto" ((Object -> Parser ChatPhoto) -> Value -> Parser ChatPhoto)
-> (Object -> Parser ChatPhoto) -> Value -> Parser ChatPhoto
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_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
"id"
Maybe Int
added_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"added_date"
Maybe Minithumbnail
minithumbnail_ <- Object
o Object -> Key -> Parser (Maybe Minithumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"minithumbnail"
Maybe [PhotoSize]
sizes_ <- Object
o Object -> Key -> Parser (Maybe [PhotoSize])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sizes"
Maybe AnimatedChatPhoto
animation_ <- Object
o Object -> Key -> Parser (Maybe AnimatedChatPhoto)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"animation"
Maybe AnimatedChatPhoto
small_animation_ <- Object
o Object -> Key -> Parser (Maybe AnimatedChatPhoto)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"small_animation"
Maybe ChatPhotoSticker
sticker_ <- Object
o Object -> Key -> Parser (Maybe ChatPhotoSticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sticker"
ChatPhoto -> Parser ChatPhoto
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatPhoto -> Parser ChatPhoto) -> ChatPhoto -> Parser ChatPhoto
forall a b. (a -> b) -> a -> b
$ ChatPhoto
{ _id :: Maybe Int
_id = Maybe Int
_id_
, added_date :: Maybe Int
added_date = Maybe Int
added_date_
, minithumbnail :: Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
, sizes :: Maybe [PhotoSize]
sizes = Maybe [PhotoSize]
sizes_
, animation :: Maybe AnimatedChatPhoto
animation = Maybe AnimatedChatPhoto
animation_
, small_animation :: Maybe AnimatedChatPhoto
small_animation = Maybe AnimatedChatPhoto
small_animation_
, sticker :: Maybe ChatPhotoSticker
sticker = Maybe ChatPhotoSticker
sticker_
}
parseJSON Value
_ = Parser ChatPhoto
forall a. Monoid a => a
mempty