module TD.Data.ForumTopic
  (ForumTopic(..)) 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.ForumTopicInfo as ForumTopicInfo
import qualified TD.Data.Message as Message
import qualified TD.Data.ChatNotificationSettings as ChatNotificationSettings
import qualified TD.Data.DraftMessage as DraftMessage

data ForumTopic
  = ForumTopic -- ^ Describes a forum topic
    { ForumTopic -> Maybe ForumTopicInfo
info                        :: Maybe ForumTopicInfo.ForumTopicInfo                     -- ^ Basic information about the topic
    , ForumTopic -> Maybe Message
last_message                :: Maybe Message.Message                                   -- ^ Last message in the topic; may be null if unknown
    , ForumTopic -> Maybe Bool
is_pinned                   :: Maybe Bool                                              -- ^ True, if the topic is pinned in the topic list
    , ForumTopic -> Maybe Int
unread_count                :: Maybe Int                                               -- ^ Number of unread messages in the topic
    , ForumTopic -> Maybe Int
last_read_inbox_message_id  :: Maybe Int                                               -- ^ Identifier of the last read incoming message
    , ForumTopic -> Maybe Int
last_read_outbox_message_id :: Maybe Int                                               -- ^ Identifier of the last read outgoing message
    , ForumTopic -> Maybe Int
unread_mention_count        :: Maybe Int                                               -- ^ Number of unread messages with a mention/reply in the topic
    , ForumTopic -> Maybe Int
unread_reaction_count       :: Maybe Int                                               -- ^ Number of messages with unread reactions in the topic
    , ForumTopic -> Maybe ChatNotificationSettings
notification_settings       :: Maybe ChatNotificationSettings.ChatNotificationSettings -- ^ Notification settings for the topic
    , ForumTopic -> Maybe DraftMessage
draft_message               :: Maybe DraftMessage.DraftMessage                         -- ^ A draft of a message in the topic; may be null if none
    }
  deriving (ForumTopic -> ForumTopic -> Bool
(ForumTopic -> ForumTopic -> Bool)
-> (ForumTopic -> ForumTopic -> Bool) -> Eq ForumTopic
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ForumTopic -> ForumTopic -> Bool
== :: ForumTopic -> ForumTopic -> Bool
$c/= :: ForumTopic -> ForumTopic -> Bool
/= :: ForumTopic -> ForumTopic -> Bool
Eq, Int -> ForumTopic -> ShowS
[ForumTopic] -> ShowS
ForumTopic -> String
(Int -> ForumTopic -> ShowS)
-> (ForumTopic -> String)
-> ([ForumTopic] -> ShowS)
-> Show ForumTopic
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ForumTopic -> ShowS
showsPrec :: Int -> ForumTopic -> ShowS
$cshow :: ForumTopic -> String
show :: ForumTopic -> String
$cshowList :: [ForumTopic] -> ShowS
showList :: [ForumTopic] -> ShowS
Show)

instance I.ShortShow ForumTopic where
  shortShow :: ForumTopic -> String
shortShow ForumTopic
    { info :: ForumTopic -> Maybe ForumTopicInfo
info                        = Maybe ForumTopicInfo
info_
    , last_message :: ForumTopic -> Maybe Message
last_message                = Maybe Message
last_message_
    , is_pinned :: ForumTopic -> Maybe Bool
is_pinned                   = Maybe Bool
is_pinned_
    , unread_count :: ForumTopic -> Maybe Int
unread_count                = Maybe Int
unread_count_
    , last_read_inbox_message_id :: ForumTopic -> Maybe Int
last_read_inbox_message_id  = Maybe Int
last_read_inbox_message_id_
    , last_read_outbox_message_id :: ForumTopic -> Maybe Int
last_read_outbox_message_id = Maybe Int
last_read_outbox_message_id_
    , unread_mention_count :: ForumTopic -> Maybe Int
unread_mention_count        = Maybe Int
unread_mention_count_
    , unread_reaction_count :: ForumTopic -> Maybe Int
unread_reaction_count       = Maybe Int
unread_reaction_count_
    , notification_settings :: ForumTopic -> Maybe ChatNotificationSettings
notification_settings       = Maybe ChatNotificationSettings
notification_settings_
    , draft_message :: ForumTopic -> Maybe DraftMessage
draft_message               = Maybe DraftMessage
draft_message_
    }
      = String
