module TD.Data.StarSubscription
(StarSubscription(..)) 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.StarSubscriptionPricing as StarSubscriptionPricing
import qualified TD.Data.StarSubscriptionType as StarSubscriptionType
data StarSubscription
= StarSubscription
{ StarSubscription -> Maybe Text
_id :: Maybe T.Text
, StarSubscription -> Maybe Int
chat_id :: Maybe Int
, StarSubscription -> Maybe Int
expiration_date :: Maybe Int
, StarSubscription -> Maybe Bool
is_canceled :: Maybe Bool
, StarSubscription -> Maybe Bool
is_expiring :: Maybe Bool
, StarSubscription -> Maybe StarSubscriptionPricing
pricing :: Maybe StarSubscriptionPricing.StarSubscriptionPricing
, StarSubscription -> Maybe StarSubscriptionType
_type :: Maybe StarSubscriptionType.StarSubscriptionType
}
deriving (StarSubscription -> StarSubscription -> Bool
(StarSubscription -> StarSubscription -> Bool)
-> (StarSubscription -> StarSubscription -> Bool)
-> Eq StarSubscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarSubscription -> StarSubscription -> Bool
== :: StarSubscription -> StarSubscription -> Bool
$c/= :: StarSubscription -> StarSubscription -> Bool
/= :: StarSubscription -> StarSubscription -> Bool
Eq, Int -> StarSubscription -> ShowS
[StarSubscription] -> ShowS
StarSubscription -> String
(Int -> StarSubscription -> ShowS)
-> (StarSubscription -> String)
-> ([StarSubscription] -> ShowS)
-> Show StarSubscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarSubscription -> ShowS
showsPrec :: Int -> StarSubscription -> ShowS
$cshow :: StarSubscription -> String
show :: StarSubscription -> String
$cshowList :: [StarSubscription] -> ShowS
showList :: [StarSubscription] -> ShowS
Show)
instance I.ShortShow StarSubscription where
shortShow :: StarSubscription -> String
shortShow StarSubscription
{ _id :: StarSubscription -> Maybe Text
_id = Maybe Text
_id_
, chat_id :: StarSubscription -> Maybe Int
chat_id = Maybe Int
chat_id_
, expiration_date :: StarSubscription -> Maybe Int
expiration_date = Maybe Int
expiration_date_
, is_canceled :: StarSubscription -> Maybe Bool
is_canceled = Maybe Bool
is_canceled_
, is_expiring :: StarSubscription -> Maybe Bool
is_expiring = Maybe Bool
is_expiring_
, pricing :: StarSubscription -> Maybe StarSubscriptionPricing
pricing = Maybe StarSubscriptionPricing
pricing_
, _type :: StarSubscription -> Maybe StarSubscriptionType
_type = Maybe StarSubscriptionType
_type_
}
= String
"StarSubscription"
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
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
, String
"expiration_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
, String
"is_canceled" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_canceled_
, String
"is_expiring" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_expiring_
, String
"pricing" String -> Maybe StarSubscriptionPricing -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarSubscriptionPricing
pricing_
, String
"_type" String -> Maybe StarSubscriptionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StarSubscriptionType
_type_
]
instance AT.FromJSON StarSubscription where
parseJSON :: Value -> Parser StarSubscription
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
"starSubscription" -> Value -> Parser StarSubscription
parseStarSubscription Value
v
String
_ -> Parser StarSubscription
forall a. Monoid a => a
mempty
where
parseStarSubscription :: A.Value -> AT.Parser StarSubscription
parseStarSubscription :: Value -> Parser StarSubscription
parseStarSubscription = String
-> (Object -> Parser StarSubscription)
-> Value
-> Parser StarSubscription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarSubscription" ((Object -> Parser StarSubscription)
-> Value -> Parser StarSubscription)
-> (Object -> Parser StarSubscription)
-> Value
-> Parser StarSubscription
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
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
Maybe Int
expiration_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"expiration_date"
Maybe Bool
is_canceled_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_canceled"
Maybe Bool
is_expiring_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_expiring"
Maybe StarSubscriptionPricing
pricing_ <- Object
o Object -> Key -> Parser (Maybe StarSubscriptionPricing)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"pricing"
Maybe StarSubscriptionType
_type_ <- Object
o Object -> Key -> Parser (Maybe StarSubscriptionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
StarSubscription -> Parser StarSubscription
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarSubscription -> Parser StarSubscription)
-> StarSubscription -> Parser StarSubscription
forall a b. (a -> b) -> a -> b
$ StarSubscription
{ _id :: Maybe Text
_id = Maybe Text
_id_
, chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
, expiration_date :: Maybe Int
expiration_date = Maybe Int
expiration_date_
, is_canceled :: Maybe Bool
is_canceled = Maybe Bool
is_canceled_
, is_expiring :: Maybe Bool
is_expiring = Maybe Bool
is_expiring_
, pricing :: Maybe StarSubscriptionPricing
pricing = Maybe StarSubscriptionPricing
pricing_
, _type :: Maybe StarSubscriptionType
_type = Maybe StarSubscriptionType
_type_
}
parseJSON Value
_ = Parser StarSubscription
forall a. Monoid a => a
mempty