module TD.Data.ChatMessageSender
(ChatMessageSender(..)) 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
data ChatMessageSender
= ChatMessageSender
{ ChatMessageSender -> Maybe MessageSender
sender :: Maybe MessageSender.MessageSender
, ChatMessageSender -> Maybe Bool
needs_premium :: Maybe Bool
}
deriving (ChatMessageSender -> ChatMessageSender -> Bool
(ChatMessageSender -> ChatMessageSender -> Bool)
-> (ChatMessageSender -> ChatMessageSender -> Bool)
-> Eq ChatMessageSender
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatMessageSender -> ChatMessageSender -> Bool
== :: ChatMessageSender -> ChatMessageSender -> Bool
$c/= :: ChatMessageSender -> ChatMessageSender -> Bool
/= :: ChatMessageSender -> ChatMessageSender -> Bool
Eq, Int -> ChatMessageSender -> ShowS
[ChatMessageSender] -> ShowS
ChatMessageSender -> String
(Int -> ChatMessageSender -> ShowS)
-> (ChatMessageSender -> String)
-> ([ChatMessageSender] -> ShowS)
-> Show ChatMessageSender
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatMessageSender -> ShowS
showsPrec :: Int -> ChatMessageSender -> ShowS
$cshow :: ChatMessageSender -> String
show :: ChatMessageSender -> String
$cshowList :: [ChatMessageSender] -> ShowS
showList :: [ChatMessageSender] -> ShowS
Show)
instance I.ShortShow ChatMessageSender where
shortShow :: ChatMessageSender -> String
shortShow ChatMessageSender
{ sender :: ChatMessageSender -> Maybe MessageSender
sender = Maybe MessageSender
sender_
, needs_premium :: ChatMessageSender -> Maybe Bool
needs_premium = Maybe Bool
needs_premium_
}
= String
"ChatMessageSender"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"sender" String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
sender_
, String
"needs_premium" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
needs_premium_
]
instance AT.FromJSON ChatMessageSender where
parseJSON :: Value -> Parser ChatMessageSender
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
"chatMessageSender" -> Value -> Parser ChatMessageSender
parseChatMessageSender Value
v
String
_ -> Parser ChatMessageSender
forall a. Monoid a => a
mempty
where
parseChatMessageSender :: A.Value -> AT.Parser ChatMessageSender
parseChatMessageSender :: Value -> Parser ChatMessageSender
parseChatMessageSender = String
-> (Object -> Parser ChatMessageSender)
-> Value
-> Parser ChatMessageSender
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatMessageSender" ((Object -> Parser ChatMessageSender)
-> Value -> Parser ChatMessageSender)
-> (Object -> Parser ChatMessageSender)
-> Value
-> Parser ChatMessageSender
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe MessageSender
sender_ <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sender"
Maybe Bool
needs_premium_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"needs_premium"
ChatMessageSender -> Parser ChatMessageSender
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatMessageSender -> Parser ChatMessageSender)
-> ChatMessageSender -> Parser ChatMessageSender
forall a b. (a -> b) -> a -> b
$ ChatMessageSender
{ sender :: Maybe MessageSender
sender = Maybe MessageSender
sender_
, needs_premium :: Maybe Bool
needs_premium = Maybe Bool
needs_premium_
}
parseJSON Value
_ = Parser ChatMessageSender
forall a. Monoid a => a
mempty