module TD.Data.CommunityChat
  (CommunityChat(..)) where

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

data CommunityChat
  = CommunityChat -- ^ Describes a chat in a community
    { CommunityChat -> Maybe Int
chat_id          :: Maybe Int  -- ^ Identifier of the chat in the community
    , CommunityChat -> Maybe Bool
can_view_history :: Maybe Bool -- ^ True, if message history of the chat can be viewed
    , CommunityChat -> Maybe Bool
is_hidden        :: Maybe Bool -- ^ True, if the chat is hidden in the list of community chats; for community administrators only
    }
  deriving (CommunityChat -> CommunityChat -> Bool
(CommunityChat -> CommunityChat -> Bool)
-> (CommunityChat -> CommunityChat -> Bool) -> Eq CommunityChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommunityChat -> CommunityChat -> Bool
== :: CommunityChat -> CommunityChat -> Bool
$c/= :: CommunityChat -> CommunityChat -> Bool
/= :: CommunityChat -> CommunityChat -> Bool
Eq, Int -> CommunityChat -> ShowS
[CommunityChat] -> ShowS
CommunityChat -> String
(Int -> CommunityChat -> ShowS)
-> (CommunityChat -> String)
-> ([CommunityChat] -> ShowS)
-> Show CommunityChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommunityChat -> ShowS
showsPrec :: Int -> CommunityChat -> ShowS
$cshow :: CommunityChat -> String
show :: CommunityChat -> String
$cshowList :: [CommunityChat] -> ShowS
showList :: [CommunityChat] -> ShowS
Show)

instance I.ShortShow CommunityChat where
  shortShow :: CommunityChat -> String
shortShow CommunityChat
    { chat_id :: CommunityChat -> Maybe Int
chat_id          = Maybe Int
chat_id_
    , can_view_history :: CommunityChat -> Maybe Bool
can_view_history = Maybe Bool
can_view_history_
    , is_hidden :: CommunityChat -> Maybe Bool
is_hidden        = Maybe Bool
is_hidden_
    }
      = String
"CommunityChat"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_id"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
        , String
"can_view_history" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_view_history_
        , String
"is_hidden"        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_hidden_
        ]

instance AT.FromJSON CommunityChat where
  parseJSON :: Value -> Parser CommunityChat
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
"communityChat" -> Value -> Parser CommunityChat
parseCommunityChat Value
v
      String
_               -> Parser CommunityChat
forall a. Monoid a => a
mempty
    
    where
      parseCommunityChat :: A.Value -> AT.Parser CommunityChat
      parseCommunityChat :: Value -> Parser CommunityChat
parseCommunityChat = String
-> (Object -> Parser CommunityChat)
-> Value
-> Parser CommunityChat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CommunityChat" ((Object -> Parser CommunityChat) -> Value -> Parser CommunityChat)
-> (Object -> Parser CommunityChat)
-> Value
-> Parser CommunityChat
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_          <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe Bool
can_view_history_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_view_history"
        Maybe Bool
is_hidden_        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_hidden"
        CommunityChat -> Parser CommunityChat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommunityChat -> Parser CommunityChat)
-> CommunityChat -> Parser CommunityChat
forall a b. (a -> b) -> a -> b
$ CommunityChat
          { chat_id :: Maybe Int
chat_id          = Maybe Int
chat_id_
          , can_view_history :: Maybe Bool
can_view_history = Maybe Bool
can_view_history_
          , is_hidden :: Maybe Bool
is_hidden        = Maybe Bool
is_hidden_
          }
  parseJSON Value
_ = Parser CommunityChat
forall a. Monoid a => a
mempty