module TD.Data.NotificationGroup
(NotificationGroup(..)) 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.NotificationGroupType as NotificationGroupType
import qualified TD.Data.Notification as Notification
data NotificationGroup
= NotificationGroup
{ NotificationGroup -> Maybe Int
_id :: Maybe Int
, NotificationGroup -> Maybe NotificationGroupType
_type :: Maybe NotificationGroupType.NotificationGroupType
, NotificationGroup -> Maybe Int
chat_id :: Maybe Int
, NotificationGroup -> Maybe Int
total_count :: Maybe Int
, NotificationGroup -> Maybe [Notification]
notifications :: Maybe [Notification.Notification]
}
deriving (NotificationGroup -> NotificationGroup -> Bool
(NotificationGroup -> NotificationGroup -> Bool)
-> (NotificationGroup -> NotificationGroup -> Bool)
-> Eq NotificationGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NotificationGroup -> NotificationGroup -> Bool
== :: NotificationGroup -> NotificationGroup -> Bool
$c/= :: NotificationGroup -> NotificationGroup -> Bool
/= :: NotificationGroup -> NotificationGroup -> Bool
Eq, Int -> NotificationGroup -> ShowS
[NotificationGroup] -> ShowS
NotificationGroup -> String
(Int -> NotificationGroup -> ShowS)
-> (NotificationGroup -> String)
-> ([NotificationGroup] -> ShowS)
-> Show NotificationGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NotificationGroup -> ShowS
showsPrec :: Int -> NotificationGroup -> ShowS
$cshow :: NotificationGroup -> String
show :: NotificationGroup -> String
$cshowList :: [NotificationGroup] -> ShowS
showList :: [NotificationGroup] -> ShowS
Show)
instance I.ShortShow NotificationGroup where
shortShow :: NotificationGroup -> String
shortShow NotificationGroup
{ _id :: NotificationGroup -> Maybe Int
_id = Maybe Int
_id_
, _type :: NotificationGroup -> Maybe NotificationGroupType
_type = Maybe NotificationGroupType
_type_
, chat_id :: NotificationGroup -> Maybe Int
chat_id = Maybe Int
chat_id_
, total_count :: NotificationGroup -> Maybe Int
total_count = Maybe Int
total_count_
, notifications :: NotificationGroup -> Maybe [Notification]
notifications = Maybe [Notification]
notifications_
}
= String
"NotificationGroup"
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
"_type" String -> Maybe NotificationGroupType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe NotificationGroupType
_type_
, String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
, String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
, String
"notifications" String -> Maybe [Notification] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Notification]
notifications_
]
instance AT.FromJSON NotificationGroup where
parseJSON :: Value -> Parser NotificationGroup
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
"notificationGroup" -> Value -> Parser NotificationGroup
parseNotificationGroup Value
v
String
_ -> Parser NotificationGroup
forall a. Monoid a => a
mempty
where
parseNotificationGroup :: A.Value -> AT.Parser NotificationGroup
parseNotificationGroup :: Value -> Parser NotificationGroup
parseNotificationGroup = String
-> (Object -> Parser NotificationGroup)
-> Value
-> Parser NotificationGroup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"NotificationGroup" ((Object -> Parser NotificationGroup)
-> Value -> Parser NotificationGroup)
-> (Object -> Parser NotificationGroup)
-> Value
-> Parser NotificationGroup
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 NotificationGroupType
_type_ <- Object
o Object -> Key -> Parser (Maybe NotificationGroupType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
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 Int
total_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"total_count"
Maybe [Notification]
notifications_ <- Object
o Object -> Key -> Parser (Maybe [Notification])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"notifications"
NotificationGroup -> Parser NotificationGroup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NotificationGroup -> Parser NotificationGroup)
-> NotificationGroup -> Parser NotificationGroup
forall a b. (a -> b) -> a -> b
$ NotificationGroup
{ _id :: Maybe Int
_id = Maybe Int
_id_
, _type :: Maybe NotificationGroupType
_type = Maybe NotificationGroupType
_type_
, chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
, total_count :: Maybe Int
total_count = Maybe Int
total_count_
, notifications :: Maybe [Notification]
notifications = Maybe [Notification]
notifications_
}
parseJSON Value
_ = Parser NotificationGroup
forall a. Monoid a => a
mempty