module TD.Data.UserType
(UserType(..)) 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 UserType
= UserTypeRegular
| UserTypeDeleted
| UserTypeBot
{ UserType -> Maybe Bool
can_be_edited :: Maybe Bool
, UserType -> Maybe Bool
can_join_groups :: Maybe Bool
, UserType -> Maybe Bool
can_read_all_group_messages :: Maybe Bool
, UserType -> Maybe Bool
has_main_web_app :: Maybe Bool
, UserType -> Maybe Bool
is_inline :: Maybe Bool
, UserType -> Maybe Text
inline_query_placeholder :: Maybe T.Text
, UserType -> Maybe Bool
need_location :: Maybe Bool
, UserType -> Maybe Bool
can_connect_to_business :: Maybe Bool
, :: Maybe Bool
, UserType -> Maybe Int
active_user_count :: Maybe Int
}
| UserTypeUnknown
deriving (UserType -> UserType -> Bool
(UserType -> UserType -> Bool)
-> (UserType -> UserType -> Bool) -> Eq UserType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserType -> UserType -> Bool
== :: UserType -> UserType -> Bool
$c/= :: UserType -> UserType -> Bool
/= :: UserType -> UserType -> Bool
Eq, Int -> UserType -> ShowS
[UserType] -> ShowS
UserType -> String
(Int -> UserType -> ShowS)
-> (UserType -> String) -> ([UserType] -> ShowS) -> Show UserType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserType -> ShowS
showsPrec :: Int -> UserType -> ShowS
$cshow :: UserType -> String
show :: UserType -> String
$cshowList :: [UserType] -> ShowS
showList :: [UserType] -> ShowS
Show)
instance I.ShortShow UserType where
shortShow :: UserType -> String
shortShow UserType
UserTypeRegular
= String
"UserTypeRegular"
shortShow UserType
UserTypeDeleted
= String
"UserTypeDeleted"
shortShow UserTypeBot
{ can_be_edited :: UserType -> Maybe Bool
can_be_edited = Maybe Bool
can_be_edited_
, can_join_groups :: UserType -> Maybe Bool
can_join_groups = Maybe Bool
can_join_groups_
, can_read_all_group_messages :: UserType -> Maybe Bool
can_read_all_group_messages = Maybe Bool
can_read_all_group_messages_
, has_main_web_app :: UserType -> Maybe Bool
has_main_web_app = Maybe Bool
has_main_web_app_
, is_inline :: UserType -> Maybe Bool
is_inline = Maybe Bool
is_inline_
, inline_query_placeholder :: UserType -> Maybe Text
inline_query_placeholder = Maybe Text
inline_query_placeholder_
, need_location :: UserType -> Maybe Bool
need_location = Maybe Bool
need_location_
, can_connect_to_business :: UserType -> Maybe Bool
can_connect_to_business = Maybe Bool
can_connect_to_business_
, can_be_added_to_attachment_menu :: UserType -> Maybe Bool
can_be_added_to_attachment_menu = Maybe Bool
can_be_added_to_attachment_menu_
, active_user_count :: UserType -> Maybe Int
active_user_count = Maybe Int
active_user_count_
}
= String
"UserTypeBot"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"can_be_edited" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_edited_
, String
"can_join_groups" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_join_groups_
, String
"can_read_all_group_messages" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_read_all_group_messages_
, String
"has_main_web_app" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_main_web_app_
, String
"is_inline" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_inline_
, String
"inline_query_placeholder" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
inline_query_placeholder_
, String
"need_location" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
need_location_
, String
"can_connect_to_business" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_connect_to_business_
, String
"can_be_added_to_attachment_menu" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_added_to_attachment_menu_
, String
"active_user_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
active_user_count_
]
shortShow UserType
UserTypeUnknown
= String
"UserTypeUnknown"
instance AT.FromJSON UserType where
parseJSON :: Value -> Parser UserType
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
"userTypeRegular" -> UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserType
UserTypeRegular
String
"userTypeDeleted" -> UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserType
UserTypeDeleted
String
"userTypeBot" -> Value -> Parser UserType
parseUserTypeBot Value
v
String
"userTypeUnknown" -> UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserType
UserTypeUnknown
String
_ -> Parser UserType
forall a. Monoid a => a
mempty
where
parseUserTypeBot :: A.Value -> AT.Parser UserType
parseUserTypeBot :: Value -> Parser UserType
parseUserTypeBot = String -> (Object -> Parser UserType) -> Value -> Parser UserType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserTypeBot" ((Object -> Parser UserType) -> Value -> Parser UserType)
-> (Object -> Parser UserType) -> Value -> Parser UserType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
can_be_edited_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_be_edited"
Maybe Bool
can_join_groups_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_join_groups"
Maybe Bool
can_read_all_group_messages_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_read_all_group_messages"
Maybe Bool
has_main_web_app_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_main_web_app"
Maybe Bool
is_inline_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_inline"
Maybe Text
inline_query_placeholder_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"inline_query_placeholder"
Maybe Bool
need_location_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"need_location"
Maybe Bool
can_connect_to_business_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_connect_to_business"
Maybe Bool
can_be_added_to_attachment_menu_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_be_added_to_attachment_menu"
Maybe Int
active_user_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"active_user_count"
UserType -> Parser UserType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserType -> Parser UserType) -> UserType -> Parser UserType
forall a b. (a -> b) -> a -> b
$ UserTypeBot
{ can_be_edited :: Maybe Bool
can_be_edited = Maybe Bool
can_be_edited_
, can_join_groups :: Maybe Bool
can_join_groups = Maybe Bool
can_join_groups_
, can_read_all_group_messages :: Maybe Bool
can_read_all_group_messages = Maybe Bool
can_read_all_group_messages_
, has_main_web_app :: Maybe Bool
has_main_web_app = Maybe Bool
has_main_web_app_
, is_inline :: Maybe Bool
is_inline = Maybe Bool
is_inline_
, inline_query_placeholder :: Maybe Text
inline_query_placeholder = Maybe Text
inline_query_placeholder_
, need_location :: Maybe Bool
need_location = Maybe Bool
need_location_
, can_connect_to_business :: Maybe Bool
can_connect_to_business = Maybe Bool
can_connect_to_business_
, can_be_added_to_attachment_menu :: Maybe Bool
can_be_added_to_attachment_menu = Maybe Bool
can_be_added_to_attachment_menu_
, active_user_count :: Maybe Int
active_user_count = Maybe Int
active_user_count_
}
parseJSON Value
_ = Parser UserType
forall a. Monoid a => a
mempty