module TD.Data.SavedMessagesTopic
(SavedMessagesTopic(..)) 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.SavedMessagesTopicType as SavedMessagesTopicType
import qualified TD.Data.Message as Message
import qualified TD.Data.DraftMessage as DraftMessage
data SavedMessagesTopic
= SavedMessagesTopic
{ SavedMessagesTopic -> Maybe Int
_id :: Maybe Int
, SavedMessagesTopic -> Maybe SavedMessagesTopicType
_type :: Maybe SavedMessagesTopicType.SavedMessagesTopicType
, SavedMessagesTopic -> Maybe Bool
is_pinned :: Maybe Bool
, SavedMessagesTopic -> Maybe Int
order :: Maybe Int
, SavedMessagesTopic -> Maybe Message
last_message :: Maybe Message.Message
, SavedMessagesTopic -> Maybe DraftMessage
draft_message :: Maybe DraftMessage.DraftMessage
}
deriving (SavedMessagesTopic -> SavedMessagesTopic -> Bool
(SavedMessagesTopic -> SavedMessagesTopic -> Bool)
-> (SavedMessagesTopic -> SavedMessagesTopic -> Bool)
-> Eq SavedMessagesTopic
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SavedMessagesTopic -> SavedMessagesTopic -> Bool
== :: SavedMessagesTopic -> SavedMessagesTopic -> Bool
$c/= :: SavedMessagesTopic -> SavedMessagesTopic -> Bool
/= :: SavedMessagesTopic -> SavedMessagesTopic -> Bool
Eq, Int -> SavedMessagesTopic -> ShowS
[SavedMessagesTopic] -> ShowS
SavedMessagesTopic -> String
(Int -> SavedMessagesTopic -> ShowS)
-> (SavedMessagesTopic -> String)
-> ([SavedMessagesTopic] -> ShowS)
-> Show SavedMessagesTopic
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SavedMessagesTopic -> ShowS
showsPrec :: Int -> SavedMessagesTopic -> ShowS
$cshow :: SavedMessagesTopic -> String
show :: SavedMessagesTopic -> String
$cshowList :: [SavedMessagesTopic] -> ShowS
showList :: [SavedMessagesTopic] -> ShowS
Show)
instance I.ShortShow SavedMessagesTopic where
shortShow :: SavedMessagesTopic -> String
shortShow SavedMessagesTopic
{ _id :: SavedMessagesTopic -> Maybe Int
_id = Maybe Int
_id_
, _type :: SavedMessagesTopic -> Maybe SavedMessagesTopicType
_type = Maybe SavedMessagesTopicType
_type_
, is_pinned :: SavedMessagesTopic -> Maybe Bool
is_pinned = Maybe Bool
is_pinned_
, order :: SavedMessagesTopic -> Maybe Int
order = Maybe Int
order_
, last_message :: SavedMessagesTopic -> Maybe Message
last_message = Maybe Message
last_message_
, draft_message :: SavedMessagesTopic -> Maybe DraftMessage
draft_message = Maybe DraftMessage
draft_message_
}
= String
"SavedMessagesTopic"
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 SavedMessagesTopicType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe SavedMessagesTopicType
_type_
, String
"is_pinned" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_pinned_
, String
"order" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
order_
, String
"last_message" String -> Maybe Message -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Message
last_message_
, String
"draft_message" String -> Maybe DraftMessage -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe DraftMessage
draft_message_
]
instance AT.FromJSON SavedMessagesTopic where
parseJSON :: Value -> Parser SavedMessagesTopic
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
"savedMessagesTopic" -> Value -> Parser SavedMessagesTopic
parseSavedMessagesTopic Value
v
String
_ -> Parser SavedMessagesTopic
forall a. Monoid a => a
mempty
where
parseSavedMessagesTopic :: A.Value -> AT.Parser SavedMessagesTopic
parseSavedMessagesTopic :: Value -> Parser SavedMessagesTopic
parseSavedMessagesTopic = String
-> (Object -> Parser SavedMessagesTopic)
-> Value
-> Parser SavedMessagesTopic
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SavedMessagesTopic" ((Object -> Parser SavedMessagesTopic)
-> Value -> Parser SavedMessagesTopic)
-> (Object -> Parser SavedMessagesTopic)
-> Value
-> Parser SavedMessagesTopic
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 SavedMessagesTopicType
_type_ <- Object
o Object -> Key -> Parser (Maybe SavedMessagesTopicType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
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
order_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"order"
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 DraftMessage
draft_message_ <- Object
o Object -> Key -> Parser (Maybe DraftMessage)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"draft_message"
SavedMessagesTopic -> Parser SavedMessagesTopic
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SavedMessagesTopic -> Parser SavedMessagesTopic)
-> SavedMessagesTopic -> Parser SavedMessagesTopic
forall a b. (a -> b) -> a -> b
$ SavedMessagesTopic
{ _id :: Maybe Int
_id = Maybe Int
_id_
, _type :: Maybe SavedMessagesTopicType
_type = Maybe SavedMessagesTopicType
_type_
, is_pinned :: Maybe Bool
is_pinned = Maybe Bool
is_pinned_
, order :: Maybe Int
order = Maybe Int
order_
, last_message :: Maybe Message
last_message = Maybe Message
last_message_
, draft_message :: Maybe DraftMessage
draft_message = Maybe DraftMessage
draft_message_
}
parseJSON Value
_ = Parser SavedMessagesTopic
forall a. Monoid a => a
mempty