module TD.Data.BotCommandScope
(BotCommandScope(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data BotCommandScope
= BotCommandScopeDefault
| BotCommandScopeAllPrivateChats
| BotCommandScopeAllGroupChats
| BotCommandScopeAllChatAdministrators
| BotCommandScopeChat
{ BotCommandScope -> Maybe Int
chat_id :: Maybe Int
}
| BotCommandScopeChatAdministrators
{ chat_id :: Maybe Int
}
| BotCommandScopeChatMember
{ chat_id :: Maybe Int
, BotCommandScope -> Maybe Int
user_id :: Maybe Int
}
deriving (BotCommandScope -> BotCommandScope -> Bool
(BotCommandScope -> BotCommandScope -> Bool)
-> (BotCommandScope -> BotCommandScope -> Bool)
-> Eq BotCommandScope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BotCommandScope -> BotCommandScope -> Bool
== :: BotCommandScope -> BotCommandScope -> Bool
$c/= :: BotCommandScope -> BotCommandScope -> Bool
/= :: BotCommandScope -> BotCommandScope -> Bool
Eq, Int -> BotCommandScope -> ShowS
[BotCommandScope] -> ShowS
BotCommandScope -> String
(Int -> BotCommandScope -> ShowS)
-> (BotCommandScope -> String)
-> ([BotCommandScope] -> ShowS)
-> Show BotCommandScope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BotCommandScope -> ShowS
showsPrec :: Int -> BotCommandScope -> ShowS
$cshow :: BotCommandScope -> String
show :: BotCommandScope -> String
$cshowList :: [BotCommandScope] -> ShowS
showList :: [BotCommandScope] -> ShowS
Show)
instance I.ShortShow BotCommandScope where
shortShow :: BotCommandScope -> String
shortShow BotCommandScope
BotCommandScopeDefault
= String
"BotCommandScopeDefault"
shortShow BotCommandScope
BotCommandScopeAllPrivateChats
= String
"BotCommandScopeAllPrivateChats"
shortShow BotCommandScope
BotCommandScopeAllGroupChats
= String
"BotCommandScopeAllGroupChats"
shortShow BotCommandScope
BotCommandScopeAllChatAdministrators
= String
"BotCommandScopeAllChatAdministrators"
shortShow BotCommandScopeChat
{ chat_id :: BotCommandScope -> Maybe Int
chat_id = Maybe Int
chat_id_
}
= String
"BotCommandScopeChat"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
]
shortShow BotCommandScopeChatAdministrators
{ chat_id :: BotCommandScope -> Maybe Int
chat_id = Maybe Int
chat_id_
}
= String
"BotCommandScopeChatAdministrators"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
]
shortShow BotCommandScopeChatMember
{ chat_id :: BotCommandScope -> Maybe Int
chat_id = Maybe Int
chat_id_
, user_id :: BotCommandScope -> Maybe Int
user_id = Maybe Int
user_id_
}
= String
"BotCommandScopeChatMember"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
, String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
]
instance AT.FromJSON BotCommandScope where
parseJSON :: Value -> Parser BotCommandScope
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
"botCommandScopeDefault" -> BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BotCommandScope
BotCommandScopeDefault
String
"botCommandScopeAllPrivateChats" -> BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BotCommandScope
BotCommandScopeAllPrivateChats
String
"botCommandScopeAllGroupChats" -> BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BotCommandScope
BotCommandScopeAllGroupChats
String
"botCommandScopeAllChatAdministrators" -> BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BotCommandScope
BotCommandScopeAllChatAdministrators
String
"botCommandScopeChat" -> Value -> Parser BotCommandScope
parseBotCommandScopeChat Value
v
String
"botCommandScopeChatAdministrators" -> Value -> Parser BotCommandScope
parseBotCommandScopeChatAdministrators Value
v
String
"botCommandScopeChatMember" -> Value -> Parser BotCommandScope
parseBotCommandScopeChatMember Value
v
String
_ -> Parser BotCommandScope
forall a. Monoid a => a
mempty
where
parseBotCommandScopeChat :: A.Value -> AT.Parser BotCommandScope
parseBotCommandScopeChat :: Value -> Parser BotCommandScope
parseBotCommandScopeChat = String
-> (Object -> Parser BotCommandScope)
-> Value
-> Parser BotCommandScope
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BotCommandScopeChat" ((Object -> Parser BotCommandScope)
-> Value -> Parser BotCommandScope)
-> (Object -> Parser BotCommandScope)
-> Value
-> Parser BotCommandScope
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BotCommandScope -> Parser BotCommandScope)
-> BotCommandScope -> Parser BotCommandScope
forall a b. (a -> b) -> a -> b
$ BotCommandScopeChat
{ chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
}
parseBotCommandScopeChatAdministrators :: A.Value -> AT.Parser BotCommandScope
parseBotCommandScopeChatAdministrators :: Value -> Parser BotCommandScope
parseBotCommandScopeChatAdministrators = String
-> (Object -> Parser BotCommandScope)
-> Value
-> Parser BotCommandScope
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BotCommandScopeChatAdministrators" ((Object -> Parser BotCommandScope)
-> Value -> Parser BotCommandScope)
-> (Object -> Parser BotCommandScope)
-> Value
-> Parser BotCommandScope
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BotCommandScope -> Parser BotCommandScope)
-> BotCommandScope -> Parser BotCommandScope
forall a b. (a -> b) -> a -> b
$ BotCommandScopeChatAdministrators
{ chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
}
parseBotCommandScopeChatMember :: A.Value -> AT.Parser BotCommandScope
parseBotCommandScopeChatMember :: Value -> Parser BotCommandScope
parseBotCommandScopeChatMember = String
-> (Object -> Parser BotCommandScope)
-> Value
-> Parser BotCommandScope
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"BotCommandScopeChatMember" ((Object -> Parser BotCommandScope)
-> Value -> Parser BotCommandScope)
-> (Object -> Parser BotCommandScope)
-> Value
-> Parser BotCommandScope
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
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
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
BotCommandScope -> Parser BotCommandScope
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BotCommandScope -> Parser BotCommandScope)
-> BotCommandScope -> Parser BotCommandScope
forall a b. (a -> b) -> a -> b
$ BotCommandScopeChatMember
{ chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
, user_id :: Maybe Int
user_id = Maybe Int
user_id_
}
parseJSON Value
_ = Parser BotCommandScope
forall a. Monoid a => a
mempty
instance AT.ToJSON BotCommandScope where
toJSON :: BotCommandScope -> Value
toJSON BotCommandScope
BotCommandScopeDefault
= [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
"botCommandScopeDefault"
]
toJSON BotCommandScope
BotCommandScopeAllPrivateChats
= [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
"botCommandScopeAllPrivateChats"
]
toJSON BotCommandScope
BotCommandScopeAllGroupChats
= [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
"botCommandScopeAllGroupChats"
]
toJSON BotCommandScope
BotCommandScopeAllChatAdministrators
= [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
"botCommandScopeAllChatAdministrators"
]
toJSON BotCommandScopeChat
{ chat_id :: BotCommandScope -> Maybe Int
chat_id = Maybe Int
chat_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
"botCommandScopeChat"
, Key
"chat_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
chat_id_
]
toJSON BotCommandScopeChatAdministrators
{ chat_id :: BotCommandScope -> Maybe Int
chat_id = Maybe Int
chat_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
"botCommandScopeChatAdministrators"
, Key
"chat_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
chat_id_
]
toJSON BotCommandScopeChatMember
{ chat_id :: BotCommandScope -> Maybe Int
chat_id = Maybe Int
chat_id_
, user_id :: BotCommandScope -> Maybe Int
user_id = Maybe Int
user_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
"botCommandScopeChatMember"
, Key
"chat_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
chat_id_
, Key
"user_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
user_id_
]