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