module TD.Data.MessageSendOptions
( MessageSendOptions(..)
, defaultMessageSendOptions
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.MessageSchedulingState as MessageSchedulingState
data MessageSendOptions
= MessageSendOptions
{ MessageSendOptions -> Maybe Bool
disable_notification :: Maybe Bool
, MessageSendOptions -> Maybe Bool
from_background :: Maybe Bool
, MessageSendOptions -> Maybe Bool
protect_content :: Maybe Bool
, MessageSendOptions -> Maybe Bool
allow_paid_broadcast :: Maybe Bool
, MessageSendOptions -> Maybe Bool
update_order_of_installed_sticker_sets :: Maybe Bool
, MessageSendOptions -> Maybe MessageSchedulingState
scheduling_state :: Maybe MessageSchedulingState.MessageSchedulingState
, MessageSendOptions -> Maybe Int
effect_id :: Maybe Int
, MessageSendOptions -> Maybe Int
sending_id :: Maybe Int
, MessageSendOptions -> Maybe Bool
only_preview :: Maybe Bool
}
deriving (MessageSendOptions -> MessageSendOptions -> Bool
(MessageSendOptions -> MessageSendOptions -> Bool)
-> (MessageSendOptions -> MessageSendOptions -> Bool)
-> Eq MessageSendOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageSendOptions -> MessageSendOptions -> Bool
== :: MessageSendOptions -> MessageSendOptions -> Bool
$c/= :: MessageSendOptions -> MessageSendOptions -> Bool
/= :: MessageSendOptions -> MessageSendOptions -> Bool
Eq, Int -> MessageSendOptions -> ShowS
[MessageSendOptions] -> ShowS
MessageSendOptions -> String
(Int -> MessageSendOptions -> ShowS)
-> (MessageSendOptions -> String)
-> ([MessageSendOptions] -> ShowS)
-> Show MessageSendOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageSendOptions -> ShowS
showsPrec :: Int -> MessageSendOptions -> ShowS
$cshow :: MessageSendOptions -> String
show :: MessageSendOptions -> String
$cshowList :: [MessageSendOptions] -> ShowS
showList :: [MessageSendOptions] -> ShowS
Show)
instance I.ShortShow MessageSendOptions where
shortShow :: MessageSendOptions -> String
shortShow MessageSendOptions
{ disable_notification :: MessageSendOptions -> Maybe Bool
disable_notification = Maybe Bool
disable_notification_
, from_background :: MessageSendOptions -> Maybe Bool
from_background = Maybe Bool
from_background_
, protect_content :: MessageSendOptions -> Maybe Bool
protect_content = Maybe Bool
protect_content_
, allow_paid_broadcast :: MessageSendOptions -> Maybe Bool
allow_paid_broadcast = Maybe Bool
allow_paid_broadcast_
, update_order_of_installed_sticker_sets :: MessageSendOptions -> Maybe Bool
update_order_of_installed_sticker_sets = Maybe Bool
update_order_of_installed_sticker_sets_
, scheduling_state :: MessageSendOptions -> Maybe MessageSchedulingState
scheduling_state = Maybe MessageSchedulingState
scheduling_state_
, effect_id :: MessageSendOptions -> Maybe Int
effect_id = Maybe Int
effect_id_
, sending_id :: MessageSendOptions -> Maybe Int
sending_id = Maybe Int
sending_id_
, only_preview :: MessageSendOptions -> Maybe Bool
only_preview = Maybe Bool
only_preview_
}
= String
"MessageSendOptions"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"disable_notification" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
disable_notification_
, String
"from_background" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
from_background_
, String
"protect_content" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
protect_content_
, String
"allow_paid_broadcast" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_paid_broadcast_
, String
"update_order_of_installed_sticker_sets" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
update_order_of_installed_sticker_sets_
, String
"scheduling_state" String -> Maybe MessageSchedulingState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSchedulingState
scheduling_state_
, String
"effect_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
effect_id_
, String
"sending_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sending_id_
, String
"only_preview" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
only_preview_
]
instance AT.FromJSON MessageSendOptions where
parseJSON :: Value -> Parser MessageSendOptions
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
"messageSendOptions" -> Value -> Parser MessageSendOptions
parseMessageSendOptions Value
v
String
_ -> Parser MessageSendOptions
forall a. Monoid a => a
mempty
where
parseMessageSendOptions :: A.Value -> AT.Parser MessageSendOptions
parseMessageSendOptions :: Value -> Parser MessageSendOptions
parseMessageSendOptions = String
-> (Object -> Parser MessageSendOptions)
-> Value
-> Parser MessageSendOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageSendOptions" ((Object -> Parser MessageSendOptions)
-> Value -> Parser MessageSendOptions)
-> (Object -> Parser MessageSendOptions)
-> Value
-> Parser MessageSendOptions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
disable_notification_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"disable_notification"
Maybe Bool
from_background_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"from_background"
Maybe Bool
protect_content_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"protect_content"
Maybe Bool
allow_paid_broadcast_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_paid_broadcast"
Maybe Bool
update_order_of_installed_sticker_sets_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"update_order_of_installed_sticker_sets"
Maybe MessageSchedulingState
scheduling_state_ <- Object
o Object -> Key -> Parser (Maybe MessageSchedulingState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"scheduling_state"
Maybe Int
effect_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"effect_id"
Maybe Int
sending_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sending_id"
Maybe Bool
only_preview_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"only_preview"
MessageSendOptions -> Parser MessageSendOptions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageSendOptions -> Parser MessageSendOptions)
-> MessageSendOptions -> Parser MessageSendOptions
forall a b. (a -> b) -> a -> b
$ MessageSendOptions
{ disable_notification :: Maybe Bool
disable_notification = Maybe Bool
disable_notification_
, from_background :: Maybe Bool
from_background = Maybe Bool
from_background_
, protect_content :: Maybe Bool
protect_content = Maybe Bool
protect_content_
, allow_paid_broadcast :: Maybe Bool
allow_paid_broadcast = Maybe Bool
allow_paid_broadcast_
, update_order_of_installed_sticker_sets :: Maybe Bool
update_order_of_installed_sticker_sets = Maybe Bool
update_order_of_installed_sticker_sets_
, scheduling_state :: Maybe MessageSchedulingState
scheduling_state = Maybe MessageSchedulingState
scheduling_state_
, effect_id :: Maybe Int
effect_id = Maybe Int
effect_id_
, sending_id :: Maybe Int
sending_id = Maybe Int
sending_id_
, only_preview :: Maybe Bool
only_preview = Maybe Bool
only_preview_
}
parseJSON Value
_ = Parser MessageSendOptions
forall a. Monoid a => a
mempty
instance AT.ToJSON MessageSendOptions where
toJSON :: MessageSendOptions -> Value
toJSON MessageSendOptions
{ disable_notification :: MessageSendOptions -> Maybe Bool
disable_notification = Maybe Bool
disable_notification_
, from_background :: MessageSendOptions -> Maybe Bool
from_background = Maybe Bool
from_background_
, protect_content :: MessageSendOptions -> Maybe Bool
protect_content = Maybe Bool
protect_content_
, allow_paid_broadcast :: MessageSendOptions -> Maybe Bool
allow_paid_broadcast = Maybe Bool
allow_paid_broadcast_
, update_order_of_installed_sticker_sets :: MessageSendOptions -> Maybe Bool
update_order_of_installed_sticker_sets = Maybe Bool
update_order_of_installed_sticker_sets_
, scheduling_state :: MessageSendOptions -> Maybe MessageSchedulingState
scheduling_state = Maybe MessageSchedulingState
scheduling_state_
, effect_id :: MessageSendOptions -> Maybe Int
effect_id = Maybe Int
effect_id_
, sending_id :: MessageSendOptions -> Maybe Int
sending_id = Maybe Int
sending_id_
, only_preview :: MessageSendOptions -> Maybe Bool
only_preview = Maybe Bool
only_preview_
}
= [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
"messageSendOptions"
, Key
"disable_notification" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
disable_notification_
, Key
"from_background" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
from_background_
, Key
"protect_content" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
protect_content_
, Key
"allow_paid_broadcast" 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_paid_broadcast_
, Key
"update_order_of_installed_sticker_sets" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
update_order_of_installed_sticker_sets_
, Key
"scheduling_state" Key -> Maybe MessageSchedulingState -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe MessageSchedulingState
scheduling_state_
, Key
"effect_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64 Maybe Int
effect_id_
, Key
"sending_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
sending_id_
, Key
"only_preview" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
only_preview_
]
defaultMessageSendOptions :: MessageSendOptions
defaultMessageSendOptions :: MessageSendOptions
defaultMessageSendOptions =
MessageSendOptions
{ disable_notification :: Maybe Bool
disable_notification = Maybe Bool
forall a. Maybe a
Nothing
, from_background :: Maybe Bool
from_background = Maybe Bool
forall a. Maybe a
Nothing
, protect_content :: Maybe Bool
protect_content = Maybe Bool
forall a. Maybe a
Nothing
, allow_paid_broadcast :: Maybe Bool
allow_paid_broadcast = Maybe Bool
forall a. Maybe a
Nothing
, update_order_of_installed_sticker_sets :: Maybe Bool
update_order_of_installed_sticker_sets = Maybe Bool
forall a. Maybe a
Nothing
, scheduling_state :: Maybe MessageSchedulingState
scheduling_state = Maybe MessageSchedulingState
forall a. Maybe a
Nothing
, effect_id :: Maybe Int
effect_id = Maybe Int
forall a. Maybe a
Nothing
, sending_id :: Maybe Int
sending_id = Maybe Int
forall a. Maybe a
Nothing
, only_preview :: Maybe Bool
only_preview = Maybe Bool
forall a. Maybe a
Nothing
}