module TD.Data.MessageReadDate
(MessageReadDate(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data MessageReadDate
= MessageReadDateRead
{ MessageReadDate -> Maybe Int
read_date :: Maybe Int
}
| MessageReadDateUnread
| MessageReadDateTooOld
| MessageReadDateUserPrivacyRestricted
| MessageReadDateMyPrivacyRestricted
deriving (MessageReadDate -> MessageReadDate -> Bool
(MessageReadDate -> MessageReadDate -> Bool)
-> (MessageReadDate -> MessageReadDate -> Bool)
-> Eq MessageReadDate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageReadDate -> MessageReadDate -> Bool
== :: MessageReadDate -> MessageReadDate -> Bool
$c/= :: MessageReadDate -> MessageReadDate -> Bool
/= :: MessageReadDate -> MessageReadDate -> Bool
Eq, Int -> MessageReadDate -> ShowS
[MessageReadDate] -> ShowS
MessageReadDate -> String
(Int -> MessageReadDate -> ShowS)
-> (MessageReadDate -> String)
-> ([MessageReadDate] -> ShowS)
-> Show MessageReadDate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageReadDate -> ShowS
showsPrec :: Int -> MessageReadDate -> ShowS
$cshow :: MessageReadDate -> String
show :: MessageReadDate -> String
$cshowList :: [MessageReadDate] -> ShowS
showList :: [MessageReadDate] -> ShowS
Show)
instance I.ShortShow MessageReadDate where
shortShow :: MessageReadDate -> String
shortShow MessageReadDateRead
{ read_date :: MessageReadDate -> Maybe Int
read_date = Maybe Int
read_date_
}
= String
"MessageReadDateRead"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"read_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
read_date_
]
shortShow MessageReadDate
MessageReadDateUnread
= String
"MessageReadDateUnread"
shortShow MessageReadDate
MessageReadDateTooOld
= String
"MessageReadDateTooOld"
shortShow MessageReadDate
MessageReadDateUserPrivacyRestricted
= String
"MessageReadDateUserPrivacyRestricted"
shortShow MessageReadDate
MessageReadDateMyPrivacyRestricted
= String
"MessageReadDateMyPrivacyRestricted"
instance AT.FromJSON MessageReadDate where
parseJSON :: Value -> Parser MessageReadDate
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
"messageReadDateRead" -> Value -> Parser MessageReadDate
parseMessageReadDateRead Value
v
String
"messageReadDateUnread" -> MessageReadDate -> Parser MessageReadDate
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageReadDate
MessageReadDateUnread
String
"messageReadDateTooOld" -> MessageReadDate -> Parser MessageReadDate
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageReadDate
MessageReadDateTooOld
String
"messageReadDateUserPrivacyRestricted" -> MessageReadDate -> Parser MessageReadDate
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageReadDate
MessageReadDateUserPrivacyRestricted
String
"messageReadDateMyPrivacyRestricted" -> MessageReadDate -> Parser MessageReadDate
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageReadDate
MessageReadDateMyPrivacyRestricted
String
_ -> Parser MessageReadDate
forall a. Monoid a => a
mempty
where
parseMessageReadDateRead :: A.Value -> AT.Parser MessageReadDate
parseMessageReadDateRead :: Value -> Parser MessageReadDate
parseMessageReadDateRead = String
-> (Object -> Parser MessageReadDate)
-> Value
-> Parser MessageReadDate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageReadDateRead" ((Object -> Parser MessageReadDate)
-> Value -> Parser MessageReadDate)
-> (Object -> Parser MessageReadDate)
-> Value
-> Parser MessageReadDate
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
read_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"read_date"
MessageReadDate -> Parser MessageReadDate
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageReadDate -> Parser MessageReadDate)
-> MessageReadDate -> Parser MessageReadDate
forall a b. (a -> b) -> a -> b
$ MessageReadDateRead
{ read_date :: Maybe Int
read_date = Maybe Int
read_date_
}
parseJSON Value
_ = Parser MessageReadDate
forall a. Monoid a => a
mempty