module TD.Data.StarTransactions
  (StarTransactions(..)) 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.StarTransaction as StarTransaction
import qualified Data.Text as T

data StarTransactions
  = StarTransactions -- ^ Represents a list of Telegram Star transactions
    { StarTransactions -> Maybe Int
star_count   :: Maybe Int                               -- ^ The amount of owned Telegram Stars
    , StarTransactions -> Maybe [StarTransaction]
transactions :: Maybe [StarTransaction.StarTransaction] -- ^ List of transactions with Telegram Stars
    , StarTransactions -> Maybe Text
next_offset  :: Maybe T.Text                            -- ^ The offset for the next request. If empty, then there are no more results
    }
  deriving (StarTransactions -> StarTransactions -> Bool
(StarTransactions -> StarTransactions -> Bool)
-> (StarTransactions -> StarTransactions -> Bool)
-> Eq StarTransactions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarTransactions -> StarTransactions -> Bool
== :: StarTransactions -> StarTransactions -> Bool
$c/= :: StarTransactions -> StarTransactions -> Bool
/= :: StarTransactions -> StarTransactions -> Bool
Eq, Int -> StarTransactions -> ShowS
[StarTransactions] -> ShowS
StarTransactions -> String
(Int -> StarTransactions -> ShowS)
-> (StarTransactions -> String)
-> ([StarTransactions] -> ShowS)
-> Show StarTransactions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarTransactions -> ShowS
showsPrec :: Int -> StarTransactions -> ShowS
$cshow :: StarTransactions -> String
show :: StarTransactions -> String
$cshowList :: [StarTransactions] -> ShowS
showList :: [StarTransactions] -> ShowS
Show)

instance I.ShortShow StarTransactions where
  shortShow :: StarTransactions -> String
shortShow StarTransactions
    { star_count :: StarTransactions -> Maybe Int
star_count   = Maybe Int
star_count_
    , transactions :: StarTransactions -> Maybe [StarTransaction]
transactions = Maybe [StarTransaction]
transactions_
    , next_offset :: StarTransactions -> Maybe Text
next_offset  = Maybe Text
next_offset_
    }
      = String
"StarTransactions"
        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
"transactions" String -> Maybe [StarTransaction] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [StarTransaction]
transactions_
        , String
"next_offset"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
        ]

instance AT.FromJSON StarTransactions where
  parseJSON :: Value -> Parser StarTransactions
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
"starTransactions" -> Value -> Parser StarTransactions
parseStarTransactions Value
v
      String
_                  -> Parser StarTransactions
forall a. Monoid a => a
mempty
    
    where
      parseStarTransactions :: A.Value -> AT.Parser StarTransactions
      parseStarTransactions :: Value -> Parser StarTransactions
parseStarTransactions = String
-> (Object -> Parser StarTransactions)
-> Value
-> Parser StarTransactions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarTransactions" ((Object -> Parser StarTransactions)
 -> Value -> Parser StarTransactions)
-> (Object -> Parser StarTransactions)
-> Value
-> Parser StarTransactions
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 [StarTransaction]
transactions_ <- Object
o Object -> Key -> Parser (Maybe [StarTransaction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"transactions"
        Maybe Text
next_offset_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_offset"
        StarTransactions -> Parser StarTransactions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarTransactions -> Parser StarTransactions)
-> StarTransactions -> Parser StarTransactions
forall a b. (a -> b) -> a -> b
$ StarTransactions
          { star_count :: Maybe Int
star_count   = Maybe Int
star_count_
          , transactions :: Maybe [StarTransaction]
transactions = Maybe [StarTransaction]
transactions_
          , next_offset :: Maybe Text
next_offset  = Maybe Text
next_offset_
          }
  parseJSON Value
_ = Parser StarTransactions
forall a. Monoid a => a
mempty