module TD.Data.PrepaidGiveaway
(PrepaidGiveaway(..)) 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.GiveawayPrize as GiveawayPrize
data PrepaidGiveaway
= PrepaidGiveaway
{ PrepaidGiveaway -> Maybe Int
_id :: Maybe Int
, PrepaidGiveaway -> Maybe Int
winner_count :: Maybe Int
, PrepaidGiveaway -> Maybe GiveawayPrize
prize :: Maybe GiveawayPrize.GiveawayPrize
, PrepaidGiveaway -> Maybe Int
boost_count :: Maybe Int
, PrepaidGiveaway -> Maybe Int
payment_date :: Maybe Int
}
deriving (PrepaidGiveaway -> PrepaidGiveaway -> Bool
(PrepaidGiveaway -> PrepaidGiveaway -> Bool)
-> (PrepaidGiveaway -> PrepaidGiveaway -> Bool)
-> Eq PrepaidGiveaway
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrepaidGiveaway -> PrepaidGiveaway -> Bool
== :: PrepaidGiveaway -> PrepaidGiveaway -> Bool
$c/= :: PrepaidGiveaway -> PrepaidGiveaway -> Bool
/= :: PrepaidGiveaway -> PrepaidGiveaway -> Bool
Eq, Int -> PrepaidGiveaway -> ShowS
[PrepaidGiveaway] -> ShowS
PrepaidGiveaway -> String
(Int -> PrepaidGiveaway -> ShowS)
-> (PrepaidGiveaway -> String)
-> ([PrepaidGiveaway] -> ShowS)
-> Show PrepaidGiveaway
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrepaidGiveaway -> ShowS
showsPrec :: Int -> PrepaidGiveaway -> ShowS
$cshow :: PrepaidGiveaway -> String
show :: PrepaidGiveaway -> String
$cshowList :: [PrepaidGiveaway] -> ShowS
showList :: [PrepaidGiveaway] -> ShowS
Show)
instance I.ShortShow PrepaidGiveaway where
shortShow :: PrepaidGiveaway -> String
shortShow PrepaidGiveaway
{ _id :: PrepaidGiveaway -> Maybe Int
_id = Maybe Int
_id_
, winner_count :: PrepaidGiveaway -> Maybe Int
winner_count = Maybe Int
winner_count_
, prize :: PrepaidGiveaway -> Maybe GiveawayPrize
prize = Maybe GiveawayPrize
prize_
, boost_count :: PrepaidGiveaway -> Maybe Int
boost_count = Maybe Int
boost_count_
, payment_date :: PrepaidGiveaway -> Maybe Int
payment_date = Maybe Int
payment_date_
}
= String
"PrepaidGiveaway"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"winner_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
winner_count_
, String
"prize" String -> Maybe GiveawayPrize -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe GiveawayPrize
prize_
, String
"boost_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
boost_count_
, String
"payment_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
payment_date_
]
instance AT.FromJSON PrepaidGiveaway where
parseJSON :: Value -> Parser PrepaidGiveaway
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
"prepaidGiveaway" -> Value -> Parser PrepaidGiveaway
parsePrepaidGiveaway Value
v
String
_ -> Parser PrepaidGiveaway
forall a. Monoid a => a
mempty
where
parsePrepaidGiveaway :: A.Value -> AT.Parser PrepaidGiveaway
parsePrepaidGiveaway :: Value -> Parser PrepaidGiveaway
parsePrepaidGiveaway = String
-> (Object -> Parser PrepaidGiveaway)
-> Value
-> Parser PrepaidGiveaway
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PrepaidGiveaway" ((Object -> Parser PrepaidGiveaway)
-> Value -> Parser PrepaidGiveaway)
-> (Object -> Parser PrepaidGiveaway)
-> Value
-> Parser PrepaidGiveaway
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Int
winner_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"winner_count"
Maybe GiveawayPrize
prize_ <- Object
o Object -> Key -> Parser (Maybe GiveawayPrize)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"prize"
Maybe Int
boost_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"boost_count"
Maybe Int
payment_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"payment_date"
PrepaidGiveaway -> Parser PrepaidGiveaway
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PrepaidGiveaway -> Parser PrepaidGiveaway)
-> PrepaidGiveaway -> Parser PrepaidGiveaway
forall a b. (a -> b) -> a -> b
$ PrepaidGiveaway
{ _id :: Maybe Int
_id = Maybe Int
_id_
, winner_count :: Maybe Int
winner_count = Maybe Int
winner_count_
, prize :: Maybe GiveawayPrize
prize = Maybe GiveawayPrize
prize_
, boost_count :: Maybe Int
boost_count = Maybe Int
boost_count_
, payment_date :: Maybe Int
payment_date = Maybe Int
payment_date_
}
parseJSON Value
_ = Parser PrepaidGiveaway
forall a. Monoid a => a
mempty