module TD.Data.UserStatus
(UserStatus(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data UserStatus
= UserStatusEmpty
| UserStatusOnline
{ UserStatus -> Maybe Int
expires :: Maybe Int
}
| UserStatusOffline
{ UserStatus -> Maybe Int
was_online :: Maybe Int
}
| UserStatusRecently
{ UserStatus -> Maybe Bool
by_my_privacy_settings :: Maybe Bool
}
| UserStatusLastWeek
{ by_my_privacy_settings :: Maybe Bool
}
| UserStatusLastMonth
{ by_my_privacy_settings :: Maybe Bool
}
deriving (UserStatus -> UserStatus -> Bool
(UserStatus -> UserStatus -> Bool)
-> (UserStatus -> UserStatus -> Bool) -> Eq UserStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserStatus -> UserStatus -> Bool
== :: UserStatus -> UserStatus -> Bool
$c/= :: UserStatus -> UserStatus -> Bool
/= :: UserStatus -> UserStatus -> Bool
Eq, Int -> UserStatus -> ShowS
[UserStatus] -> ShowS
UserStatus -> String
(Int -> UserStatus -> ShowS)
-> (UserStatus -> String)
-> ([UserStatus] -> ShowS)
-> Show UserStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserStatus -> ShowS
showsPrec :: Int -> UserStatus -> ShowS
$cshow :: UserStatus -> String
show :: UserStatus -> String
$cshowList :: [UserStatus] -> ShowS
showList :: [UserStatus] -> ShowS
Show)
instance I.ShortShow UserStatus where
shortShow :: UserStatus -> String
shortShow UserStatus
UserStatusEmpty
= String
"UserStatusEmpty"
shortShow UserStatusOnline
{ expires :: UserStatus -> Maybe Int
expires = Maybe Int
expires_
}
= String
"UserStatusOnline"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"expires" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expires_
]
shortShow UserStatusOffline
{ was_online :: UserStatus -> Maybe Int
was_online = Maybe Int
was_online_
}
= String
"UserStatusOffline"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"was_online" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
was_online_
]
shortShow UserStatusRecently
{ by_my_privacy_settings :: UserStatus -> Maybe Bool
by_my_privacy_settings = Maybe Bool
by_my_privacy_settings_
}
= String
"UserStatusRecently"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"by_my_privacy_settings" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
by_my_privacy_settings_
]
shortShow UserStatusLastWeek
{ by_my_privacy_settings :: UserStatus -> Maybe Bool
by_my_privacy_settings = Maybe Bool
by_my_privacy_settings_
}
= String
"UserStatusLastWeek"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"by_my_privacy_settings" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
by_my_privacy_settings_
]
shortShow UserStatusLastMonth
{ by_my_privacy_settings :: UserStatus -> Maybe Bool
by_my_privacy_settings = Maybe Bool
by_my_privacy_settings_
}
= String
"UserStatusLastMonth"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"by_my_privacy_settings" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
by_my_privacy_settings_
]
instance AT.FromJSON UserStatus where
parseJSON :: Value -> Parser UserStatus
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
"userStatusEmpty" -> UserStatus -> Parser UserStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserStatus
UserStatusEmpty
String
"userStatusOnline" -> Value -> Parser UserStatus
parseUserStatusOnline Value
v
String
"userStatusOffline" -> Value -> Parser UserStatus
parseUserStatusOffline Value
v
String
"userStatusRecently" -> Value -> Parser UserStatus
parseUserStatusRecently Value
v
String
"userStatusLastWeek" -> Value -> Parser UserStatus
parseUserStatusLastWeek Value
v
String
"userStatusLastMonth" -> Value -> Parser UserStatus
parseUserStatusLastMonth Value
v
String
_ -> Parser UserStatus
forall a. Monoid a => a
mempty
where
parseUserStatusOnline :: A.Value -> AT.Parser UserStatus
parseUserStatusOnline :: Value -> Parser UserStatus
parseUserStatusOnline = String
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserStatusOnline" ((Object -> Parser UserStatus) -> Value -> Parser UserStatus)
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
expires_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"expires"
UserStatus -> Parser UserStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserStatus -> Parser UserStatus)
-> UserStatus -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ UserStatusOnline
{ expires :: Maybe Int
expires = Maybe Int
expires_
}
parseUserStatusOffline :: A.Value -> AT.Parser UserStatus
parseUserStatusOffline :: Value -> Parser UserStatus
parseUserStatusOffline = String
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserStatusOffline" ((Object -> Parser UserStatus) -> Value -> Parser UserStatus)
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
was_online_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"was_online"
UserStatus -> Parser UserStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserStatus -> Parser UserStatus)
-> UserStatus -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ UserStatusOffline
{ was_online :: Maybe Int
was_online = Maybe Int
was_online_
}
parseUserStatusRecently :: A.Value -> AT.Parser UserStatus
parseUserStatusRecently :: Value -> Parser UserStatus
parseUserStatusRecently = String
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserStatusRecently" ((Object -> Parser UserStatus) -> Value -> Parser UserStatus)
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
by_my_privacy_settings_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"by_my_privacy_settings"
UserStatus -> Parser UserStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserStatus -> Parser UserStatus)
-> UserStatus -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ UserStatusRecently
{ by_my_privacy_settings :: Maybe Bool
by_my_privacy_settings = Maybe Bool
by_my_privacy_settings_
}
parseUserStatusLastWeek :: A.Value -> AT.Parser UserStatus
parseUserStatusLastWeek :: Value -> Parser UserStatus
parseUserStatusLastWeek = String
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserStatusLastWeek" ((Object -> Parser UserStatus) -> Value -> Parser UserStatus)
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
by_my_privacy_settings_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"by_my_privacy_settings"
UserStatus -> Parser UserStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserStatus -> Parser UserStatus)
-> UserStatus -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ UserStatusLastWeek
{ by_my_privacy_settings :: Maybe Bool
by_my_privacy_settings = Maybe Bool
by_my_privacy_settings_
}
parseUserStatusLastMonth :: A.Value -> AT.Parser UserStatus
parseUserStatusLastMonth :: Value -> Parser UserStatus
parseUserStatusLastMonth = String
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserStatusLastMonth" ((Object -> Parser UserStatus) -> Value -> Parser UserStatus)
-> (Object -> Parser UserStatus) -> Value -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
by_my_privacy_settings_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"by_my_privacy_settings"
UserStatus -> Parser UserStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserStatus -> Parser UserStatus)
-> UserStatus -> Parser UserStatus
forall a b. (a -> b) -> a -> b
$ UserStatusLastMonth
{ by_my_privacy_settings :: Maybe Bool
by_my_privacy_settings = Maybe Bool
by_my_privacy_settings_
}
parseJSON Value
_ = Parser UserStatus
forall a. Monoid a => a
mempty