module TD.Data.StarSubscriptions
(StarSubscriptions(..)) 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.StarAmount as StarAmount
import qualified TD.Data.StarSubscription as StarSubscription
import qualified Data.Text as T
data StarSubscriptions
= StarSubscriptions
{ StarSubscriptions -> Maybe StarAmount
star_amount :: Maybe StarAmount.StarAmount
, StarSubscriptions -> Maybe [StarSubscription]
subscriptions :: Maybe [StarSubscription.StarSubscription]
, StarSubscriptions -> Maybe Int
required_star_count :: Maybe Int
, StarSubscriptions -> Maybe Text
next_offset :: Maybe T.Text
}
deriving (StarSubscriptions -> StarSubscriptions -> Bool
(StarSubscriptions -> StarSubscriptions -> Bool)
-> (StarSubscriptions -> StarSubscriptions -> Bool)
-> Eq StarSubscriptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarSubscriptions -> StarSubscriptions -> Bool
== :: StarSubscriptions -> StarSubscriptions -> Bool
$c/= :: StarSubscriptions -> StarSubscriptions -> Bool
/= :: StarSubscriptions -> StarSubscriptions -> Bool
Eq, Int -> StarSubscriptions -> ShowS
[StarSubscriptions] -> ShowS
StarSubscriptions -> String
(Int -> StarSubscriptions -> ShowS)
-> (StarSubscriptions -> String)
-> ([StarSubscriptions] -> ShowS)
-> Show StarSubscriptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarSubscriptions -> ShowS
showsPrec :: Int -> StarSubscriptions -> ShowS
$cshow :: StarSubscriptions -> String
show :: StarSubscriptions -> String
$cshowList :: [StarSubscriptions] -> ShowS
showList :: [StarSubscriptions] -> ShowS
Show)
instance I.ShortShow StarSubscriptions where
shortShow :: StarSubscriptions -> String
shortShow StarSubscriptions
{ star_amount :: StarSubscriptions -> Maybe StarAmount
star_amount = Maybe StarAmount
star_amount_
, subscriptions :: StarSubscriptions -> Maybe [StarSubscription]
subscriptions = Maybe [StarSubscription]
subscriptions_
, required_star_count :: StarSubscriptions -> Maybe Int
required_star_count = Maybe Int
required_star_count_
, next_offset :: StarSubscriptions -> Maybe Text
next_offset = Maybe Text
next_offset_
}
= String
"StarSubscriptions"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"star_amount" String -> Maybe StarAmount -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarAmount
star_amount_
, String
"subscriptions" String -> Maybe [StarSubscription] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [StarSubscription]
subscriptions_
, String
"required_star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
required_star_count_
, String
"next_offset" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
]
instance AT.FromJSON StarSubscriptions where
parseJSON :: Value -> Parser StarSubscriptions
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
"starSubscriptions" -> Value -> Parser StarSubscriptions
parseStarSubscriptions Value
v
String
_ -> Parser StarSubscriptions
forall a. Monoid a => a
mempty
where
parseStarSubscriptions :: A.Value -> AT.Parser StarSubscriptions
parseStarSubscriptions :: Value -> Parser StarSubscriptions
parseStarSubscriptions = String
-> (Object -> Parser StarSubscriptions)
-> Value
-> Parser StarSubscriptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarSubscriptions" ((Object -> Parser StarSubscriptions)
-> Value -> Parser StarSubscriptions)
-> (Object -> Parser StarSubscriptions)
-> Value
-> Parser StarSubscriptions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe StarAmount
star_amount_ <- Object
o Object -> Key -> Parser (Maybe StarAmount)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"star_amount"
Maybe [StarSubscription]
subscriptions_ <- Object
o Object -> Key -> Parser (Maybe [StarSubscription])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"subscriptions"
Maybe Int
required_star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"required_star_count"
Maybe Text
next_offset_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"next_offset"
StarSubscriptions -> Parser StarSubscriptions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarSubscriptions -> Parser StarSubscriptions)
-> StarSubscriptions -> Parser StarSubscriptions
forall a b. (a -> b) -> a -> b
$ StarSubscriptions
{ star_amount :: Maybe StarAmount
star_amount = Maybe StarAmount
star_amount_
, subscriptions :: Maybe [StarSubscription]
subscriptions = Maybe [StarSubscription]
subscriptions_
, required_star_count :: Maybe Int
required_star_count = Maybe Int
required_star_count_
, next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
}
parseJSON Value
_ = Parser StarSubscriptions
forall a. Monoid a => a
mempty