module TD.Data.UserRating
(UserRating(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data UserRating
= UserRating
{ UserRating -> Maybe Int
level :: Maybe Int
, UserRating -> Maybe Bool
is_maximum_level_reached :: Maybe Bool
, UserRating -> Maybe Int
rating :: Maybe Int
, UserRating -> Maybe Int
current_level_rating :: Maybe Int
, UserRating -> Maybe Int
next_level_rating :: Maybe Int
}
deriving (UserRating -> UserRating -> Bool
(UserRating -> UserRating -> Bool)
-> (UserRating -> UserRating -> Bool) -> Eq UserRating
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserRating -> UserRating -> Bool
== :: UserRating -> UserRating -> Bool
$c/= :: UserRating -> UserRating -> Bool
/= :: UserRating -> UserRating -> Bool
Eq, Int -> UserRating -> ShowS
[UserRating] -> ShowS
UserRating -> String
(Int -> UserRating -> ShowS)
-> (UserRating -> String)
-> ([UserRating] -> ShowS)
-> Show UserRating
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserRating -> ShowS
showsPrec :: Int -> UserRating -> ShowS
$cshow :: UserRating -> String
show :: UserRating -> String
$cshowList :: [UserRating] -> ShowS
showList :: [UserRating] -> ShowS
Show)
instance I.ShortShow UserRating where
shortShow :: UserRating -> String
shortShow UserRating
{ level :: UserRating -> Maybe Int
level = Maybe Int
level_
, is_maximum_level_reached :: UserRating -> Maybe Bool
is_maximum_level_reached = Maybe Bool
is_maximum_level_reached_
, rating :: UserRating -> Maybe Int
rating = Maybe Int
rating_
, current_level_rating :: UserRating -> Maybe Int
current_level_rating = Maybe Int
current_level_rating_
, next_level_rating :: UserRating -> Maybe Int
next_level_rating = Maybe Int
next_level_rating_
}
= String
"UserRating"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"level" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
level_
, String
"is_maximum_level_reached" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_maximum_level_reached_
, String
"rating" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
rating_
, String
"current_level_rating" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
current_level_rating_
, String
"next_level_rating" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
next_level_rating_
]
instance AT.FromJSON UserRating where
parseJSON :: Value -> Parser UserRating
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
"userRating" -> Value -> Parser UserRating
parseUserRating Value
v
String
_ -> Parser UserRating
forall a. Monoid a => a
mempty
where
parseUserRating :: A.Value -> AT.Parser UserRating
parseUserRating :: Value -> Parser UserRating
parseUserRating = String
-> (Object -> Parser UserRating) -> Value -> Parser UserRating
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UserRating" ((Object -> Parser UserRating) -> Value -> Parser UserRating)
-> (Object -> Parser UserRating) -> Value -> Parser UserRating
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
level_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"level"
Maybe Bool
is_maximum_level_reached_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_maximum_level_reached"
Maybe Int
rating_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"rating"
Maybe Int
current_level_rating_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"current_level_rating"
Maybe Int
next_level_rating_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"next_level_rating"
UserRating -> Parser UserRating
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserRating -> Parser UserRating)
-> UserRating -> Parser UserRating
forall a b. (a -> b) -> a -> b
$ UserRating
{ level :: Maybe Int
level = Maybe Int
level_
, is_maximum_level_reached :: Maybe Bool
is_maximum_level_reached = Maybe Bool
is_maximum_level_reached_
, rating :: Maybe Int
rating = Maybe Int
rating_
, current_level_rating :: Maybe Int
current_level_rating = Maybe Int
current_level_rating_
, next_level_rating :: Maybe Int
next_level_rating = Maybe Int
next_level_rating_
}
parseJSON Value
_ = Parser UserRating
forall a. Monoid a => a
mempty