module TD.Data.WalletBotBalance
  (WalletBotBalance(..)) 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 WalletBotBalance
  = WalletBotBalance -- ^ Describes balance of the current user in the bot https://t.me/walt
    { WalletBotBalance -> Maybe Bool
has_balance :: Maybe Bool   -- ^ True, if the user has positive TON Gram balance
    , WalletBotBalance -> Maybe Text
url         :: Maybe T.Text -- ^ The URL to open to launch the bot; may be empty if none
    }
  deriving (WalletBotBalance -> WalletBotBalance -> Bool
(WalletBotBalance -> WalletBotBalance -> Bool)
-> (WalletBotBalance -> WalletBotBalance -> Bool)
-> Eq WalletBotBalance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WalletBotBalance -> WalletBotBalance -> Bool
== :: WalletBotBalance -> WalletBotBalance -> Bool
$c/= :: WalletBotBalance -> WalletBotBalance -> Bool
/= :: WalletBotBalance -> WalletBotBalance -> Bool
Eq, Int -> WalletBotBalance -> ShowS
[WalletBotBalance] -> ShowS
WalletBotBalance -> String
(Int -> WalletBotBalance -> ShowS)
-> (WalletBotBalance -> String)
-> ([WalletBotBalance] -> ShowS)
-> Show WalletBotBalance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WalletBotBalance -> ShowS
showsPrec :: Int -> WalletBotBalance -> ShowS
$cshow :: WalletBotBalance -> String
show :: WalletBotBalance -> String
$cshowList :: [WalletBotBalance] -> ShowS
showList :: [WalletBotBalance] -> ShowS
Show)

instance I.ShortShow WalletBotBalance where
  shortShow :: WalletBotBalance -> String
shortShow WalletBotBalance
    { has_balance :: WalletBotBalance -> Maybe Bool
has_balance = Maybe Bool
has_balance_
    , url :: WalletBotBalance -> Maybe Text
url         = Maybe Text
url_
    }
      = String
"WalletBotBalance"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"has_balance" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_balance_
        , String
"url"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        ]

instance AT.FromJSON WalletBotBalance where
  parseJSON :: Value -> Parser WalletBotBalance
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
"walletBotBalance" -> Value -> Parser WalletBotBalance
parseWalletBotBalance Value
v
      String
_                  -> Parser WalletBotBalance
forall a. Monoid a => a
mempty
    
    where
      parseWalletBotBalance :: A.Value -> AT.Parser WalletBotBalance
      parseWalletBotBalance :: Value -> Parser WalletBotBalance
parseWalletBotBalance = String
-> (Object -> Parser WalletBotBalance)
-> Value
-> Parser WalletBotBalance
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"WalletBotBalance" ((Object -> Parser WalletBotBalance)
 -> Value -> Parser WalletBotBalance)
-> (Object -> Parser WalletBotBalance)
-> Value
-> Parser WalletBotBalance
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
has_balance_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_balance"
        Maybe Text
url_         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        WalletBotBalance -> Parser WalletBotBalance
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WalletBotBalance -> Parser WalletBotBalance)
-> WalletBotBalance -> Parser WalletBotBalance
forall a b. (a -> b) -> a -> b
$ WalletBotBalance
          { has_balance :: Maybe Bool
has_balance = Maybe Bool
has_balance_
          , url :: Maybe Text
url         = Maybe Text
url_
          }
  parseJSON Value
_ = Parser WalletBotBalance
forall a. Monoid a => a
mempty