module TD.Data.TargetChatTypes
( TargetChatTypes(..)
, defaultTargetChatTypes
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data TargetChatTypes
= TargetChatTypes
{ TargetChatTypes -> Maybe Bool
allow_user_chats :: Maybe Bool
, TargetChatTypes -> Maybe Bool
allow_bot_chats :: Maybe Bool
, TargetChatTypes -> Maybe Bool
allow_group_chats :: Maybe Bool
, TargetChatTypes -> Maybe Bool
allow_channel_chats :: Maybe Bool
}
deriving (TargetChatTypes -> TargetChatTypes -> Bool
(TargetChatTypes -> TargetChatTypes -> Bool)
-> (TargetChatTypes -> TargetChatTypes -> Bool)
-> Eq TargetChatTypes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TargetChatTypes -> TargetChatTypes -> Bool
== :: TargetChatTypes -> TargetChatTypes -> Bool
$c/= :: TargetChatTypes -> TargetChatTypes -> Bool
/= :: TargetChatTypes -> TargetChatTypes -> Bool
Eq, Int -> TargetChatTypes -> ShowS
[TargetChatTypes] -> ShowS
TargetChatTypes -> String
(Int -> TargetChatTypes -> ShowS)
-> (TargetChatTypes -> String)
-> ([TargetChatTypes] -> ShowS)
-> Show TargetChatTypes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TargetChatTypes -> ShowS
showsPrec :: Int -> TargetChatTypes -> ShowS
$cshow :: TargetChatTypes -> String
show :: TargetChatTypes -> String
$cshowList :: [TargetChatTypes] -> ShowS
showList :: [TargetChatTypes] -> ShowS
Show)
instance I.ShortShow TargetChatTypes where
shortShow :: TargetChatTypes -> String
shortShow TargetChatTypes
{ allow_user_chats :: TargetChatTypes -> Maybe Bool
allow_user_chats = Maybe Bool
allow_user_chats_
, allow_bot_chats :: TargetChatTypes -> Maybe Bool
allow_bot_chats = Maybe Bool
allow_bot_chats_
, allow_group_chats :: TargetChatTypes -> Maybe Bool
allow_group_chats = Maybe Bool
allow_group_chats_
, allow_channel_chats :: TargetChatTypes -> Maybe Bool
allow_channel_chats = Maybe Bool
allow_channel_chats_
}
= String
"TargetChatTypes"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"allow_user_chats" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_user_chats_
, String
"allow_bot_chats" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_bot_chats_
, String
"allow_group_chats" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_group_chats_
, String
"allow_channel_chats" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_channel_chats_
]
instance AT.FromJSON TargetChatTypes where
parseJSON :: Value -> Parser TargetChatTypes
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
"targetChatTypes" -> Value -> Parser TargetChatTypes
parseTargetChatTypes Value
v
String
_ -> Parser TargetChatTypes
forall a. Monoid a => a
mempty
where
parseTargetChatTypes :: A.Value -> AT.Parser TargetChatTypes
parseTargetChatTypes :: Value -> Parser TargetChatTypes
parseTargetChatTypes = String
-> (Object -> Parser TargetChatTypes)
-> Value
-> Parser TargetChatTypes
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TargetChatTypes" ((Object -> Parser TargetChatTypes)
-> Value -> Parser TargetChatTypes)
-> (Object -> Parser TargetChatTypes)
-> Value
-> Parser TargetChatTypes
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
allow_user_chats_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_user_chats"
Maybe Bool
allow_bot_chats_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_bot_chats"
Maybe Bool
allow_group_chats_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_group_chats"
Maybe Bool
allow_channel_chats_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_channel_chats"
TargetChatTypes -> Parser TargetChatTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TargetChatTypes -> Parser TargetChatTypes)
-> TargetChatTypes -> Parser TargetChatTypes
forall a b. (a -> b) -> a -> b
$ TargetChatTypes
{ allow_user_chats :: Maybe Bool
allow_user_chats = Maybe Bool
allow_user_chats_
, allow_bot_chats :: Maybe Bool
allow_bot_chats = Maybe Bool
allow_bot_chats_
, allow_group_chats :: Maybe Bool
allow_group_chats = Maybe Bool
allow_group_chats_
, allow_channel_chats :: Maybe Bool
allow_channel_chats = Maybe Bool
allow_channel_chats_
}
parseJSON Value
_ = Parser TargetChatTypes
forall a. Monoid a => a
mempty
instance AT.ToJSON TargetChatTypes where
toJSON :: TargetChatTypes -> Value
toJSON TargetChatTypes
{ allow_user_chats :: TargetChatTypes -> Maybe Bool
allow_user_chats = Maybe Bool
allow_user_chats_
, allow_bot_chats :: TargetChatTypes -> Maybe Bool
allow_bot_chats = Maybe Bool
allow_bot_chats_
, allow_group_chats :: TargetChatTypes -> Maybe Bool
allow_group_chats = Maybe Bool
allow_group_chats_
, allow_channel_chats :: TargetChatTypes -> Maybe Bool
allow_channel_chats = Maybe Bool
allow_channel_chats_
}
= [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
"targetChatTypes"
, Key
"allow_user_chats" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_user_chats_
, Key
"allow_bot_chats" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_bot_chats_
, Key
"allow_group_chats" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_group_chats_
, Key
"allow_channel_chats" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_channel_chats_
]
defaultTargetChatTypes :: TargetChatTypes
defaultTargetChatTypes :: TargetChatTypes
defaultTargetChatTypes =
TargetChatTypes
{ allow_user_chats :: Maybe Bool
allow_user_chats = Maybe Bool
forall a. Maybe a
Nothing
, allow_bot_chats :: Maybe Bool
allow_bot_chats = Maybe Bool
forall a. Maybe a
Nothing
, allow_group_chats :: Maybe Bool
allow_group_chats = Maybe Bool
forall a. Maybe a
Nothing
, allow_channel_chats :: Maybe Bool
allow_channel_chats = Maybe Bool
forall a. Maybe a
Nothing
}