module TD.Data.BasicGroup
(BasicGroup(..)) 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.ChatMemberStatus as ChatMemberStatus
data BasicGroup
= BasicGroup
{ BasicGroup -> Maybe Int
_id :: Maybe Int
, BasicGroup -> Maybe Int
member_count :: Maybe Int
, BasicGroup -> Maybe ChatMemberStatus
status :: Maybe ChatMemberStatus.ChatMemberStatus
, BasicGroup -> Maybe Bool
is_active :: Maybe Bool
, BasicGroup -> Maybe Int
upgraded_to_supergroup_id :: Maybe Int
}
deriving (BasicGroup -> BasicGroup -> Bool
(BasicGroup -> BasicGroup -> Bool)
-> (BasicGroup -> BasicGroup -> Bool) -> Eq BasicGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BasicGroup -> BasicGroup -> Bool
== :: BasicGroup -> BasicGroup -> Bool
$c/= :: BasicGroup -> BasicGroup -> Bool
/= :: BasicGroup -> BasicGroup -> Bool
Eq, Int -> BasicGroup -> ShowS
[BasicGroup] -> ShowS
BasicGroup -> String
(Int -> BasicGroup -> ShowS)
-> (BasicGroup -> String)
-> ([BasicGroup] -> ShowS)
-> Show BasicGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BasicGroup -> ShowS
showsPrec :: Int -> BasicGroup -> ShowS
$cshow :: BasicGroup -> String
show :: BasicGroup -> String
$cshowList :: [BasicGroup] -> ShowS
showList :: [BasicGroup] -> ShowS
Show)
instance I.ShortShow BasicGroup where
shortShow :: BasicGroup -> String
shortShow BasicGroup
{ _id :: BasicGroup -> Maybe Int
_id = Maybe Int
_id_
, member_count :: BasicGroup -> Maybe Int
member_count = Maybe Int
member_count_
, status :: BasicGroup -> Maybe ChatMemberStatus
status = Maybe ChatMemberStatus
status_
, is_active :: BasicGroup -> Maybe Bool
is_active = Maybe Bool
is_active_
, upgraded_to_supergroup_id :: BasicGroup -> Maybe Int
upgraded_to_supergroup_id = Maybe Int
upgraded_to_supergroup_id_
}
= String
"BasicGroup"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"member_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
member_count_
, String
"status" String -> Maybe ChatMemberStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatMemberStatus
status_
, String
"is_active" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_active_
, String
"upgraded_to_supergroup_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
upgraded_to_supergroup_id_
]
instance AT.FromJSON BasicGroup where
parseJSON :: Value -> Parser BasicGroup
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
"basicGroup" -> Value -> Parser BasicGroup
parseBasicGroup Value
v
String
_ -> Parser BasicGroup
forall a. Monoid a => a
mempty
where
parseBasicGroup :: A.Value -> AT.Parser BasicGroup
parseBasicGroup :: Value -> Parser BasicGroup
parseBasicGroup = String
-> (Object -> Parser BasicGroup) -> Value -> Parser BasicGroup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BasicGroup" ((Object -> Parser BasicGroup) -> Value -> Parser BasicGroup)
-> (Object -> Parser BasicGroup) -> Value -> Parser BasicGroup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Int
member_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"member_count"
Maybe ChatMemberStatus
status_ <- Object
o Object -> Key -> Parser (Maybe ChatMemberStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"status"
Maybe Bool
is_active_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_active"
Maybe Int
upgraded_to_supergroup_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"upgraded_to_supergroup_id"
BasicGroup -> Parser BasicGroup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BasicGroup -> Parser BasicGroup)
-> BasicGroup -> Parser BasicGroup
forall a b. (a -> b) -> a -> b
$ BasicGroup
{ _id :: Maybe Int
_id = Maybe Int
_id_
, member_count :: Maybe Int
member_count = Maybe Int
member_count_
, status :: Maybe ChatMemberStatus
status = Maybe ChatMemberStatus
status_
, is_active :: Maybe Bool
is_active = Maybe Bool
is_active_
, upgraded_to_supergroup_id :: Maybe Int
upgraded_to_supergroup_id = Maybe Int
upgraded_to_supergroup_id_
}
parseJSON Value
_ = Parser BasicGroup
forall a. Monoid a => a
mempty