module TD.Data.CommunityMemberChats
  (CommunityMemberChats(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

data CommunityMemberChats
  = CommunityMemberChats -- ^ Contains information about chats in a community, which are joined or owned by a member of the community
    { CommunityMemberChats -> Maybe [Int]
owned_chat_ids  :: Maybe [Int] -- ^ Identifiers of the chats owned by the member. The chats will be removed from the community if the member is banned in the community
    , CommunityMemberChats -> Maybe [Int]
joined_chat_ids :: Maybe [Int] -- ^ Identifiers of the non-owned chats joined by the member
    }
  deriving (CommunityMemberChats -> CommunityMemberChats -> Bool
(CommunityMemberChats -> CommunityMemberChats -> Bool)
-> (CommunityMemberChats -> CommunityMemberChats -> Bool)
-> Eq CommunityMemberChats
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommunityMemberChats -> CommunityMemberChats -> Bool
== :: CommunityMemberChats -> CommunityMemberChats -> Bool
$c/= :: CommunityMemberChats -> CommunityMemberChats -> Bool
/= :: CommunityMemberChats -> CommunityMemberChats -> Bool
Eq, Int -> CommunityMemberChats -> ShowS
[CommunityMemberChats] -> ShowS
CommunityMemberChats -> String
(Int -> CommunityMemberChats -> ShowS)
-> (CommunityMemberChats -> String)
-> ([CommunityMemberChats] -> ShowS)
-> Show CommunityMemberChats
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommunityMemberChats -> ShowS
showsPrec :: Int -> CommunityMemberChats -> ShowS
$cshow :: CommunityMemberChats -> String
show :: CommunityMemberChats -> String
$cshowList :: [CommunityMemberChats] -> ShowS
showList :: [CommunityMemberChats] -> ShowS
Show)

instance I.ShortShow CommunityMemberChats where
  shortShow :: CommunityMemberChats -> String
shortShow CommunityMemberChats
    { owned_chat_ids :: CommunityMemberChats -> Maybe [Int]
owned_chat_ids  = Maybe [Int]
owned_chat_ids_
    , joined_chat_ids :: CommunityMemberChats -> Maybe [Int]
joined_chat_ids = Maybe [Int]
joined_chat_ids_
    }
      = String
"CommunityMemberChats"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"owned_chat_ids"  String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
owned_chat_ids_
        , String
"joined_chat_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
joined_chat_ids_
        ]

instance AT.FromJSON CommunityMemberChats where
  parseJSON :: Value -> Parser CommunityMemberChats
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
"communityMemberChats" -> Value -> Parser CommunityMemberChats
parseCommunityMemberChats Value
v
      String
_                      -> Parser CommunityMemberChats
forall a. Monoid a => a
mempty
    
    where
      parseCommunityMemberChats :: A.Value -> AT.Parser CommunityMemberChats
      parseCommunityMemberChats :: Value -> Parser CommunityMemberChats
parseCommunityMemberChats = String
-> (Object -> Parser CommunityMemberChats)
-> Value
-> Parser CommunityMemberChats
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CommunityMemberChats" ((Object -> Parser CommunityMemberChats)
 -> Value -> Parser CommunityMemberChats)
-> (Object -> Parser CommunityMemberChats)
-> Value
-> Parser CommunityMemberChats
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Int]
owned_chat_ids_  <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"owned_chat_ids"
        Maybe [Int]
joined_chat_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"joined_chat_ids"
        CommunityMemberChats -> Parser CommunityMemberChats
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommunityMemberChats -> Parser CommunityMemberChats)
-> CommunityMemberChats -> Parser CommunityMemberChats
forall a b. (a -> b) -> a -> b
$ CommunityMemberChats
          { owned_chat_ids :: Maybe [Int]
owned_chat_ids  = Maybe [Int]
owned_chat_ids_
          , joined_chat_ids :: Maybe [Int]
joined_chat_ids = Maybe [Int]
joined_chat_ids_
          }
  parseJSON Value
_ = Parser CommunityMemberChats
forall a. Monoid a => a
mempty