module TD.Data.ChatActionBar
(ChatActionBar(..)) 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
data ChatActionBar
= ChatActionBarReportSpam
{ ChatActionBar -> Maybe Bool
can_unarchive :: Maybe Bool
}
| ChatActionBarInviteMembers
| ChatActionBarReportAddBlock
{ can_unarchive :: Maybe Bool
}
| ChatActionBarAddContact
| ChatActionBarSharePhoneNumber
| ChatActionBarJoinRequest
{ ChatActionBar -> Maybe Text
title :: Maybe T.Text
, ChatActionBar -> Maybe Bool
is_channel :: Maybe Bool
, ChatActionBar -> Maybe Int
request_date :: Maybe Int
}
deriving (ChatActionBar -> ChatActionBar -> Bool
(ChatActionBar -> ChatActionBar -> Bool)
-> (ChatActionBar -> ChatActionBar -> Bool) -> Eq ChatActionBar
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatActionBar -> ChatActionBar -> Bool
== :: ChatActionBar -> ChatActionBar -> Bool
$c/= :: ChatActionBar -> ChatActionBar -> Bool
/= :: ChatActionBar -> ChatActionBar -> Bool
Eq, Int -> ChatActionBar -> ShowS
[ChatActionBar] -> ShowS
ChatActionBar -> String
(Int -> ChatActionBar -> ShowS)
-> (ChatActionBar -> String)
-> ([ChatActionBar] -> ShowS)
-> Show ChatActionBar
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatActionBar -> ShowS
showsPrec :: Int -> ChatActionBar -> ShowS
$cshow :: ChatActionBar -> String
show :: ChatActionBar -> String
$cshowList :: [ChatActionBar] -> ShowS
showList :: [ChatActionBar] -> ShowS
Show)
instance I.ShortShow ChatActionBar where
shortShow :: ChatActionBar -> String
shortShow ChatActionBarReportSpam
{ can_unarchive :: ChatActionBar -> Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
}
= String
"ChatActionBarReportSpam"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"can_unarchive" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_unarchive_
]
shortShow ChatActionBar
ChatActionBarInviteMembers
= String
"ChatActionBarInviteMembers"
shortShow ChatActionBarReportAddBlock
{ can_unarchive :: ChatActionBar -> Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
}
= String
"ChatActionBarReportAddBlock"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"can_unarchive" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_unarchive_
]
shortShow ChatActionBar
ChatActionBarAddContact
= String
"ChatActionBarAddContact"
shortShow ChatActionBar
ChatActionBarSharePhoneNumber
= String
"ChatActionBarSharePhoneNumber"
shortShow ChatActionBarJoinRequest
{ title :: ChatActionBar -> Maybe Text
title = Maybe Text
title_
, is_channel :: ChatActionBar -> Maybe Bool
is_channel = Maybe Bool
is_channel_
, request_date :: ChatActionBar -> Maybe Int
request_date = Maybe Int
request_date_
}
= String
"ChatActionBarJoinRequest"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"is_channel" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_channel_
, String
"request_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
request_date_
]
instance AT.FromJSON ChatActionBar where
parseJSON :: Value -> Parser ChatActionBar
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
"chatActionBarReportSpam" -> Value -> Parser ChatActionBar
parseChatActionBarReportSpam Value
v
String
"chatActionBarInviteMembers" -> ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatActionBar
ChatActionBarInviteMembers
String
"chatActionBarReportAddBlock" -> Value -> Parser ChatActionBar
parseChatActionBarReportAddBlock Value
v
String
"chatActionBarAddContact" -> ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatActionBar
ChatActionBarAddContact
String
"chatActionBarSharePhoneNumber" -> ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatActionBar
ChatActionBarSharePhoneNumber
String
"chatActionBarJoinRequest" -> Value -> Parser ChatActionBar
parseChatActionBarJoinRequest Value
v
String
_ -> Parser ChatActionBar
forall a. Monoid a => a
mempty
where
parseChatActionBarReportSpam :: A.Value -> AT.Parser ChatActionBar
parseChatActionBarReportSpam :: Value -> Parser ChatActionBar
parseChatActionBarReportSpam = String
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionBarReportSpam" ((Object -> Parser ChatActionBar) -> Value -> Parser ChatActionBar)
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
can_unarchive_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_unarchive"
ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActionBar -> Parser ChatActionBar)
-> ChatActionBar -> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ ChatActionBarReportSpam
{ can_unarchive :: Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
}
parseChatActionBarReportAddBlock :: A.Value -> AT.Parser ChatActionBar
parseChatActionBarReportAddBlock :: Value -> Parser ChatActionBar
parseChatActionBarReportAddBlock = String
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionBarReportAddBlock" ((Object -> Parser ChatActionBar) -> Value -> Parser ChatActionBar)
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
can_unarchive_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_unarchive"
ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActionBar -> Parser ChatActionBar)
-> ChatActionBar -> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ ChatActionBarReportAddBlock
{ can_unarchive :: Maybe Bool
can_unarchive = Maybe Bool
can_unarchive_
}
parseChatActionBarJoinRequest :: A.Value -> AT.Parser ChatActionBar
parseChatActionBarJoinRequest :: Value -> Parser ChatActionBar
parseChatActionBarJoinRequest = String
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionBarJoinRequest" ((Object -> Parser ChatActionBar) -> Value -> Parser ChatActionBar)
-> (Object -> Parser ChatActionBar)
-> Value
-> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe Bool
is_channel_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_channel"
Maybe Int
request_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"request_date"
ChatActionBar -> Parser ChatActionBar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatActionBar -> Parser ChatActionBar)
-> ChatActionBar -> Parser ChatActionBar
forall a b. (a -> b) -> a -> b
$ ChatActionBarJoinRequest
{ title :: Maybe Text
title = Maybe Text
title_
, is_channel :: Maybe Bool
is_channel = Maybe Bool
is_channel_
, request_date :: Maybe Int
request_date = Maybe Int
request_date_
}
parseJSON Value
_ = Parser ChatActionBar
forall a. Monoid a => a
mempty