module TD.Data.ChatMembersFilter
(ChatMembersFilter(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data ChatMembersFilter
= ChatMembersFilterContacts
| ChatMembersFilterAdministrators
| ChatMembersFilterMembers
| ChatMembersFilterMention
{ ChatMembersFilter -> Maybe Int
message_thread_id :: Maybe Int
}
| ChatMembersFilterRestricted
| ChatMembersFilterBanned
| ChatMembersFilterBots
deriving (ChatMembersFilter -> ChatMembersFilter -> Bool
(ChatMembersFilter -> ChatMembersFilter -> Bool)
-> (ChatMembersFilter -> ChatMembersFilter -> Bool)
-> Eq ChatMembersFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatMembersFilter -> ChatMembersFilter -> Bool
== :: ChatMembersFilter -> ChatMembersFilter -> Bool
$c/= :: ChatMembersFilter -> ChatMembersFilter -> Bool
/= :: ChatMembersFilter -> ChatMembersFilter -> Bool
Eq, Int -> ChatMembersFilter -> ShowS
[ChatMembersFilter] -> ShowS
ChatMembersFilter -> String
(Int -> ChatMembersFilter -> ShowS)
-> (ChatMembersFilter -> String)
-> ([ChatMembersFilter] -> ShowS)
-> Show ChatMembersFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatMembersFilter -> ShowS
showsPrec :: Int -> ChatMembersFilter -> ShowS
$cshow :: ChatMembersFilter -> String
show :: ChatMembersFilter -> String
$cshowList :: [ChatMembersFilter] -> ShowS
showList :: [ChatMembersFilter] -> ShowS
Show)
instance I.ShortShow ChatMembersFilter where
shortShow :: ChatMembersFilter -> String
shortShow ChatMembersFilter
ChatMembersFilterContacts
= String
"ChatMembersFilterContacts"
shortShow ChatMembersFilter
ChatMembersFilterAdministrators
= String
"ChatMembersFilterAdministrators"
shortShow ChatMembersFilter
ChatMembersFilterMembers
= String
"ChatMembersFilterMembers"
shortShow ChatMembersFilterMention
{ message_thread_id :: ChatMembersFilter -> Maybe Int
message_thread_id = Maybe Int
message_thread_id_
}
= String
"ChatMembersFilterMention"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"message_thread_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_thread_id_
]
shortShow ChatMembersFilter
ChatMembersFilterRestricted
= String
"ChatMembersFilterRestricted"
shortShow ChatMembersFilter
ChatMembersFilterBanned
= String
"ChatMembersFilterBanned"
shortShow ChatMembersFilter
ChatMembersFilterBots
= String
"ChatMembersFilterBots"
instance AT.FromJSON ChatMembersFilter where
parseJSON :: Value -> Parser ChatMembersFilter
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
"chatMembersFilterContacts" -> ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatMembersFilter
ChatMembersFilterContacts
String
"chatMembersFilterAdministrators" -> ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatMembersFilter
ChatMembersFilterAdministrators
String
"chatMembersFilterMembers" -> ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatMembersFilter
ChatMembersFilterMembers
String
"chatMembersFilterMention" -> Value -> Parser ChatMembersFilter
parseChatMembersFilterMention Value
v
String
"chatMembersFilterRestricted" -> ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatMembersFilter
ChatMembersFilterRestricted
String
"chatMembersFilterBanned" -> ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatMembersFilter
ChatMembersFilterBanned
String
"chatMembersFilterBots" -> ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatMembersFilter
ChatMembersFilterBots
String
_ -> Parser ChatMembersFilter
forall a. Monoid a => a
mempty
where
parseChatMembersFilterMention :: A.Value -> AT.Parser ChatMembersFilter
parseChatMembersFilterMention :: Value -> Parser ChatMembersFilter
parseChatMembersFilterMention = String
-> (Object -> Parser ChatMembersFilter)
-> Value
-> Parser ChatMembersFilter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatMembersFilterMention" ((Object -> Parser ChatMembersFilter)
-> Value -> Parser ChatMembersFilter)
-> (Object -> Parser ChatMembersFilter)
-> Value
-> Parser ChatMembersFilter
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
message_thread_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message_thread_id"
ChatMembersFilter -> Parser ChatMembersFilter
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatMembersFilter -> Parser ChatMembersFilter)
-> ChatMembersFilter -> Parser ChatMembersFilter
forall a b. (a -> b) -> a -> b
$ ChatMembersFilterMention
{ message_thread_id :: Maybe Int
message_thread_id = Maybe Int
message_thread_id_
}
parseJSON Value
_ = Parser ChatMembersFilter
forall a. Monoid a => a
mempty
instance AT.ToJSON ChatMembersFilter where
toJSON :: ChatMembersFilter -> Value
toJSON ChatMembersFilter
ChatMembersFilterContacts
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterContacts"
]
toJSON ChatMembersFilter
ChatMembersFilterAdministrators
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterAdministrators"
]
toJSON ChatMembersFilter
ChatMembersFilterMembers
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterMembers"
]
toJSON ChatMembersFilterMention
{ message_thread_id :: ChatMembersFilter -> Maybe Int
message_thread_id = Maybe Int
message_thread_id_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterMention"
, Key
"message_thread_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
message_thread_id_
]
toJSON ChatMembersFilter
ChatMembersFilterRestricted
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterRestricted"
]
toJSON ChatMembersFilter
ChatMembersFilterBanned
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterBanned"
]
toJSON ChatMembersFilter
ChatMembersFilterBots
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatMembersFilterBots"
]