module TD.Data.GiveawayInfo
(GiveawayInfo(..)) 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.GiveawayParticipantStatus as GiveawayParticipantStatus
import qualified Data.Text as T
data GiveawayInfo
= GiveawayInfoOngoing
{ GiveawayInfo -> Maybe Int
creation_date :: Maybe Int
, GiveawayInfo -> Maybe GiveawayParticipantStatus
status :: Maybe GiveawayParticipantStatus.GiveawayParticipantStatus
, GiveawayInfo -> Maybe Bool
is_ended :: Maybe Bool
}
| GiveawayInfoCompleted
{ creation_date :: Maybe Int
, GiveawayInfo -> Maybe Int
actual_winners_selection_date :: Maybe Int
, GiveawayInfo -> Maybe Bool
was_refunded :: Maybe Bool
, GiveawayInfo -> Maybe Bool
is_winner :: Maybe Bool
, GiveawayInfo -> Maybe Int
winner_count :: Maybe Int
, GiveawayInfo -> Maybe Int
activation_count :: Maybe Int
, GiveawayInfo -> Maybe Text
gift_code :: Maybe T.Text
, GiveawayInfo -> Maybe Int
won_star_count :: Maybe Int
}
deriving (GiveawayInfo -> GiveawayInfo -> Bool
(GiveawayInfo -> GiveawayInfo -> Bool)
-> (GiveawayInfo -> GiveawayInfo -> Bool) -> Eq GiveawayInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiveawayInfo -> GiveawayInfo -> Bool
== :: GiveawayInfo -> GiveawayInfo -> Bool
$c/= :: GiveawayInfo -> GiveawayInfo -> Bool
/= :: GiveawayInfo -> GiveawayInfo -> Bool
Eq, Int -> GiveawayInfo -> ShowS
[GiveawayInfo] -> ShowS
GiveawayInfo -> String
(Int -> GiveawayInfo -> ShowS)
-> (GiveawayInfo -> String)
-> ([GiveawayInfo] -> ShowS)
-> Show GiveawayInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiveawayInfo -> ShowS
showsPrec :: Int -> GiveawayInfo -> ShowS
$cshow :: GiveawayInfo -> String
show :: GiveawayInfo -> String
$cshowList :: [GiveawayInfo] -> ShowS
showList :: [GiveawayInfo] -> ShowS
Show)
instance I.ShortShow GiveawayInfo where
shortShow :: GiveawayInfo -> String
shortShow GiveawayInfoOngoing
{ creation_date :: GiveawayInfo -> Maybe Int
creation_date = Maybe Int
creation_date_
, status :: GiveawayInfo -> Maybe GiveawayParticipantStatus
status = Maybe GiveawayParticipantStatus
status_
, is_ended :: GiveawayInfo -> Maybe Bool
is_ended = Maybe Bool
is_ended_
}
= String
"GiveawayInfoOngoing"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"creation_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
creation_date_
, String
"status" String -> Maybe GiveawayParticipantStatus -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe GiveawayParticipantStatus
status_
, String
"is_ended" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_ended_
]
shortShow GiveawayInfoCompleted
{ creation_date :: GiveawayInfo -> Maybe Int
creation_date = Maybe Int
creation_date_
, actual_winners_selection_date :: GiveawayInfo -> Maybe Int
actual_winners_selection_date = Maybe Int
actual_winners_selection_date_
, was_refunded :: GiveawayInfo -> Maybe Bool
was_refunded = Maybe Bool
was_refunded_
, is_winner :: GiveawayInfo -> Maybe Bool
is_winner = Maybe Bool
is_winner_
, winner_count :: GiveawayInfo -> Maybe Int
winner_count = Maybe Int
winner_count_
, activation_count :: GiveawayInfo -> Maybe Int
activation_count = Maybe Int
activation_count_
, gift_code :: GiveawayInfo -> Maybe Text
gift_code = Maybe Text
gift_code_
, won_star_count :: GiveawayInfo -> Maybe Int
won_star_count = Maybe Int
won_star_count_
}
= String
"GiveawayInfoCompleted"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"creation_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
creation_date_
, String
"actual_winners_selection_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
actual_winners_selection_date_
, String
"was_refunded" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
was_refunded_
, String
"is_winner" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_winner_
, String
"winner_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
winner_count_
, String
"activation_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
activation_count_
, String
"gift_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
gift_code_
, String
"won_star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
won_star_count_
]
instance AT.FromJSON GiveawayInfo where
parseJSON :: Value -> Parser GiveawayInfo
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
"giveawayInfoOngoing" -> Value -> Parser GiveawayInfo
parseGiveawayInfoOngoing Value
v
String
"giveawayInfoCompleted" -> Value -> Parser GiveawayInfo
parseGiveawayInfoCompleted Value
v
String
_ -> Parser GiveawayInfo
forall a. Monoid a => a
mempty
where
parseGiveawayInfoOngoing :: A.Value -> AT.Parser GiveawayInfo
parseGiveawayInfoOngoing :: Value -> Parser GiveawayInfo
parseGiveawayInfoOngoing = String
-> (Object -> Parser GiveawayInfo) -> Value -> Parser GiveawayInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiveawayInfoOngoing" ((Object -> Parser GiveawayInfo) -> Value -> Parser GiveawayInfo)
-> (Object -> Parser GiveawayInfo) -> Value -> Parser GiveawayInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
creation_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"creation_date"
Maybe GiveawayParticipantStatus
status_ <- Object
o Object -> Key -> Parser (Maybe GiveawayParticipantStatus)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"status"
Maybe Bool
is_ended_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_ended"
GiveawayInfo -> Parser GiveawayInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiveawayInfo -> Parser GiveawayInfo)
-> GiveawayInfo -> Parser GiveawayInfo
forall a b. (a -> b) -> a -> b
$ GiveawayInfoOngoing
{ creation_date :: Maybe Int
creation_date = Maybe Int
creation_date_
, status :: Maybe GiveawayParticipantStatus
status = Maybe GiveawayParticipantStatus
status_
, is_ended :: Maybe Bool
is_ended = Maybe Bool
is_ended_
}
parseGiveawayInfoCompleted :: A.Value -> AT.Parser GiveawayInfo
parseGiveawayInfoCompleted :: Value -> Parser GiveawayInfo
parseGiveawayInfoCompleted = String
-> (Object -> Parser GiveawayInfo) -> Value -> Parser GiveawayInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiveawayInfoCompleted" ((Object -> Parser GiveawayInfo) -> Value -> Parser GiveawayInfo)
-> (Object -> Parser GiveawayInfo) -> Value -> Parser GiveawayInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
creation_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"creation_date"
Maybe Int
actual_winners_selection_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"actual_winners_selection_date"
Maybe Bool
was_refunded_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"was_refunded"
Maybe Bool
is_winner_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_winner"
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 Int
activation_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"activation_count"
Maybe Text
gift_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gift_code"
Maybe Int
won_star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"won_star_count"
GiveawayInfo -> Parser GiveawayInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiveawayInfo -> Parser GiveawayInfo)
-> GiveawayInfo -> Parser GiveawayInfo
forall a b. (a -> b) -> a -> b
$ GiveawayInfoCompleted
{ creation_date :: Maybe Int
creation_date = Maybe Int
creation_date_
, actual_winners_selection_date :: Maybe Int
actual_winners_selection_date = Maybe Int
actual_winners_selection_date_
, was_refunded :: Maybe Bool
was_refunded = Maybe Bool
was_refunded_
, is_winner :: Maybe Bool
is_winner = Maybe Bool
is_winner_
, winner_count :: Maybe Int
winner_count = Maybe Int
winner_count_
, activation_count :: Maybe Int
activation_count = Maybe Int
activation_count_
, gift_code :: Maybe Text
gift_code = Maybe Text
gift_code_
, won_star_count :: Maybe Int
won_star_count = Maybe Int
won_star_count_
}
parseJSON Value
_ = Parser GiveawayInfo
forall a. Monoid a => a
mempty