module TD.Data.GiftAuctionState
(GiftAuctionState(..)) 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.Gift as Gift
import qualified TD.Data.AuctionState as AuctionState
data GiftAuctionState
= GiftAuctionState
{ GiftAuctionState -> Maybe Gift
gift :: Maybe Gift.Gift
, GiftAuctionState -> Maybe AuctionState
state :: Maybe AuctionState.AuctionState
}
deriving (GiftAuctionState -> GiftAuctionState -> Bool
(GiftAuctionState -> GiftAuctionState -> Bool)
-> (GiftAuctionState -> GiftAuctionState -> Bool)
-> Eq GiftAuctionState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiftAuctionState -> GiftAuctionState -> Bool
== :: GiftAuctionState -> GiftAuctionState -> Bool
$c/= :: GiftAuctionState -> GiftAuctionState -> Bool
/= :: GiftAuctionState -> GiftAuctionState -> Bool
Eq, Int -> GiftAuctionState -> ShowS
[GiftAuctionState] -> ShowS
GiftAuctionState -> String
(Int -> GiftAuctionState -> ShowS)
-> (GiftAuctionState -> String)
-> ([GiftAuctionState] -> ShowS)
-> Show GiftAuctionState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GiftAuctionState -> ShowS
showsPrec :: Int -> GiftAuctionState -> ShowS
$cshow :: GiftAuctionState -> String
show :: GiftAuctionState -> String
$cshowList :: [GiftAuctionState] -> ShowS
showList :: [GiftAuctionState] -> ShowS
Show)
instance I.ShortShow GiftAuctionState where
shortShow :: GiftAuctionState -> String
shortShow GiftAuctionState
{ gift :: GiftAuctionState -> Maybe Gift
gift = Maybe Gift
gift_
, state :: GiftAuctionState -> Maybe AuctionState
state = Maybe AuctionState
state_
}
= String
"GiftAuctionState"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"gift" String -> Maybe Gift -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Gift
gift_
, String
"state" String -> Maybe AuctionState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AuctionState
state_
]
instance AT.FromJSON GiftAuctionState where
parseJSON :: Value -> Parser GiftAuctionState
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
"giftAuctionState" -> Value -> Parser GiftAuctionState
parseGiftAuctionState Value
v
String
_ -> Parser GiftAuctionState
forall a. Monoid a => a
mempty
where
parseGiftAuctionState :: A.Value -> AT.Parser GiftAuctionState
parseGiftAuctionState :: Value -> Parser GiftAuctionState
parseGiftAuctionState = String
-> (Object -> Parser GiftAuctionState)
-> Value
-> Parser GiftAuctionState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GiftAuctionState" ((Object -> Parser GiftAuctionState)
-> Value -> Parser GiftAuctionState)
-> (Object -> Parser GiftAuctionState)
-> Value
-> Parser GiftAuctionState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Gift
gift_ <- Object
o Object -> Key -> Parser (Maybe Gift)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gift"
Maybe AuctionState
state_ <- Object
o Object -> Key -> Parser (Maybe AuctionState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"state"
GiftAuctionState -> Parser GiftAuctionState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GiftAuctionState -> Parser GiftAuctionState)
-> GiftAuctionState -> Parser GiftAuctionState
forall a b. (a -> b) -> a -> b
$ GiftAuctionState
{ gift :: Maybe Gift
gift = Maybe Gift
gift_
, state :: Maybe AuctionState
state = Maybe AuctionState
state_
}
parseJSON Value
_ = Parser GiftAuctionState
forall a. Monoid a => a
mempty