module Codeforces.Types.User where
import Codeforces.Types.Common
import Data.Aeson
import Data.Maybe
import Data.Text ( Text )
data User = User
{ User -> Handle
userHandle :: Handle
, User -> Maybe Text
userFirstName :: Maybe Text
, User -> Maybe Text
userLastName :: Maybe Text
, User -> Rating
userRating :: Rating
, User -> Rating
userMaxRating :: Rating
, User -> Maybe Text
userCity :: Maybe Text
, User -> Maybe Text
userCountry :: Maybe Text
, User -> Maybe Text
userOrganization :: Maybe Text
, User -> Rating
userFriendOfCount :: Int
}
deriving Rating -> User -> ShowS
[User] -> ShowS
User -> String
(Rating -> User -> ShowS)
-> (User -> String) -> ([User] -> ShowS) -> Show User
forall a.
(Rating -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [User] -> ShowS
$cshowList :: [User] -> ShowS
show :: User -> String
$cshow :: User -> String
showsPrec :: Rating -> User -> ShowS
$cshowsPrec :: Rating -> User -> ShowS
Show
instance FromJSON User where
parseJSON :: Value -> Parser User
parseJSON = String -> (Object -> Parser User) -> Value -> Parser User
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"User" ((Object -> Parser User) -> Value -> Parser User)
-> (Object -> Parser User) -> Value -> Parser User
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Handle
-> Maybe Text
-> Maybe Text
-> Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User
User
(Handle
-> Maybe Text
-> Maybe Text
-> Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
-> Parser Handle
-> Parser
(Maybe Text
-> Maybe Text
-> Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object
v Object -> Text -> Parser Handle
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"handle")
Parser
(Maybe Text
-> Maybe Text
-> Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
-> Parser (Maybe Text)
-> Parser
(Maybe Text
-> Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"firstName")
Parser
(Maybe Text
-> Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
-> Parser (Maybe Text)
-> Parser
(Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"lastName")
Parser
(Rating
-> Rating
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rating
-> User)
-> Parser Rating
-> Parser
(Rating
-> Maybe Text -> Maybe Text -> Maybe Text -> Rating -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rating -> Maybe Rating -> Rating
forall a. a -> Maybe a -> a
fromMaybe Rating
0 (Maybe Rating -> Rating) -> Parser (Maybe Rating) -> Parser Rating
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser (Maybe Rating)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"rating")
Parser
(Rating
-> Maybe Text -> Maybe Text -> Maybe Text -> Rating -> User)
-> Parser Rating
-> Parser
(Maybe Text -> Maybe Text -> Maybe Text -> Rating -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rating -> Maybe Rating -> Rating
forall a. a -> Maybe a -> a
fromMaybe Rating
0 (Maybe Rating -> Rating) -> Parser (Maybe Rating) -> Parser Rating
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Text -> Parser (Maybe Rating)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"maxRating")
Parser (Maybe Text -> Maybe Text -> Maybe Text -> Rating -> User)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Rating -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"city")
Parser (Maybe Text -> Maybe Text -> Rating -> User)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Rating -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"country")
Parser (Maybe Text -> Rating -> User)
-> Parser (Maybe Text) -> Parser (Rating -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
"organization")
Parser (Rating -> User) -> Parser Rating -> Parser User
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Text -> Parser Rating
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"friendOfCount")