module TD.Data.CommunityFullInfo
  (CommunityFullInfo(..)) 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.ChatPhoto as ChatPhoto
import qualified TD.Data.CommunityChat as CommunityChat

data CommunityFullInfo
  = CommunityFullInfo -- ^ Contains full information about a community
    { CommunityFullInfo -> Maybe ChatPhoto
photo                  :: Maybe ChatPhoto.ChatPhoto           -- ^ Photo of the community
    , CommunityFullInfo -> Maybe [CommunityChat]
chats                  :: Maybe [CommunityChat.CommunityChat] -- ^ Chats belonging to the community
    , CommunityFullInfo -> Maybe Int
administrator_count    :: Maybe Int                           -- ^ Number of privileged users in the community; 0 if the current user isn't an administrator of the community
    , CommunityFullInfo -> Maybe Int
banned_count           :: Maybe Int                           -- ^ Number of users banned from the community; 0 if the current user isn't an administrator of the community
    , CommunityFullInfo -> Maybe Int
add_chat_request_count :: Maybe Int                           -- ^ Number of pending requests for addition of chats to the community; 0 if the current user isn't an administrator of the community
    }
  deriving (CommunityFullInfo -> CommunityFullInfo -> Bool
(CommunityFullInfo -> CommunityFullInfo -> Bool)
-> (CommunityFullInfo -> CommunityFullInfo -> Bool)
-> Eq CommunityFullInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommunityFullInfo -> CommunityFullInfo -> Bool
== :: CommunityFullInfo -> CommunityFullInfo -> Bool
$c/= :: CommunityFullInfo -> CommunityFullInfo -> Bool
/= :: CommunityFullInfo -> CommunityFullInfo -> Bool
Eq, Int -> CommunityFullInfo -> ShowS
[CommunityFullInfo] -> ShowS
CommunityFullInfo -> String
(Int -> CommunityFullInfo -> ShowS)
-> (CommunityFullInfo -> String)
-> ([CommunityFullInfo] -> ShowS)
-> Show CommunityFullInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommunityFullInfo -> ShowS
showsPrec :: Int -> CommunityFullInfo -> ShowS
$cshow :: CommunityFullInfo -> String
show :: CommunityFullInfo -> String
$cshowList :: [CommunityFullInfo] -> ShowS
showList :: [CommunityFullInfo] -> ShowS
Show)

instance I.ShortShow CommunityFullInfo where
  shortShow :: CommunityFullInfo -> String
shortShow CommunityFullInfo
    { photo :: CommunityFullInfo -> Maybe ChatPhoto
photo                  = Maybe ChatPhoto
photo_
    , chats :: CommunityFullInfo -> Maybe [CommunityChat]
chats                  = Maybe [CommunityChat]
chats_
    , administrator_count :: CommunityFullInfo -> Maybe Int
administrator_count    = Maybe Int
administrator_count_
    , banned_count :: CommunityFullInfo -> Maybe Int
banned_count           = Maybe Int
banned_count_
    , add_chat_request_count :: CommunityFullInfo -> Maybe Int
add_chat_request_count = Maybe Int
add_chat_request_count_
    }
      = String
"CommunityFullInfo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"photo"                  String -> Maybe ChatPhoto -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatPhoto
photo_
        , String
"chats"                  String -> Maybe [CommunityChat] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [CommunityChat]
chats_
        , String
"administrator_count"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
administrator_count_
        , String
"banned_count"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
banned_count_
        , String
"add_chat_request_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
add_chat_request_count_
        ]

instance AT.FromJSON CommunityFullInfo where
  parseJSON :: Value -> Parser CommunityFullInfo
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
"communityFullInfo" -> Value -> Parser CommunityFullInfo
parseCommunityFullInfo Value
v
      String
_                   -> Parser CommunityFullInfo
forall a. Monoid a => a
mempty
    
    where
      parseCommunityFullInfo :: A.Value -> AT.Parser CommunityFullInfo
      parseCommunityFullInfo :: Value -> Parser CommunityFullInfo
parseCommunityFullInfo = String
-> (Object -> Parser CommunityFullInfo)
-> Value
-> Parser CommunityFullInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CommunityFullInfo" ((Object -> Parser CommunityFullInfo)
 -> Value -> Parser CommunityFullInfo)
-> (Object -> Parser CommunityFullInfo)
-> Value
-> Parser CommunityFullInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ChatPhoto
photo_                  <- Object
o Object -> Key -> Parser (Maybe ChatPhoto)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"photo"
        Maybe [CommunityChat]
chats_                  <- Object
o Object -> Key -> Parser (Maybe [CommunityChat])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chats"
        Maybe Int
administrator_count_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"administrator_count"
        Maybe Int
banned_count_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"banned_count"
        Maybe Int
add_chat_request_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"add_chat_request_count"
        CommunityFullInfo -> Parser CommunityFullInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommunityFullInfo -> Parser CommunityFullInfo)
-> CommunityFullInfo -> Parser CommunityFullInfo
forall a b. (a -> b) -> a -> b
$ CommunityFullInfo
          { photo :: Maybe ChatPhoto
photo                  = Maybe ChatPhoto
photo_
          , chats :: Maybe [CommunityChat]
chats                  = Maybe [CommunityChat]
chats_
          , administrator_count :: Maybe Int
administrator_count    = Maybe Int
administrator_count_
          , banned_count :: Maybe Int
banned_count           = Maybe Int
banned_count_
          , add_chat_request_count :: Maybe Int
add_chat_request_count = Maybe Int
add_chat_request_count_
          }
  parseJSON Value
_ = Parser CommunityFullInfo
forall a. Monoid a => a
mempty