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 -- ^ Describes state of the stake dice
    { StakeDiceState -> Maybe Text
state_hash                   :: Maybe T.Text -- ^ Hash of the state to use for sending the next dice; may be empty if the stake dice can't be sent by the current user
    , StakeDiceState -> Maybe Int
stake_gram_amount            :: Maybe Int    -- ^ The amount of TON Grams staked in the previous roll; in the smallest units of the currency
    , StakeDiceState -> Maybe [Int]
suggested_stake_gram_amounts :: Maybe [Int]  -- ^ The amounts of Grams that are suggested to be staked; in the smallest units of the currency
    , StakeDiceState -> Maybe Int
current_streak               :: Maybe Int    -- ^ The number of rolled sixes towards the streak; 0-2
    , StakeDiceState -> Maybe [Int]
prize_per_mille              :: Maybe [Int]  -- ^ The number of Grams received by the user for each 1000 Grams staked if the dice outcome is 1-6 correspondingly; may be empty if the stake dice can't be sent by the current user
    , StakeDiceState -> Maybe Int
streak_prize_per_mille       :: Maybe Int    -- ^ The number of Grams received by the user for each 1000 Grams staked if the dice outcome is 6 three times in a row with the same stake
    }
  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_gram_amount :: StakeDiceState -> Maybe Int
stake_gram_amount            = Maybe Int
stake_gram_amount_
    , suggested_stake_gram_amounts :: StakeDiceState -> Maybe [Int]
suggested_stake_gram_amounts = Maybe [Int]
suggested_stake_gram_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_gram_amount"            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
stake_gram_amount_
        , String
"suggested_stake_gram_amounts" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
suggested_stake_gram_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_gram_amount_            <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"stake_gram_amount"
        Maybe [Int]
suggested_stake_gram_amounts_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"suggested_stake_gram_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_gram_amount :: Maybe Int
stake_gram_amount            = Maybe Int
stake_gram_amount_
          , suggested_stake_gram_amounts :: Maybe [Int]
suggested_stake_gram_amounts = Maybe [Int]
suggested_stake_gram_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