module TD.Data.MessageLinkInfo
(MessageLinkInfo(..)) 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.Message as Message
data MessageLinkInfo
= MessageLinkInfo
{ MessageLinkInfo -> Maybe Bool
is_public :: Maybe Bool
, MessageLinkInfo -> Maybe Int
chat_id :: Maybe Int
, MessageLinkInfo -> Maybe Int
message_thread_id :: Maybe Int
, MessageLinkInfo -> Maybe Message
message :: Maybe Message.Message
, MessageLinkInfo -> Maybe Int
media_timestamp :: Maybe Int
, MessageLinkInfo -> Maybe Bool
for_album :: Maybe Bool
}
deriving (MessageLinkInfo -> MessageLinkInfo -> Bool
(MessageLinkInfo -> MessageLinkInfo -> Bool)
-> (MessageLinkInfo -> MessageLinkInfo -> Bool)
-> Eq MessageLinkInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageLinkInfo -> MessageLinkInfo -> Bool
== :: MessageLinkInfo -> MessageLinkInfo -> Bool
$c/= :: MessageLinkInfo -> MessageLinkInfo -> Bool
/= :: MessageLinkInfo -> MessageLinkInfo -> Bool
Eq, Int -> MessageLinkInfo -> ShowS
[MessageLinkInfo] -> ShowS
MessageLinkInfo -> String
(Int -> MessageLinkInfo -> ShowS)
-> (MessageLinkInfo -> String)
-> ([MessageLinkInfo] -> ShowS)
-> Show MessageLinkInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageLinkInfo -> ShowS
showsPrec :: Int -> MessageLinkInfo -> ShowS
$cshow :: MessageLinkInfo -> String
show :: MessageLinkInfo -> String
$cshowList :: [MessageLinkInfo] -> ShowS
showList :: [MessageLinkInfo] -> ShowS
Show)
instance I.ShortShow MessageLinkInfo where
shortShow :: MessageLinkInfo -> String
shortShow MessageLinkInfo
{ is_public :: MessageLinkInfo -> Maybe Bool
is_public = Maybe Bool
is_public_
, chat_id :: MessageLinkInfo -> Maybe Int
chat_id = Maybe Int
chat_id_
, message_thread_id :: MessageLinkInfo -> Maybe Int
message_thread_id = Maybe Int
message_thread_id_
, message :: MessageLinkInfo -> Maybe Message
message = Maybe Message
message_
, media_timestamp :: MessageLinkInfo -> Maybe Int
media_timestamp = Maybe Int
media_timestamp_
, for_album :: MessageLinkInfo -> Maybe Bool
for_album = Maybe Bool
for_album_
}
= String
"MessageLinkInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"is_public" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_public_
, String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
, String
"message_thread_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_thread_id_
, String
"message" String -> Maybe Message -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Message
message_
, String
"media_timestamp" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
media_timestamp_
, String
"for_album" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
for_album_
]
instance AT.FromJSON MessageLinkInfo where
parseJSON :: Value -> Parser MessageLinkInfo
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
"messageLinkInfo" -> Value -> Parser MessageLinkInfo
parseMessageLinkInfo Value
v
String
_ -> Parser MessageLinkInfo
forall a. Monoid a => a
mempty
where
parseMessageLinkInfo :: A.Value -> AT.Parser MessageLinkInfo
parseMessageLinkInfo :: Value -> Parser MessageLinkInfo
parseMessageLinkInfo = String
-> (Object -> Parser MessageLinkInfo)
-> Value
-> Parser MessageLinkInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageLinkInfo" ((Object -> Parser MessageLinkInfo)
-> Value -> Parser MessageLinkInfo)
-> (Object -> Parser MessageLinkInfo)
-> Value
-> Parser MessageLinkInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
is_public_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_public"
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
Maybe Int
message_thread_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message_thread_id"
Maybe Message
message_ <- Object
o Object -> Key -> Parser (Maybe Message)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message"
Maybe Int
media_timestamp_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"media_timestamp"
Maybe Bool
for_album_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"for_album"
MessageLinkInfo -> Parser MessageLinkInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageLinkInfo -> Parser MessageLinkInfo)
-> MessageLinkInfo -> Parser MessageLinkInfo
forall a b. (a -> b) -> a -> b
$ MessageLinkInfo
{ is_public :: Maybe Bool
is_public = Maybe Bool
is_public_
, chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
, message_thread_id :: Maybe Int
message_thread_id = Maybe Int
message_thread_id_
, message :: Maybe Message
message = Maybe Message
message_
, media_timestamp :: Maybe Int
media_timestamp = Maybe Int
media_timestamp_
, for_album :: Maybe Bool
for_album = Maybe Bool
for_album_
}
parseJSON Value
_ = Parser MessageLinkInfo
forall a. Monoid a => a
mempty