module TD.Data.ChatJoinRequest
( ChatJoinRequest(..)
, defaultChatJoinRequest
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data ChatJoinRequest
= ChatJoinRequest
{ ChatJoinRequest -> Maybe Int
user_id :: Maybe Int
, ChatJoinRequest -> Maybe Int
date :: Maybe Int
, ChatJoinRequest -> Maybe Text
bio :: Maybe T.Text
}
deriving (ChatJoinRequest -> ChatJoinRequest -> Bool
(ChatJoinRequest -> ChatJoinRequest -> Bool)
-> (ChatJoinRequest -> ChatJoinRequest -> Bool)
-> Eq ChatJoinRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatJoinRequest -> ChatJoinRequest -> Bool
== :: ChatJoinRequest -> ChatJoinRequest -> Bool
$c/= :: ChatJoinRequest -> ChatJoinRequest -> Bool
/= :: ChatJoinRequest -> ChatJoinRequest -> Bool
Eq, Int -> ChatJoinRequest -> ShowS
[ChatJoinRequest] -> ShowS
ChatJoinRequest -> String
(Int -> ChatJoinRequest -> ShowS)
-> (ChatJoinRequest -> String)
-> ([ChatJoinRequest] -> ShowS)
-> Show ChatJoinRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatJoinRequest -> ShowS
showsPrec :: Int -> ChatJoinRequest -> ShowS
$cshow :: ChatJoinRequest -> String
show :: ChatJoinRequest -> String
$cshowList :: [ChatJoinRequest] -> ShowS
showList :: [ChatJoinRequest] -> ShowS
Show)
instance I.ShortShow ChatJoinRequest where
shortShow :: ChatJoinRequest -> String
shortShow ChatJoinRequest
{ user_id :: ChatJoinRequest -> Maybe Int
user_id = Maybe Int
user_id_
, date :: ChatJoinRequest -> Maybe Int
date = Maybe Int
date_
, bio :: ChatJoinRequest -> Maybe Text
bio = Maybe Text
bio_
}
= String
"ChatJoinRequest"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
, String
"bio" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
bio_
]
instance AT.FromJSON ChatJoinRequest where
parseJSON :: Value -> Parser ChatJoinRequest
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
"chatJoinRequest" -> Value -> Parser ChatJoinRequest
parseChatJoinRequest Value
v
String
_ -> Parser ChatJoinRequest
forall a. Monoid a => a
mempty
where
parseChatJoinRequest :: A.Value -> AT.Parser ChatJoinRequest
parseChatJoinRequest :: Value -> Parser ChatJoinRequest
parseChatJoinRequest = String
-> (Object -> Parser ChatJoinRequest)
-> Value
-> Parser ChatJoinRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatJoinRequest" ((Object -> Parser ChatJoinRequest)
-> Value -> Parser ChatJoinRequest)
-> (Object -> Parser ChatJoinRequest)
-> Value
-> Parser ChatJoinRequest
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
Maybe Text
bio_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"bio"
ChatJoinRequest -> Parser ChatJoinRequest
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatJoinRequest -> Parser ChatJoinRequest)
-> ChatJoinRequest -> Parser ChatJoinRequest
forall a b. (a -> b) -> a -> b
$ ChatJoinRequest
{ user_id :: Maybe Int
user_id = Maybe Int
user_id_
, date :: Maybe Int
date = Maybe Int
date_
, bio :: Maybe Text
bio = Maybe Text
bio_
}
parseJSON Value
_ = Parser ChatJoinRequest
forall a. Monoid a => a
mempty
instance AT.ToJSON ChatJoinRequest where
toJSON :: ChatJoinRequest -> Value
toJSON ChatJoinRequest
{ user_id :: ChatJoinRequest -> Maybe Int
user_id = Maybe Int
user_id_
, date :: ChatJoinRequest -> Maybe Int
date = Maybe Int
date_
, bio :: ChatJoinRequest -> Maybe Text
bio = Maybe Text
bio_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatJoinRequest"
, Key
"user_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
user_id_
, Key
"date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
date_
, Key
"bio" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
bio_
]
defaultChatJoinRequest :: ChatJoinRequest
defaultChatJoinRequest :: ChatJoinRequest
defaultChatJoinRequest =
ChatJoinRequest
{ user_id :: Maybe Int
user_id = Maybe Int
forall a. Maybe a
Nothing
, date :: Maybe Int
date = Maybe Int
forall a. Maybe a
Nothing
, bio :: Maybe Text
bio = Maybe Text
forall a. Maybe a
Nothing
}