module TD.Data.StarRevenueStatus
  (StarRevenueStatus(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.StarAmount as StarAmount

data StarRevenueStatus
  = StarRevenueStatus -- ^ Contains information about Telegram Stars earned by a bot or a chat
    { StarRevenueStatus -> Maybe StarAmount
total_amount       :: Maybe StarAmount.StarAmount -- ^ Total amount of Telegram Stars earned
    , StarRevenueStatus -> Maybe StarAmount
current_amount     :: Maybe StarAmount.StarAmount -- ^ The amount of Telegram Stars that aren't withdrawn yet
    , StarRevenueStatus -> Maybe StarAmount
available_amount   :: Maybe StarAmount.StarAmount -- ^ The amount of Telegram Stars that are available for withdrawal
    , StarRevenueStatus -> Maybe Bool
withdrawal_enabled :: Maybe Bool                  -- ^ True, if Telegram Stars can be withdrawn now or later
    , StarRevenueStatus -> Maybe Int
next_withdrawal_in :: Maybe Int                   -- ^ Time left before the next withdrawal can be started, in seconds; 0 if withdrawal can be started now
    }
  deriving (StarRevenueStatus -> StarRevenueStatus -> Bool
(StarRevenueStatus -> StarRevenueStatus -> Bool)
-> (StarRevenueStatus -> StarRevenueStatus -> Bool)
-> Eq StarRevenueStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarRevenueStatus -> StarRevenueStatus -> Bool
== :: StarRevenueStatus -> StarRevenueStatus -> Bool
$c/= :: StarRevenueStatus -> StarRevenueStatus -> Bool
/= :: StarRevenueStatus -> StarRevenueStatus -> Bool
Eq, Int -> StarRevenueStatus -> ShowS
[StarRevenueStatus] -> ShowS
StarRevenueStatus -> String
(Int -> StarRevenueStatus -> ShowS)
-> (StarRevenueStatus -> String)
-> ([StarRevenueStatus] -> ShowS)
-> Show StarRevenueStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarRevenueStatus -> ShowS
showsPrec :: Int -> StarRevenueStatus -> ShowS
$cshow :: StarRevenueStatus -> String
show :: StarRevenueStatus -> String
$cshowList :: [StarRevenueStatus] -> ShowS
showList :: [StarRevenueStatus] -> ShowS
Show)

instance I.ShortShow StarRevenueStatus where
  shortShow :: StarRevenueStatus -> String
shortShow StarRevenueStatus
    { total_amount :: StarRevenueStatus -> Maybe StarAmount
total_amount       = Maybe StarAmount
total_amount_
    , current_amount :: StarRevenueStatus -> Maybe StarAmount
current_amount     = Maybe StarAmount
current_amount_
    , available_amount :: StarRevenueStatus -> Maybe StarAmount
available_amount   = Maybe StarAmount
available_amount_
    , withdrawal_enabled :: StarRevenueStatus -> Maybe Bool
withdrawal_enabled = Maybe Bool
withdrawal_enabled_
    , next_withdrawal_in :: StarRevenueStatus -> Maybe Int
next_withdrawal_in = Maybe Int
next_withdrawal_in_
    }
      = String
"StarRevenueStatus"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"total_amount"       String -> Maybe StarAmount -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarAmount
total_amount_
        , String
"current_amount"     String -> Maybe StarAmount -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarAmount
current_amount_
        , String
"available_amount"   String -> Maybe StarAmount -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarAmount
available_amount_
        , String
"withdrawal_enabled" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
withdrawal_enabled_
        , String
"next_withdrawal_in" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
next_withdrawal_in_
        ]

instance AT.FromJSON StarRevenueStatus where
  parseJSON :: Value -> Parser StarRevenueStatus
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
"starRevenueStatus" -> Value -> Parser StarRevenueStatus
parseStarRevenueStatus Value
v
      String
_                   -> Parser StarRevenueStatus
forall a. Monoid a => a
mempty
    
    where
      parseStarRevenueStatus :: A.Value -> AT.Parser StarRevenueStatus
      parseStarRevenueStatus :: Value -> Parser StarRevenueStatus
parseStarRevenueStatus = String
-> (Object -> Parser StarRevenueStatus)
-> Value
-> Parser StarRevenueStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarRevenueStatus" ((Object -> Parser StarRevenueStatus)
 -> Value -> Parser StarRevenueStatus)
-> (Object -> Parser StarRevenueStatus)
-> Value
-> Parser StarRevenueStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe StarAmount
total_amount_       <- Object
o Object -> Key -> Parser (Maybe StarAmount)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_amount"
        Maybe StarAmount
current_amount_     <- Object
o Object -> Key -> Parser (Maybe StarAmount)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"current_amount"
        Maybe StarAmount
available_amount_   <- Object
o Object -> Key -> Parser (Maybe StarAmount)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"available_amount"
        Maybe Bool
withdrawal_enabled_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"withdrawal_enabled"
        Maybe Int
next_withdrawal_in_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_withdrawal_in"
        StarRevenueStatus -> Parser StarRevenueStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarRevenueStatus -> Parser StarRevenueStatus)
-> StarRevenueStatus -> Parser StarRevenueStatus
forall a b. (a -> b) -> a -> b
$ StarRevenueStatus
          { total_amount :: Maybe StarAmount
total_amount       = Maybe StarAmount
total_amount_
          , current_amount :: Maybe StarAmount
current_amount     = Maybe StarAmount
current_amount_
          , available_amount :: Maybe StarAmount
available_amount   = Maybe StarAmount
available_amount_
          , withdrawal_enabled :: Maybe Bool
withdrawal_enabled = Maybe Bool
withdrawal_enabled_
          , next_withdrawal_in :: Maybe Int
next_withdrawal_in = Maybe Int
next_withdrawal_in_
          }
  parseJSON Value
_ = Parser StarRevenueStatus
forall a. Monoid a => a
mempty