module TD.Data.UpgradedGift
(UpgradedGift(..)) 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
import qualified TD.Data.UpgradedGiftModel as UpgradedGiftModel
import qualified TD.Data.UpgradedGiftSymbol as UpgradedGiftSymbol
import qualified TD.Data.UpgradedGiftBackdrop as UpgradedGiftBackdrop
import qualified TD.Data.UpgradedGiftOriginalDetails as UpgradedGiftOriginalDetails
data UpgradedGift
= UpgradedGift
{ UpgradedGift -> Maybe Int
_id :: Maybe Int
, UpgradedGift -> Maybe Text
title :: Maybe T.Text
, UpgradedGift -> Maybe Int
number :: Maybe Int
, UpgradedGift -> Maybe Int
total_upgraded_count :: Maybe Int
, UpgradedGift -> Maybe Int
max_upgraded_count :: Maybe Int
, UpgradedGift -> Maybe Int
owner_user_id :: Maybe Int
, UpgradedGift -> Maybe UpgradedGiftModel
model :: Maybe UpgradedGiftModel.UpgradedGiftModel
, UpgradedGift -> Maybe UpgradedGiftSymbol
symbol :: Maybe UpgradedGiftSymbol.UpgradedGiftSymbol
, UpgradedGift -> Maybe UpgradedGiftBackdrop
backdrop :: Maybe UpgradedGiftBackdrop.UpgradedGiftBackdrop
, UpgradedGift -> Maybe UpgradedGiftOriginalDetails
original_details :: Maybe UpgradedGiftOriginalDetails.UpgradedGiftOriginalDetails
}
deriving (UpgradedGift -> UpgradedGift -> Bool
(UpgradedGift -> UpgradedGift -> Bool)
-> (UpgradedGift -> UpgradedGift -> Bool) -> Eq UpgradedGift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UpgradedGift -> UpgradedGift -> Bool
== :: UpgradedGift -> UpgradedGift -> Bool
$c/= :: UpgradedGift -> UpgradedGift -> Bool
/= :: UpgradedGift -> UpgradedGift -> Bool
Eq, Int -> UpgradedGift -> ShowS
[UpgradedGift] -> ShowS
UpgradedGift -> String
(Int -> UpgradedGift -> ShowS)
-> (UpgradedGift -> String)
-> ([UpgradedGift] -> ShowS)
-> Show UpgradedGift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UpgradedGift -> ShowS
showsPrec :: Int -> UpgradedGift -> ShowS
$cshow :: UpgradedGift -> String
show :: UpgradedGift -> String
$cshowList :: [UpgradedGift] -> ShowS
showList :: [UpgradedGift] -> ShowS
Show)
instance I.ShortShow UpgradedGift where
shortShow :: UpgradedGift -> String
shortShow UpgradedGift
{ _id :: UpgradedGift -> Maybe Int
_id = Maybe Int
_id_
, title :: UpgradedGift -> Maybe Text
title = Maybe Text
title_
, number :: UpgradedGift -> Maybe Int
number = Maybe Int
number_
, total_upgraded_count :: UpgradedGift -> Maybe Int
total_upgraded_count = Maybe Int
total_upgraded_count_
, max_upgraded_count :: UpgradedGift -> Maybe Int
max_upgraded_count = Maybe Int
max_upgraded_count_
, owner_user_id :: UpgradedGift -> Maybe Int
owner_user_id = Maybe Int
owner_user_id_
, model :: UpgradedGift -> Maybe UpgradedGiftModel
model = Maybe UpgradedGiftModel
model_
, symbol :: UpgradedGift -> Maybe UpgradedGiftSymbol
symbol = Maybe UpgradedGiftSymbol
symbol_
, backdrop :: UpgradedGift -> Maybe UpgradedGiftBackdrop
backdrop = Maybe UpgradedGiftBackdrop
backdrop_
, original_details :: UpgradedGift -> Maybe UpgradedGiftOriginalDetails
original_details = Maybe UpgradedGiftOriginalDetails
original_details_
}
= String
"UpgradedGift"
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
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"number" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
number_
, String
"total_upgraded_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_upgraded_count_
, String
"max_upgraded_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_upgraded_count_
, String
"owner_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
owner_user_id_
, String
"model" String -> Maybe UpgradedGiftModel -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftModel
model_
, String
"symbol" String -> Maybe UpgradedGiftSymbol -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftSymbol
symbol_
, String
"backdrop" String -> Maybe UpgradedGiftBackdrop -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftBackdrop
backdrop_
, String
"original_details" String -> Maybe UpgradedGiftOriginalDetails -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe UpgradedGiftOriginalDetails
original_details_
]
instance AT.FromJSON UpgradedGift where
parseJSON :: Value -> Parser UpgradedGift
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
"upgradedGift" -> Value -> Parser UpgradedGift
parseUpgradedGift Value
v
String
_ -> Parser UpgradedGift
forall a. Monoid a => a
mempty
where
parseUpgradedGift :: A.Value -> AT.Parser UpgradedGift
parseUpgradedGift :: Value -> Parser UpgradedGift
parseUpgradedGift = String
-> (Object -> Parser UpgradedGift) -> Value -> Parser UpgradedGift
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"UpgradedGift" ((Object -> Parser UpgradedGift) -> Value -> Parser UpgradedGift)
-> (Object -> Parser UpgradedGift) -> Value -> Parser UpgradedGift
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 Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe Int
number_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"number"
Maybe Int
total_upgraded_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"total_upgraded_count"
Maybe Int
max_upgraded_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"max_upgraded_count"
Maybe Int
owner_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"owner_user_id"
Maybe UpgradedGiftModel
model_ <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftModel)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"model"
Maybe UpgradedGiftSymbol
symbol_ <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftSymbol)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"symbol"
Maybe UpgradedGiftBackdrop
backdrop_ <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftBackdrop)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"backdrop"
Maybe UpgradedGiftOriginalDetails
original_details_ <- Object
o Object -> Key -> Parser (Maybe UpgradedGiftOriginalDetails)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"original_details"
UpgradedGift -> Parser UpgradedGift
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UpgradedGift -> Parser UpgradedGift)
-> UpgradedGift -> Parser UpgradedGift
forall a b. (a -> b) -> a -> b
$ UpgradedGift
{ _id :: Maybe Int
_id = Maybe Int
_id_
, title :: Maybe Text
title = Maybe Text
title_
, number :: Maybe Int
number = Maybe Int
number_
, total_upgraded_count :: Maybe Int
total_upgraded_count = Maybe Int
total_upgraded_count_
, max_upgraded_count :: Maybe Int
max_upgraded_count = Maybe Int
max_upgraded_count_
, owner_user_id :: Maybe Int
owner_user_id = Maybe Int
owner_user_id_
, model :: Maybe UpgradedGiftModel
model = Maybe UpgradedGiftModel
model_
, symbol :: Maybe UpgradedGiftSymbol
symbol = Maybe UpgradedGiftSymbol
symbol_
, backdrop :: Maybe UpgradedGiftBackdrop
backdrop = Maybe UpgradedGiftBackdrop
backdrop_
, original_details :: Maybe UpgradedGiftOriginalDetails
original_details = Maybe UpgradedGiftOriginalDetails
original_details_
}
parseJSON Value
_ = Parser UpgradedGift
forall a. Monoid a => a
mempty