module TD.Data.Community
(Community(..)) 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
import qualified TD.Data.ChatPhotoInfo as ChatPhotoInfo
import qualified TD.Data.CommunityMemberStatus as CommunityMemberStatus
import qualified TD.Data.CommunityPermissions as CommunityPermissions
data
=
{ Community -> Maybe Int
_id :: Maybe Int
, Community -> Maybe Bool
have_access :: Maybe Bool
, Community -> Maybe Text
name :: Maybe T.Text
, Community -> Maybe ChatPhotoInfo
photo :: Maybe ChatPhotoInfo.ChatPhotoInfo
, Community -> Maybe Int
date :: Maybe Int
, Community -> Maybe CommunityMemberStatus
status :: Maybe CommunityMemberStatus.CommunityMemberStatus
, Community -> Maybe CommunityPermissions
permissions :: Maybe CommunityPermissions.CommunityPermissions
}
deriving (Community -> Community -> Bool
(Community -> Community -> Bool)
-> (Community -> Community -> Bool) -> Eq Community
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Community -> Community -> Bool
== :: Community -> Community -> Bool
$c/= :: Community -> Community -> Bool
/= :: Community -> Community -> Bool
Eq, Int -> Community -> ShowS
[Community] -> ShowS
Community -> String
(Int -> Community -> ShowS)
-> (Community -> String)
-> ([Community] -> ShowS)
-> Show Community
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Community -> ShowS
showsPrec :: Int -> Community -> ShowS
$cshow :: Community -> String
show :: Community -> String
$cshowList :: [Community] -> ShowS
showList :: [Community] -> ShowS
Show)
instance I.ShortShow Community where
shortShow :: Community -> String
shortShow Community
{ _id :: Community -> Maybe Int
_id = Maybe Int
_id_
, have_access :: Community -> Maybe Bool
have_access = Maybe Bool
have_access_
, name :: Community -> Maybe Text
name = Maybe Text
name_
, photo :: Community -> Maybe ChatPhotoInfo
photo = Maybe ChatPhotoInfo
photo_
, date :: Community -> Maybe Int
date = Maybe Int
date_
, status :: Community -> Maybe CommunityMemberStatus
status = Maybe CommunityMemberStatus
status_
, permissions :: Community -> Maybe CommunityPermissions
permissions = Maybe CommunityPermissions
permissions_
}
= String
"Community"
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
"have_access" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
have_access_
, String
"name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
, String
"photo" String -> Maybe ChatPhotoInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatPhotoInfo
photo_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
, String
"status" String -> Maybe CommunityMemberStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe CommunityMemberStatus
status_
, String
"permissions" String -> Maybe CommunityPermissions -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe CommunityPermissions
permissions_
]
instance AT.FromJSON Community where
parseJSON :: Value -> Parser Community
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
"community" -> Value -> Parser Community
parseCommunity Value
v
String
_ -> Parser Community
forall a. Monoid a => a
mempty
where
parseCommunity :: A.Value -> AT.Parser Community
parseCommunity :: Value -> Parser Community
parseCommunity = String -> (Object -> Parser Community) -> Value -> Parser Community
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Community" ((Object -> Parser Community) -> Value -> Parser Community)
-> (Object -> Parser Community) -> Value -> Parser Community
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 Bool
have_access_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"have_access"
Maybe Text
name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"name"
Maybe ChatPhotoInfo
photo_ <- Object
o Object -> Key -> Parser (Maybe ChatPhotoInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
Maybe CommunityMemberStatus
status_ <- Object
o Object -> Key -> Parser (Maybe CommunityMemberStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"status"
Maybe CommunityPermissions
permissions_ <- Object
o Object -> Key -> Parser (Maybe CommunityPermissions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"permissions"
Community -> Parser Community
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Community -> Parser Community) -> Community -> Parser Community
forall a b. (a -> b) -> a -> b
$ Community
{ _id :: Maybe Int
_id = Maybe Int
_id_
, have_access :: Maybe Bool
have_access = Maybe Bool
have_access_
, name :: Maybe Text
name = Maybe Text
name_
, photo :: Maybe ChatPhotoInfo
photo = Maybe ChatPhotoInfo
photo_
, date :: Maybe Int
date = Maybe Int
date_
, status :: Maybe CommunityMemberStatus
status = Maybe CommunityMemberStatus
status_
, permissions :: Maybe CommunityPermissions
permissions = Maybe CommunityPermissions
permissions_
}
parseJSON Value
_ = Parser Community
forall a. Monoid a => a
mempty