module TD.Data.UserSupportInfo
(UserSupportInfo(..)) 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.FormattedText as FormattedText
import qualified Data.Text as T
data UserSupportInfo
= UserSupportInfo
{ UserSupportInfo -> Maybe FormattedText
message :: Maybe FormattedText.FormattedText
, UserSupportInfo -> Maybe Text
author :: Maybe T.Text
, UserSupportInfo -> Maybe Int
date :: Maybe Int
}
deriving (UserSupportInfo -> UserSupportInfo -> Bool
(UserSupportInfo -> UserSupportInfo -> Bool)
-> (UserSupportInfo -> UserSupportInfo -> Bool)
-> Eq UserSupportInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserSupportInfo -> UserSupportInfo -> Bool
== :: UserSupportInfo -> UserSupportInfo -> Bool
$c/= :: UserSupportInfo -> UserSupportInfo -> Bool
/= :: UserSupportInfo -> UserSupportInfo -> Bool
Eq, Int -> UserSupportInfo -> ShowS
[UserSupportInfo] -> ShowS
UserSupportInfo -> String
(Int -> UserSupportInfo -> ShowS)
-> (UserSupportInfo -> String)
-> ([UserSupportInfo] -> ShowS)
-> Show UserSupportInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserSupportInfo -> ShowS
showsPrec :: Int -> UserSupportInfo -> ShowS
$cshow :: UserSupportInfo -> String
show :: UserSupportInfo -> String
$cshowList :: [UserSupportInfo] -> ShowS
showList :: [UserSupportInfo] -> ShowS
Show)
instance I.ShortShow UserSupportInfo where
shortShow :: UserSupportInfo -> String
shortShow UserSupportInfo
{ message :: UserSupportInfo -> Maybe FormattedText
message = Maybe FormattedText
message_
, author :: UserSupportInfo -> Maybe Text
author = Maybe Text
author_
, date :: UserSupportInfo -> Maybe Int
date = Maybe Int
date_
}
= String
"UserSupportInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"message" String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
message_
, String
"author" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
author_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
]
instance AT.FromJSON UserSupportInfo where
parseJSON :: Value -> Parser UserSupportInfo
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
"userSupportInfo" -> Value -> Parser UserSupportInfo
parseUserSupportInfo Value
v
String
_ -> Parser UserSupportInfo
forall a. Monoid a => a
mempty
where
parseUserSupportInfo :: A.Value -> AT.Parser UserSupportInfo
parseUserSupportInfo :: Value -> Parser UserSupportInfo
parseUserSupportInfo = String
-> (Object -> Parser UserSupportInfo)
-> Value
-> Parser UserSupportInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserSupportInfo" ((Object -> Parser UserSupportInfo)
-> Value -> Parser UserSupportInfo)
-> (Object -> Parser UserSupportInfo)
-> Value
-> Parser UserSupportInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe FormattedText
message_ <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message"
Maybe Text
author_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"author"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
UserSupportInfo -> Parser UserSupportInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserSupportInfo -> Parser UserSupportInfo)
-> UserSupportInfo -> Parser UserSupportInfo
forall a b. (a -> b) -> a -> b
$ UserSupportInfo
{ message :: Maybe FormattedText
message = Maybe FormattedText
message_
, author :: Maybe Text
author = Maybe Text
author_
, date :: Maybe Int
date = Maybe Int
date_
}
parseJSON Value
_ = Parser UserSupportInfo
forall a. Monoid a => a
mempty