module TD.Data.StarSubscriptionType
(StarSubscriptionType(..)) 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.Photo as Photo
data StarSubscriptionType
= StarSubscriptionTypeChannel
{ StarSubscriptionType -> Maybe Bool
can_reuse :: Maybe Bool
, StarSubscriptionType -> Maybe Text
invite_link :: Maybe T.Text
}
| StarSubscriptionTypeBot
{ StarSubscriptionType -> Maybe Bool
is_canceled_by_bot :: Maybe Bool
, StarSubscriptionType -> Maybe Text
title :: Maybe T.Text
, StarSubscriptionType -> Maybe Photo
photo :: Maybe Photo.Photo
, StarSubscriptionType -> Maybe Text
invoice_link :: Maybe T.Text
}
deriving (StarSubscriptionType -> StarSubscriptionType -> Bool
(StarSubscriptionType -> StarSubscriptionType -> Bool)
-> (StarSubscriptionType -> StarSubscriptionType -> Bool)
-> Eq StarSubscriptionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarSubscriptionType -> StarSubscriptionType -> Bool
== :: StarSubscriptionType -> StarSubscriptionType -> Bool
$c/= :: StarSubscriptionType -> StarSubscriptionType -> Bool
/= :: StarSubscriptionType -> StarSubscriptionType -> Bool
Eq, Int -> StarSubscriptionType -> ShowS
[StarSubscriptionType] -> ShowS
StarSubscriptionType -> String
(Int -> StarSubscriptionType -> ShowS)
-> (StarSubscriptionType -> String)
-> ([StarSubscriptionType] -> ShowS)
-> Show StarSubscriptionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarSubscriptionType -> ShowS
showsPrec :: Int -> StarSubscriptionType -> ShowS
$cshow :: StarSubscriptionType -> String
show :: StarSubscriptionType -> String
$cshowList :: [StarSubscriptionType] -> ShowS
showList :: [StarSubscriptionType] -> ShowS
Show)
instance I.ShortShow StarSubscriptionType where
shortShow :: StarSubscriptionType -> String
shortShow StarSubscriptionTypeChannel
{ can_reuse :: StarSubscriptionType -> Maybe Bool
can_reuse = Maybe Bool
can_reuse_
, invite_link :: StarSubscriptionType -> Maybe Text
invite_link = Maybe Text
invite_link_
}
= String
"StarSubscriptionTypeChannel"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"can_reuse" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_reuse_
, String
"invite_link" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
invite_link_
]
shortShow StarSubscriptionTypeBot
{ is_canceled_by_bot :: StarSubscriptionType -> Maybe Bool
is_canceled_by_bot = Maybe Bool
is_canceled_by_bot_
, title :: StarSubscriptionType -> Maybe Text
title = Maybe Text
title_
, photo :: StarSubscriptionType -> Maybe Photo
photo = Maybe Photo
photo_
, invoice_link :: StarSubscriptionType -> Maybe Text
invoice_link = Maybe Text
invoice_link_
}
= String
"StarSubscriptionTypeBot"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"is_canceled_by_bot" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_canceled_by_bot_
, String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"photo" String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
, String
"invoice_link" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
invoice_link_
]
instance AT.FromJSON StarSubscriptionType where
parseJSON :: Value -> Parser StarSubscriptionType
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
"starSubscriptionTypeChannel" -> Value -> Parser StarSubscriptionType
parseStarSubscriptionTypeChannel Value
v
String
"starSubscriptionTypeBot" -> Value -> Parser StarSubscriptionType
parseStarSubscriptionTypeBot Value
v
String
_ -> Parser StarSubscriptionType
forall a. Monoid a => a
mempty
where
parseStarSubscriptionTypeChannel :: A.Value -> AT.Parser StarSubscriptionType
parseStarSubscriptionTypeChannel :: Value -> Parser StarSubscriptionType
parseStarSubscriptionTypeChannel = String
-> (Object -> Parser StarSubscriptionType)
-> Value
-> Parser StarSubscriptionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarSubscriptionTypeChannel" ((Object -> Parser StarSubscriptionType)
-> Value -> Parser StarSubscriptionType)
-> (Object -> Parser StarSubscriptionType)
-> Value
-> Parser StarSubscriptionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
can_reuse_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_reuse"
Maybe Text
invite_link_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"invite_link"
StarSubscriptionType -> Parser StarSubscriptionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarSubscriptionType -> Parser StarSubscriptionType)
-> StarSubscriptionType -> Parser StarSubscriptionType
forall a b. (a -> b) -> a -> b
$ StarSubscriptionTypeChannel
{ can_reuse :: Maybe Bool
can_reuse = Maybe Bool
can_reuse_
, invite_link :: Maybe Text
invite_link = Maybe Text
invite_link_
}
parseStarSubscriptionTypeBot :: A.Value -> AT.Parser StarSubscriptionType
parseStarSubscriptionTypeBot :: Value -> Parser StarSubscriptionType
parseStarSubscriptionTypeBot = String
-> (Object -> Parser StarSubscriptionType)
-> Value
-> Parser StarSubscriptionType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarSubscriptionTypeBot" ((Object -> Parser StarSubscriptionType)
-> Value -> Parser StarSubscriptionType)
-> (Object -> Parser StarSubscriptionType)
-> Value
-> Parser StarSubscriptionType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
is_canceled_by_bot_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_canceled_by_bot"
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe Photo
photo_ <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
Maybe Text
invoice_link_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"invoice_link"
StarSubscriptionType -> Parser StarSubscriptionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarSubscriptionType -> Parser StarSubscriptionType)
-> StarSubscriptionType -> Parser StarSubscriptionType
forall a b. (a -> b) -> a -> b
$ StarSubscriptionTypeBot
{ is_canceled_by_bot :: Maybe Bool
is_canceled_by_bot = Maybe Bool
is_canceled_by_bot_
, title :: Maybe Text
title = Maybe Text
title_
, photo :: Maybe Photo
photo = Maybe Photo
photo_
, invoice_link :: Maybe Text
invoice_link = Maybe Text
invoice_link_
}
parseJSON Value
_ = Parser StarSubscriptionType
forall a. Monoid a => a
mempty