module TD.Data.ChatMember
(ChatMember(..)) 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.MessageSender as MessageSender
import qualified TD.Data.ChatMemberStatus as ChatMemberStatus
data ChatMember
= ChatMember
{ ChatMember -> Maybe MessageSender
member_id :: Maybe MessageSender.MessageSender
, ChatMember -> Maybe Int
inviter_user_id :: Maybe Int
, ChatMember -> Maybe Int
joined_chat_date :: Maybe Int
, ChatMember -> Maybe ChatMemberStatus
status :: Maybe ChatMemberStatus.ChatMemberStatus
}
deriving (ChatMember -> ChatMember -> Bool
(ChatMember -> ChatMember -> Bool)
-> (ChatMember -> ChatMember -> Bool) -> Eq ChatMember
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatMember -> ChatMember -> Bool
== :: ChatMember -> ChatMember -> Bool
$c/= :: ChatMember -> ChatMember -> Bool
/= :: ChatMember -> ChatMember -> Bool
Eq, Int -> ChatMember -> ShowS
[ChatMember] -> ShowS
ChatMember -> String
(Int -> ChatMember -> ShowS)
-> (ChatMember -> String)
-> ([ChatMember] -> ShowS)
-> Show ChatMember
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatMember -> ShowS
showsPrec :: Int -> ChatMember -> ShowS
$cshow :: ChatMember -> String
show :: ChatMember -> String
$cshowList :: [ChatMember] -> ShowS
showList :: [ChatMember] -> ShowS
Show)
instance I.ShortShow ChatMember where
shortShow :: ChatMember -> String
shortShow ChatMember
{ member_id :: ChatMember -> Maybe MessageSender
member_id = Maybe MessageSender
member_id_
, inviter_user_id :: ChatMember -> Maybe Int
inviter_user_id = Maybe Int
inviter_user_id_
, joined_chat_date :: ChatMember -> Maybe Int
joined_chat_date = Maybe Int
joined_chat_date_
, status :: ChatMember -> Maybe ChatMemberStatus
status = Maybe ChatMemberStatus
status_
}
= String
"ChatMember"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"member_id" String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
member_id_
, String
"inviter_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
inviter_user_id_
, String
"joined_chat_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
joined_chat_date_
, String
"status" String -> Maybe ChatMemberStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatMemberStatus
status_
]
instance AT.FromJSON ChatMember where
parseJSON :: Value -> Parser ChatMember
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
"chatMember" -> Value -> Parser ChatMember
parseChatMember Value
v
String
_ -> Parser ChatMember
forall a. Monoid a => a
mempty
where
parseChatMember :: A.Value -> AT.Parser ChatMember
parseChatMember :: Value -> Parser ChatMember
parseChatMember = String
-> (Object -> Parser ChatMember) -> Value -> Parser ChatMember
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatMember" ((Object -> Parser ChatMember) -> Value -> Parser ChatMember)
-> (Object -> Parser ChatMember) -> Value -> Parser ChatMember
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe MessageSender
member_id_ <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"member_id"
Maybe Int
inviter_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"inviter_user_id"
Maybe Int
joined_chat_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"joined_chat_date"
Maybe ChatMemberStatus
status_ <- Object
o Object -> Key -> Parser (Maybe ChatMemberStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"status"
ChatMember -> Parser ChatMember
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatMember -> Parser ChatMember)
-> ChatMember -> Parser ChatMember
forall a b. (a -> b) -> a -> b
$ ChatMember
{ member_id :: Maybe MessageSender
member_id = Maybe MessageSender
member_id_
, inviter_user_id :: Maybe Int
inviter_user_id = Maybe Int
inviter_user_id_
, joined_chat_date :: Maybe Int
joined_chat_date = Maybe Int
joined_chat_date_
, status :: Maybe ChatMemberStatus
status = Maybe ChatMemberStatus
status_
}
parseJSON Value
_ = Parser ChatMember
forall a. Monoid a => a
mempty