"ForumTopic"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"info"                        String -> Maybe ForumTopicInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ForumTopicInfo
info_
        , String
"last_message"                String -> Maybe Message -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Message
last_message_
        , String
"is_pinned"                   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_pinned_
        , String
"unread_count"                String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
unread_count_
        , String
"last_read_inbox_message_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_read_inbox_message_id_
        , String
"last_read_outbox_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_read_outbox_message_id_
        , String
"unread_mention_count"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
unread_mention_count_
        , String
"unread_reaction_count"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
unread_reaction_count_
        , String
"notification_settings"       String -> Maybe ChatNotificationSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatNotificationSettings
notification_settings_
        , String
"draft_message"               String -> Maybe DraftMessage -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe DraftMessage
draft_message_
        ]

instance AT.FromJSON ForumTopic where
  parseJSON :: Value -> Parser ForumTopic
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
"forumTopic" -> Value -> Parser ForumTopic
parseForumTopic Value
v
      String
_            -> Parser ForumTopic
forall a. Monoid a => a
mempty
    
    where
      parseForumTopic :: A.Value -> AT.Parser ForumTopic
      parseForumTopic :: Value -> Parser ForumTopic
parseForumTopic = String
-> (Object -> Parser ForumTopic) -> Value -> Parser ForumTopic
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ForumTopic" ((Object -> Parser ForumTopic) -> Value -> Parser ForumTopic)
-> (Object -> Parser ForumTopic) -> Value -> Parser ForumTopic
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ForumTopicInfo
info_                        <- Object
o Object -> Key -> Parser (Maybe ForumTopicInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"info"
        Maybe Message
last_message_                <- Object
o Object -> Key -> Parser (Maybe Message)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"last_message"
        Maybe Bool
is_pinned_                   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_pinned"
        Maybe Int
unread_count_                <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"unread_count"
        Maybe Int
last_read_inbox_message_id_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"last_read_inbox_message_id"
        Maybe Int
last_read_outbox_message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"last_read_outbox_message_id"
        Maybe Int
unread_mention_count_        <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"unread_mention_count"
        Maybe Int
unread_reaction_count_       <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"unread_reaction_count"
        Maybe ChatNotificationSettings
notification_settings_       <- Object
o Object -> Key -> Parser (Maybe ChatNotificationSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"notification_settings"
        Maybe DraftMessage
draft_message_               <- Object
o Object -> Key -> Parser (Maybe DraftMessage)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"draft_message"
        ForumTopic -> Parser ForumTopic
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ForumTopic -> Parser ForumTopic)
-> ForumTopic -> Parser ForumTopic
forall a b. (a -> b) -> a -> b
$ ForumTopic
          { info :: Maybe ForumTopicInfo
info                        = Maybe ForumTopicInfo
info_
          , last_message :: Maybe Message
last_message                = Maybe Message
last_message_
          , is_pinned :: Maybe Bool
is_pinned                   = Maybe Bool
is_pinned_
          , unread_count :: Maybe Int
unread_count                = Maybe Int
unread_count_
          , last_read_inbox_message_id :: Maybe Int
last_read_inbox_message_id  = Maybe Int
last_read_inbox_message_id_
          , last_read_outbox_message_id :: Maybe Int
last_read_outbox_message_id = Maybe Int
last_read_outbox_message_id_
          , unread_mention_count :: Maybe Int
unread_mention_count        = Maybe Int
unread_mention_count_
          , unread_reaction_count :: Maybe Int
unread_reaction_count       = Maybe Int
unread_reaction_count_
          , notification_settings :: Maybe ChatNotificationSettings
notification_settings       = Maybe ChatNotificationSettings
notification_settings_
          , draft_message :: Maybe DraftMessage
draft_message               = Maybe DraftMessage
draft_message_
          }
  parseJSON Value
_ = Parser ForumTopic
forall a. Monoid a => a
mempty