module TD.Data.StakeDiceState
(StakeDiceState(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data StakeDiceState
= StakeDiceState
{ StakeDiceState -> Maybe Text
state_hash :: Maybe T.Text
, StakeDiceState -> Maybe Int
stake_toncoin_amount :: Maybe Int
, StakeDiceState -> Maybe [Int]
suggested_stake_toncoin_amounts :: Maybe [Int]
, StakeDiceState -> Maybe Int
current_streak :: Maybe Int
, StakeDiceState -> Maybe [Int]
prize_per_mille :: Maybe [Int]
, StakeDiceState -> Maybe Int
streak_prize_per_mille :: Maybe Int
}
deriving (StakeDiceState -> StakeDiceState -> Bool
(StakeDiceState -> StakeDiceState -> Bool)
-> (StakeDiceState -> StakeDiceState -> Bool) -> Eq StakeDiceState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StakeDiceState -> StakeDiceState -> Bool
== :: StakeDiceState -> StakeDiceState -> Bool
$c/= :: StakeDiceState -> StakeDiceState -> Bool
/= :: StakeDiceState -> StakeDiceState -> Bool
Eq, Int -> StakeDiceState -> ShowS
[StakeDiceState] -> ShowS
StakeDiceState -> String
(Int -> StakeDiceState -> ShowS)
-> (StakeDiceState -> String)
-> ([StakeDiceState] -> ShowS)
-> Show StakeDiceState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StakeDiceState -> ShowS
showsPrec :: Int -> StakeDiceState -> ShowS
$cshow :: StakeDiceState -> String
show :: StakeDiceState -> String
$cshowList :: [StakeDiceState] -> ShowS
showList :: [StakeDiceState] -> ShowS
Show)
instance I.ShortShow StakeDiceState where
shortShow :: StakeDiceState -> String
shortShow StakeDiceState
{ state_hash :: StakeDiceState -> Maybe Text
state_hash = Maybe Text
state_hash_
, stake_toncoin_amount :: StakeDiceState -> Maybe Int
stake_toncoin_amount = Maybe Int
stake_toncoin_amount_
, suggested_stake_toncoin_amounts :: StakeDiceState -> Maybe [Int]
suggested_stake_toncoin_amounts = Maybe [Int]
suggested_stake_toncoin_amounts_
, current_streak :: StakeDiceState -> Maybe Int
current_streak = Maybe Int
current_streak_
, prize_per_mille :: StakeDiceState -> Maybe [Int]
prize_per_mille = Maybe [Int]
prize_per_mille_
, streak_prize_per_mille :: StakeDiceState -> Maybe Int
streak_prize_per_mille = Maybe Int
streak_prize_per_mille_
}
= String
"StakeDiceState"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"state_hash" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
state_hash_
, String
"stake_toncoin_amount" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
stake_toncoin_amount_
, String
"suggested_stake_toncoin_amounts" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
suggested_stake_toncoin_amounts_
, String
"current_streak" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
current_streak_
, String
"prize_per_mille" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
prize_per_mille_
, String
"streak_prize_per_mille" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
streak_prize_per_mille_
]
instance AT.FromJSON StakeDiceState where
parseJSON :: Value -> Parser StakeDiceState
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
"stakeDiceState" -> Value -> Parser StakeDiceState
parseStakeDiceState Value
v
String
_ -> Parser StakeDiceState
forall a. Monoid a => a
mempty
where
parseStakeDiceState :: A.Value -> AT.Parser StakeDiceState
parseStakeDiceState :: Value -> Parser StakeDiceState
parseStakeDiceState = String
-> (Object -> Parser StakeDiceState)
-> Value
-> Parser StakeDiceState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StakeDiceState" ((Object -> Parser StakeDiceState)
-> Value -> Parser StakeDiceState)
-> (Object -> Parser StakeDiceState)
-> Value
-> Parser StakeDiceState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
state_hash_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"state_hash"
Maybe Int
stake_toncoin_amount_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"stake_toncoin_amount"
Maybe [Int]
suggested_stake_toncoin_amounts_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"suggested_stake_toncoin_amounts"
Maybe Int
current_streak_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"current_streak"
Maybe [Int]
prize_per_mille_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"prize_per_mille"
Maybe Int
streak_prize_per_mille_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"streak_prize_per_mille"
StakeDiceState -> Parser StakeDiceState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StakeDiceState -> Parser StakeDiceState)
-> StakeDiceState -> Parser StakeDiceState
forall a b. (a -> b) -> a -> b
$ StakeDiceState
{ state_hash :: Maybe Text
state_hash = Maybe Text
state_hash_
, stake_toncoin_amount :: Maybe Int
stake_toncoin_amount = Maybe Int
stake_toncoin_amount_
, suggested_stake_toncoin_amounts :: Maybe [Int]
suggested_stake_toncoin_amounts = Maybe [Int]
suggested_stake_toncoin_amounts_
, current_streak :: Maybe Int
current_streak = Maybe Int
current_streak_
, prize_per_mille :: Maybe [Int]
prize_per_mille = Maybe [Int]
prize_per_mille_
, streak_prize_per_mille :: Maybe Int
streak_prize_per_mille = Maybe Int
streak_prize_per_mille_
}
parseJSON Value
_ = Parser StakeDiceState
forall a. Monoid a => a
mempty