module TD.Data.GiftAuction
(GiftAuction(..)) 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 GiftAuction
= GiftAuction
{ GiftAuction -> Maybe Text
_id :: Maybe T.Text
, GiftAuction -> Maybe Int
gifts_per_round :: Maybe Int
, GiftAuction -> Maybe Int
start_date :: Maybe Int
}
deriving (GiftAuction -> GiftAuction -> Bool
(GiftAuction -> GiftAuction -> Bool)
-> (GiftAuction -> GiftAuction -> Bool) -> Eq GiftAuction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftAuction -> GiftAuction -> Bool
== :: GiftAuction -> GiftAuction -> Bool
$c/= :: GiftAuction -> GiftAuction -> Bool
/= :: GiftAuction -> GiftAuction -> Bool
Eq, Int -> GiftAuction -> ShowS
[GiftAuction] -> ShowS
GiftAuction -> String
(Int -> GiftAuction -> ShowS)
-> (GiftAuction -> String)
-> ([GiftAuction] -> ShowS)
-> Show GiftAuction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftAuction -> ShowS
showsPrec :: Int -> GiftAuction -> ShowS
$cshow :: GiftAuction -> String
show :: GiftAuction -> String
$cshowList :: [GiftAuction] -> ShowS
showList :: [GiftAuction] -> ShowS
Show)
instance I.ShortShow GiftAuction where
shortShow :: GiftAuction -> String
shortShow GiftAuction
{ _id :: GiftAuction -> Maybe Text
_id = Maybe Text
_id_
, gifts_per_round :: GiftAuction -> Maybe Int
gifts_per_round = Maybe Int
gifts_per_round_
, start_date :: GiftAuction -> Maybe Int
start_date = Maybe Int
start_date_
}
= String
"GiftAuction"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
, String
"gifts_per_round" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gifts_per_round_
, String
"start_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
start_date_
]
instance AT.FromJSON GiftAuction where
parseJSON :: Value -> Parser GiftAuction
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
"giftAuction" -> Value -> Parser GiftAuction
parseGiftAuction Value
v
String
_ -> Parser GiftAuction
forall a. Monoid a => a
mempty
where
parseGiftAuction :: A.Value -> AT.Parser GiftAuction
parseGiftAuction :: Value -> Parser GiftAuction
parseGiftAuction = String
-> (Object -> Parser GiftAuction) -> Value -> Parser GiftAuction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftAuction" ((Object -> Parser GiftAuction) -> Value -> Parser GiftAuction)
-> (Object -> Parser GiftAuction) -> Value -> Parser GiftAuction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Int
gifts_per_round_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gifts_per_round"
Maybe Int
start_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"start_date"
GiftAuction -> Parser GiftAuction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftAuction -> Parser GiftAuction)
-> GiftAuction -> Parser GiftAuction
forall a b. (a -> b) -> a -> b
$ GiftAuction
{ _id :: Maybe Text
_id = Maybe Text
_id_
, gifts_per_round :: Maybe Int
gifts_per_round = Maybe Int
gifts_per_round_
, start_date :: Maybe Int
start_date = Maybe Int
start_date_
}
parseJSON Value
_ = Parser GiftAuction
forall a. Monoid a => a
mempty